|
7 | 7 | // Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
8 | 8 | //
|
9 | 9 |
|
10 |
| -#import <AsyncDisplayKit/ASButtonNode.h> |
11 |
| -#import <AsyncDisplayKit/ASAvailability.h> |
12 |
| -#import <AsyncDisplayKit/ASDisplayNodeInternal.h> |
| 10 | +#import <AsyncDisplayKit/ASButtonNode+Private.h> |
| 11 | +#import <AsyncDisplayKit/ASButtonNode+Yoga.h> |
13 | 12 | #import <AsyncDisplayKit/ASStackLayoutSpec.h>
|
14 |
| -#import <AsyncDisplayKit/ASStackLayoutSpecUtilities.h> |
15 | 13 | #import <AsyncDisplayKit/ASThread.h>
|
16 | 14 | #import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
17 | 15 | #import <AsyncDisplayKit/ASBackgroundLayoutSpec.h>
|
18 | 16 | #import <AsyncDisplayKit/ASInsetLayoutSpec.h>
|
19 | 17 | #import <AsyncDisplayKit/ASAbsoluteLayoutSpec.h>
|
20 |
| -#import <AsyncDisplayKit/ASTextNode.h> |
21 |
| -#import <AsyncDisplayKit/ASImageNode.h> |
22 | 18 | #import <AsyncDisplayKit/ASInternalHelpers.h>
|
23 | 19 |
|
24 |
| -#if YOGA |
25 |
| -static void ASButtonNodeResolveHorizontalAlignmentForStyle(ASLayoutElementStyle *style, ASStackLayoutDirection _direction, ASHorizontalAlignment _horizontalAlignment, ASStackLayoutJustifyContent _justifyContent, ASStackLayoutAlignItems _alignItems) { |
26 |
| - if (_direction == ASStackLayoutDirectionHorizontal) { |
27 |
| - style.justifyContent = justifyContent(_horizontalAlignment, _justifyContent); |
28 |
| - } else { |
29 |
| - style.alignItems = alignment(_horizontalAlignment, _alignItems); |
30 |
| - } |
31 |
| -} |
32 |
| - |
33 |
| -static void ASButtonNodeResolveVerticalAlignmentForStyle(ASLayoutElementStyle *style, ASStackLayoutDirection _direction, ASVerticalAlignment _verticalAlignment, ASStackLayoutJustifyContent _justifyContent, ASStackLayoutAlignItems _alignItems) { |
34 |
| - if (_direction == ASStackLayoutDirectionHorizontal) { |
35 |
| - style.alignItems = alignment(_verticalAlignment, _alignItems); |
36 |
| - } else { |
37 |
| - style.justifyContent = justifyContent(_verticalAlignment, _justifyContent); |
38 |
| - } |
39 |
| -} |
40 |
| -#endif |
41 |
| - |
42 |
| -@interface ASButtonNode () |
43 |
| -{ |
44 |
| - NSAttributedString *_normalAttributedTitle; |
45 |
| - NSAttributedString *_highlightedAttributedTitle; |
46 |
| - NSAttributedString *_selectedAttributedTitle; |
47 |
| - NSAttributedString *_selectedHighlightedAttributedTitle; |
48 |
| - NSAttributedString *_disabledAttributedTitle; |
49 |
| - |
50 |
| - UIImage *_normalImage; |
51 |
| - UIImage *_highlightedImage; |
52 |
| - UIImage *_selectedImage; |
53 |
| - UIImage *_selectedHighlightedImage; |
54 |
| - UIImage *_disabledImage; |
55 |
| - |
56 |
| - UIImage *_normalBackgroundImage; |
57 |
| - UIImage *_highlightedBackgroundImage; |
58 |
| - UIImage *_selectedBackgroundImage; |
59 |
| - UIImage *_selectedHighlightedBackgroundImage; |
60 |
| - UIImage *_disabledBackgroundImage; |
61 |
| -} |
62 |
| - |
63 |
| -@end |
64 |
| - |
65 | 20 | @implementation ASButtonNode
|
66 | 21 |
|
67 | 22 | @synthesize contentSpacing = _contentSpacing;
|
@@ -590,69 +545,6 @@ - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
590 | 545 | }
|
591 | 546 | #endif
|
592 | 547 |
|
593 |
| -- (void)updateYogaLayoutIfNeeded |
594 |
| -{ |
595 |
| -#if YOGA |
596 |
| - NSMutableArray<ASDisplayNode *> *children = [[NSMutableArray alloc] initWithCapacity:2]; |
597 |
| - { |
598 |
| - ASLockScopeSelf(); |
599 |
| - |
600 |
| - // Build up yoga children for button node again |
601 |
| - unowned ASLayoutElementStyle *style = [self _locked_style]; |
602 |
| - [style yogaNodeCreateIfNeeded]; |
603 |
| - |
604 |
| - // Setup stack layout values |
605 |
| - style.flexDirection = _laysOutHorizontally ? ASStackLayoutDirectionHorizontal : ASStackLayoutDirectionVertical; |
606 |
| - |
607 |
| - // Resolve horizontal and vertical alignment |
608 |
| - ASButtonNodeResolveHorizontalAlignmentForStyle(style, style.flexDirection, _contentHorizontalAlignment, style.justifyContent, style.alignItems); |
609 |
| - ASButtonNodeResolveVerticalAlignmentForStyle(style, style.flexDirection, _contentVerticalAlignment, style.justifyContent, style.alignItems); |
610 |
| - |
611 |
| - // Setup new yoga children |
612 |
| - if (_imageNode.image != nil) { |
613 |
| - [_imageNode.style yogaNodeCreateIfNeeded]; |
614 |
| - [children addObject:_imageNode]; |
615 |
| - } |
616 |
| - |
617 |
| - if (_titleNode.attributedText.length > 0) { |
618 |
| - [_titleNode.style yogaNodeCreateIfNeeded]; |
619 |
| - if (_imageAlignment == ASButtonNodeImageAlignmentBeginning) { |
620 |
| - [children addObject:_titleNode]; |
621 |
| - } else { |
622 |
| - [children insertObject:_titleNode atIndex:0]; |
623 |
| - } |
624 |
| - } |
625 |
| - |
626 |
| - // Add spacing between title and button |
627 |
| - if (children.count == 2) { |
628 |
| - unowned ASLayoutElementStyle *firstChildStyle = children.firstObject.style; |
629 |
| - if (_laysOutHorizontally) { |
630 |
| - firstChildStyle.margin = ASEdgeInsetsMake(UIEdgeInsetsMake(0, 0, 0, _contentSpacing)); |
631 |
| - } else { |
632 |
| - firstChildStyle.margin = ASEdgeInsetsMake(UIEdgeInsetsMake(0, 0, _contentSpacing, 0)); |
633 |
| - } |
634 |
| - } |
635 |
| - |
636 |
| - // Add padding to button |
637 |
| - if (UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, _contentEdgeInsets) == NO) { |
638 |
| - style.padding = ASEdgeInsetsMake(_contentEdgeInsets); |
639 |
| - } |
640 |
| - |
641 |
| - // Add background node |
642 |
| - if (_backgroundImageNode.image) { |
643 |
| - [_backgroundImageNode.style yogaNodeCreateIfNeeded]; |
644 |
| - [children insertObject:_backgroundImageNode atIndex:0]; |
645 |
| - |
646 |
| - _backgroundImageNode.style.positionType = YGPositionTypeAbsolute; |
647 |
| - _backgroundImageNode.style.position = ASEdgeInsetsMake(UIEdgeInsetsZero); |
648 |
| - } |
649 |
| - } |
650 |
| - |
651 |
| - // Update new children |
652 |
| - [self setYogaChildren:children]; |
653 |
| -#endif |
654 |
| -} |
655 |
| - |
656 | 548 | - (void)layout
|
657 | 549 | {
|
658 | 550 | [super layout];
|
|
0 commit comments