Created
May 1, 2018 15:45
-
-
Save GeekTree0101/b7a8792676faa629d9448f345d58b854 to your computer and use it in GitHub Desktop.
Message Balloon Node Content Area Spec Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func talkBalloonContentLayoutSpec(_ constrainedSize: ASSizeRange, | |
isLeft: Bool) -> ASLayoutSpec { | |
let talkTailLayout = ASAbsoluteLayoutSpec(sizing: .sizeToFit, | |
children: [self.talkTailNode]) | |
let stackElements: [ASLayoutElement] = [self.contentAreaNode, | |
talkTailLayout] | |
let stackLayout = ASStackLayoutSpec(direction: .horizontal, | |
spacing: 0.0, | |
justifyContent: .start, | |
alignItems: .notSet, | |
children: isLeft ? stackElements.reversed(): stackElements) | |
let insets = UIEdgeInsets(top: Const.contentAreaTopInset, | |
left: isLeft ? Const.contentAreaSideInset: 0.0, | |
bottom: 0.0, | |
right: !isLeft ? Const.contentAreaSideInset: 0.0) | |
let talkBalloonLayout = ASInsetLayoutSpec(insets: insets, child: stackLayout) | |
let contentNodeSize = contentNode.calculatedSize | |
let hasMedia = self.mediaRatio != nil | |
let isContentSingleLine = !hasMedia && contentNodeSize.height <= Const.contentNodeLineHeight | |
if let engageNodeLayout = self.engageNodeLayoutSpec(constrainedSize, | |
isSingleLine: isContentSingleLine, | |
isLeft: isLeft) { | |
let talkBalloonElements = [talkBalloonLayout, engageNodeLayout] | |
return ASStackLayoutSpec(direction: .horizontal, | |
spacing: 0.0, | |
justifyContent: .spaceBetween, | |
alignItems: isContentSingleLine ? .center: .stretch, | |
children: isLeft ? | |
talkBalloonElements: | |
talkBalloonElements.reversed()) | |
} | |
return talkBalloonLayout | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment