From d6e5e27c39f36a9715dec24bd10f41acb6b1c0c7 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Tue, 4 Oct 2016 09:35:45 -0700 Subject: [PATCH] [Layout] Add helper properties for setting sizes via CGSize and ASRelativeSize (#2324) * Remove set layout style size helper * Update API to set and get a CGSize / ASRelativeSize from an ASLayoutElementStyle - Expose ASRelativeSize type - Add new helper properties to set a size / relative size to ASLayoutElementStyle - Don't expose the size in ASLayoutElementStyle anymore and move into ASLayoutElementStylePrivate * Update examples * Update comments for size helpers --- AsyncDisplayKit.xcodeproj/project.pbxproj | 24 ++---- AsyncDisplayKit/ASDisplayNode.mm | 4 +- AsyncDisplayKit/ASVideoNode.mm | 3 +- AsyncDisplayKit/ASVideoPlayerNode.mm | 15 ++-- .../Layout/ASAbsoluteLayoutSpec.mm | 1 + AsyncDisplayKit/Layout/ASDimension.h | 28 ++++++- AsyncDisplayKit/Layout/ASDimension.mm | 16 ---- AsyncDisplayKit/Layout/ASLayoutElement.h | 73 +++++++++++++--- AsyncDisplayKit/Layout/ASLayoutElement.mm | 84 +++++++++++++++---- .../Layout/ASLayoutElementStylePrivate.h | 27 ++++++ AsyncDisplayKit/Layout/ASLayoutSpec.mm | 2 + AsyncDisplayKit/Layout/ASRelativeSize.h | 11 --- AsyncDisplayKit/Layout/ASRelativeSize.mm | 11 --- .../Private/ASStackUnpositionedLayout.mm | 1 + .../ASDisplayNodeLayoutTests.mm | 3 +- .../ASImageNodeSnapshotTests.m | 6 +- .../ASLayoutElementStyleTests.m | 56 ++++++++++--- .../ASStackLayoutSpecSnapshotTests.mm | 3 +- examples/ASDKgram/Sample/PhotoCellNode.m | 6 +- examples/ASMapNode/Sample/MapHandlerNode.m | 12 +-- .../ASViewController/Sample/DetailCellNode.m | 2 +- .../ASViewController/Sample/DetailRootNode.m | 2 +- .../Sample/OverviewComponentsViewController.m | 20 ++--- .../Sample/LoadingNode.m | 2 +- .../Sample/HorizontalScrollCellNode.mm | 4 +- examples/Kittens/Sample/KittenNode.mm | 2 +- examples/SocialAppLayout/Sample/PostNode.m | 1 - .../Sample/GradientTableNode.mm | 2 +- .../Sample/ViewController.m | 2 +- examples/Videos/Sample/ViewController.m | 8 +- 30 files changed, 288 insertions(+), 143 deletions(-) create mode 100644 AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h delete mode 100644 AsyncDisplayKit/Layout/ASRelativeSize.h delete mode 100644 AsyncDisplayKit/Layout/ASRelativeSize.mm diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index 8ef41aa331..4c73e0d2a5 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -136,8 +136,6 @@ 34EFC7621B701CA400AD841F /* ASBackgroundLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED021B17843500DA7C62 /* ASBackgroundLayoutSpec.mm */; }; 34EFC7631B701CBF00AD841F /* ASCenterLayoutSpec.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED031B17843500DA7C62 /* ASCenterLayoutSpec.h */; settings = {ATTRIBUTES = (Public, ); }; }; 34EFC7641B701CC600AD841F /* ASCenterLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED041B17843500DA7C62 /* ASCenterLayoutSpec.mm */; }; - 34EFC7651B701CCC00AD841F /* ASRelativeSize.h in Headers */ = {isa = PBXBuildFile; fileRef = AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 34EFC7661B701CD200AD841F /* ASRelativeSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */; }; 34EFC7671B701CD900AD841F /* ASLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED0B1B17843500DA7C62 /* ASLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; 34EFC7681B701CDE00AD841F /* ASLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED0C1B17843500DA7C62 /* ASLayout.mm */; }; 34EFC7691B701CE100AD841F /* ASLayoutElement.h in Headers */ = {isa = PBXBuildFile; fileRef = ACF6ED111B17843500DA7C62 /* ASLayoutElement.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -212,6 +210,7 @@ 698548641CA9E025008A345F /* ASEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = 698548611CA9E025008A345F /* ASEnvironment.h */; settings = {ATTRIBUTES = (Public, ); }; }; 698C8B621CAB49FC0052DC3F /* ASLayoutElementExtensibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 698C8B601CAB49FC0052DC3F /* ASLayoutElementExtensibility.h */; settings = {ATTRIBUTES = (Public, ); }; }; 69B225671D72535E00B25B22 /* ASDisplayNodeLayoutTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69B225661D72535E00B25B22 /* ASDisplayNodeLayoutTests.mm */; }; + 69C4CAF61DA3147000B1EC9B /* ASLayoutElementStylePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */; }; 69CB62AC1CB8165900024920 /* _ASDisplayViewAccessiblity.h in Headers */ = {isa = PBXBuildFile; fileRef = 69CB62A91CB8165900024920 /* _ASDisplayViewAccessiblity.h */; }; 69CB62AD1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */; }; 69CB62AE1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */; }; @@ -298,7 +297,6 @@ AC026B721BD57DBF00BBC17E /* _ASHierarchyChangeSet.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC026B6E1BD57DBF00BBC17E /* _ASHierarchyChangeSet.mm */; }; AC3C4A521A1139C100143C57 /* ASCollectionView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC3C4A501A1139C100143C57 /* ASCollectionView.mm */; }; AC47D9421B3B891B00AAEE9D /* ASCellNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC6456071B0A335000CF11B8 /* ASCellNode.mm */; }; - AC47D9461B3BB41900AAEE9D /* ASRelativeSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */; }; AC6145411D8AFAE8003D62A2 /* ASSection.h in Headers */ = {isa = PBXBuildFile; fileRef = AC6145401D8AFAE8003D62A2 /* ASSection.h */; }; AC6145431D8AFD4F003D62A2 /* ASSection.m in Sources */ = {isa = PBXBuildFile; fileRef = AC6145421D8AFD4F003D62A2 /* ASSection.m */; }; AC6145441D8AFD4F003D62A2 /* ASSection.m in Sources */ = {isa = PBXBuildFile; fileRef = AC6145421D8AFD4F003D62A2 /* ASSection.m */; }; @@ -566,7 +564,6 @@ F7CE6C641D2CDB3E00BE4C15 /* ASOverlayLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED121B17843500DA7C62 /* ASOverlayLayoutSpec.h */; }; F7CE6C651D2CDB3E00BE4C15 /* ASRatioLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED141B17843500DA7C62 /* ASRatioLayoutSpec.h */; }; F7CE6C661D2CDB3E00BE4C15 /* ASRelativeLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7A06A7391C35F08800FE8DAA /* ASRelativeLayoutSpec.h */; }; - F7CE6C671D2CDB3E00BE4C15 /* ASRelativeSize.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */; }; F7CE6C681D2CDB3E00BE4C15 /* ASStackLayoutElement.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */; }; F7CE6C691D2CDB3E00BE4C15 /* ASStackLayoutDefines.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */; }; F7CE6C6A1D2CDB3E00BE4C15 /* ASStackLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */; }; @@ -737,7 +734,6 @@ F7CE6C641D2CDB3E00BE4C15 /* ASOverlayLayoutSpec.h in CopyFiles */, F7CE6C651D2CDB3E00BE4C15 /* ASRatioLayoutSpec.h in CopyFiles */, F7CE6C661D2CDB3E00BE4C15 /* ASRelativeLayoutSpec.h in CopyFiles */, - F7CE6C671D2CDB3E00BE4C15 /* ASRelativeSize.h in CopyFiles */, F7CE6C681D2CDB3E00BE4C15 /* ASStackLayoutElement.h in CopyFiles */, F7CE6C691D2CDB3E00BE4C15 /* ASStackLayoutDefines.h in CopyFiles */, F7CE6C6A1D2CDB3E00BE4C15 /* ASStackLayoutSpec.h in CopyFiles */, @@ -990,6 +986,7 @@ 698C8B601CAB49FC0052DC3F /* ASLayoutElementExtensibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASLayoutElementExtensibility.h; path = AsyncDisplayKit/Layout/ASLayoutElementExtensibility.h; sourceTree = ""; }; 69B225661D72535E00B25B22 /* ASDisplayNodeLayoutTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDisplayNodeLayoutTests.mm; sourceTree = ""; }; 69B225681D7265DA00B25B22 /* ASXCTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASXCTExtensions.h; sourceTree = ""; }; + 69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASLayoutElementStylePrivate.h; path = AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h; sourceTree = ""; }; 69CB62A91CB8165900024920 /* _ASDisplayViewAccessiblity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _ASDisplayViewAccessiblity.h; sourceTree = ""; }; 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _ASDisplayViewAccessiblity.mm; sourceTree = ""; }; 69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASEnvironmentInternal.h; sourceTree = ""; }; @@ -1049,8 +1046,6 @@ AC3C4A4F1A1139C100143C57 /* ASCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ASCollectionView.h; sourceTree = ""; }; AC3C4A501A1139C100143C57 /* ASCollectionView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = ASCollectionView.mm; sourceTree = ""; }; AC3C4A531A113EEC00143C57 /* ASCollectionViewProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionViewProtocols.h; sourceTree = ""; }; - AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASRelativeSize.h; path = AsyncDisplayKit/Layout/ASRelativeSize.h; sourceTree = ""; }; - AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASRelativeSize.mm; path = AsyncDisplayKit/Layout/ASRelativeSize.mm; sourceTree = ""; }; AC6145401D8AFAE8003D62A2 /* ASSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASSection.h; path = ../Private/ASSection.h; sourceTree = ""; }; AC6145421D8AFD4F003D62A2 /* ASSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ASSection.m; path = ../Private/ASSection.m; sourceTree = ""; }; AC6456071B0A335000CF11B8 /* ASCellNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCellNode.mm; sourceTree = ""; }; @@ -1669,6 +1664,9 @@ AC6456051B0A333200CF11B8 /* Layout */ = { isa = PBXGroup; children = ( + 9C6BB3B01B8CC9C200F13F52 /* ASAbsoluteLayoutElement.h */, + ACF6ED181B17843500DA7C62 /* ASAbsoluteLayoutSpec.h */, + ACF6ED191B17843500DA7C62 /* ASAbsoluteLayoutSpec.mm */, 9C5586671BD549CB00B50E3A /* ASAsciiArtBoxCreator.h */, 9C5586681BD549CB00B50E3A /* ASAsciiArtBoxCreator.m */, ACF6ED011B17843500DA7C62 /* ASBackgroundLayoutSpec.h */, @@ -1685,6 +1683,7 @@ E55D86311CA8A14000A0C26F /* ASLayoutElement.mm */, 698C8B601CAB49FC0052DC3F /* ASLayoutElementExtensibility.h */, 9CDC18CB1B910E12004965E2 /* ASLayoutElementPrivate.h */, + 69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */, ACF6ED0D1B17843500DA7C62 /* ASLayoutSpec.h */, ACF6ED0E1B17843500DA7C62 /* ASLayoutSpec.mm */, 6977965D1D8AC8D3007E93D7 /* ASLayoutSpec+Subclasses.h */, @@ -1695,15 +1694,10 @@ ACF6ED151B17843500DA7C62 /* ASRatioLayoutSpec.mm */, 7A06A7391C35F08800FE8DAA /* ASRelativeLayoutSpec.h */, 7A06A7381C35F08800FE8DAA /* ASRelativeLayoutSpec.mm */, - AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */, - AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */, - 9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */, AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */, + 9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */, ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */, ACF6ED171B17843500DA7C62 /* ASStackLayoutSpec.mm */, - 9C6BB3B01B8CC9C200F13F52 /* ASAbsoluteLayoutElement.h */, - ACF6ED181B17843500DA7C62 /* ASAbsoluteLayoutSpec.h */, - ACF6ED191B17843500DA7C62 /* ASAbsoluteLayoutSpec.mm */, ); name = Layout; path = ..; @@ -1808,6 +1802,7 @@ B35062191B010EFD0018CF92 /* ASDealloc2MainObject.h in Headers */, 34EFC75B1B701BAF00AD841F /* ASDimension.h in Headers */, 68FC85EA1CE29C7D00EDD713 /* ASVisibilityProtocols.h in Headers */, + 69C4CAF61DA3147000B1EC9B /* ASLayoutElementStylePrivate.h in Headers */, A37320101C571B740011FC94 /* ASTextNode+Beta.h in Headers */, DBABFAFC1C6A8D2F0039EA4A /* _ASTransitionContext.h in Headers */, 9C70F2061CDA4F0C007D6C76 /* ASTraitCollection.h in Headers */, @@ -1859,7 +1854,6 @@ 34EFC76C1B701CED00AD841F /* ASOverlayLayoutSpec.h in Headers */, B35062261B010EFD0018CF92 /* ASRangeController.h in Headers */, 34EFC76E1B701CF400AD841F /* ASRatioLayoutSpec.h in Headers */, - 34EFC7651B701CCC00AD841F /* ASRelativeSize.h in Headers */, 254C6B741BF94DF4003EC431 /* ASTextNodeWordKerner.h in Headers */, DB55C2671C641AE4004EDCF5 /* ASContextTransitioning.h in Headers */, 68B0277B1C1A79D60041016B /* ASDisplayNode+Beta.h in Headers */, @@ -2202,7 +2196,6 @@ 044285091BAA63FE00D16268 /* ASBatchFetching.m in Sources */, 257754AE1BEE44CD00737CA5 /* ASTextKitRenderer+Positioning.mm in Sources */, ACF6ED2E1B17843500DA7C62 /* ASRatioLayoutSpec.mm in Sources */, - AC47D9461B3BB41900AAEE9D /* ASRelativeSize.mm in Sources */, CC4C2A781D88E3BF0039ACAB /* ASTraceEvent.m in Sources */, 205F0E121B371BD7007741D0 /* ASScrollDirection.m in Sources */, 9C8898BB1C738B9800D6B02E /* ASTextKitFontSizeAdjuster.mm in Sources */, @@ -2390,7 +2383,6 @@ CC4C2A791D88E3BF0039ACAB /* ASTraceEvent.m in Sources */, 34EFC76F1B701CF700AD841F /* ASRatioLayoutSpec.mm in Sources */, 254C6B8B1BF94F8A003EC431 /* ASTextKitShadower.mm in Sources */, - 34EFC7661B701CD200AD841F /* ASRelativeSize.mm in Sources */, 254C6B851BF94F8A003EC431 /* ASTextKitAttributes.mm in Sources */, 509E68601B3AED8E009B9150 /* ASScrollDirection.m in Sources */, B35062091B010EFD0018CF92 /* ASScrollNode.m in Sources */, diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index c8b8b49d4b..3a6fcae555 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -27,6 +27,7 @@ #import "ASRunLoopQueue.h" #import "ASEnvironmentInternal.h" #import "ASDimension.h" +#import "ASLayoutElementStylePrivate.h" #import "ASInternalHelpers.h" #import "ASLayout.h" @@ -3478,8 +3479,7 @@ ASEnvironmentLayoutExtensibilityForwarding ASDN::MutexLocker l(__instanceLock__); // Deprecated preferredFrameSize just calls through to set width and height - _style.width = ASDimensionMake(preferredFrameSize.width); - _style.height = ASDimensionMake(preferredFrameSize.height); + _style.preferredSize = preferredFrameSize; [self invalidateCalculatedLayout]; } diff --git a/AsyncDisplayKit/ASVideoNode.mm b/AsyncDisplayKit/ASVideoNode.mm index 36fb9b2ce6..c369a13caa 100644 --- a/AsyncDisplayKit/ASVideoNode.mm +++ b/AsyncDisplayKit/ASVideoNode.mm @@ -250,8 +250,7 @@ static NSString * const kRate = @"rate"; } if (_playerNode) { - _playerNode.style.width = ASDimensionMake(calculatedSize.width); - _playerNode.style.height = ASDimensionMake(calculatedSize.height); + _playerNode.style.preferredSize = calculatedSize; [_playerNode layoutThatFits:ASSizeRangeMake(CGSizeZero, calculatedSize)]; } diff --git a/AsyncDisplayKit/ASVideoPlayerNode.mm b/AsyncDisplayKit/ASVideoPlayerNode.mm index 408d45d6b9..573d38dd7f 100644 --- a/AsyncDisplayKit/ASVideoPlayerNode.mm +++ b/AsyncDisplayKit/ASVideoPlayerNode.mm @@ -324,8 +324,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext; { if (_playbackButtonNode == nil) { _playbackButtonNode = [[ASDefaultPlaybackButton alloc] init]; - _playbackButtonNode.style.width = ASDimensionMakeWithPoints(16.0); - _playbackButtonNode.style.height = ASDimensionMakeWithPoints(22.0); + _playbackButtonNode.style.preferredSize = CGSizeMake(16.0, 22.0); if (_delegateFlags.delegatePlaybackButtonTint) { _playbackButtonNode.tintColor = [_delegate videoPlayerNodePlaybackButtonTint:self]; @@ -601,8 +600,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext; return spinnnerView; }]; - _spinnerNode.style.width = ASDimensionMakeWithPoints(44.0); - _spinnerNode.style.height = ASDimensionMakeWithPoints(44.0); + _spinnerNode.style.preferredSize = CGSizeMake(44.0, 44.0); [self addSubnode:_spinnerNode]; [self setNeedsLayout]; @@ -706,7 +704,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext; maxSize = CGSizeZero; } - [_videoNode.style setSizeWithCGSize:maxSize]; + _videoNode.style.preferredSize = maxSize; ASLayoutSpec *layoutSpec; if (_delegateFlags.delegateLayoutSpecForControls) { @@ -719,12 +717,12 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext; if (_spinnerNode) { ASCenterLayoutSpec *centerLayoutSpec = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionDefault child:_spinnerNode]; - [centerLayoutSpec.style setSizeWithCGSize:maxSize]; + centerLayoutSpec.style.preferredSize = maxSize; [children addObject:centerLayoutSpec]; } ASOverlayLayoutSpec *overlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_videoNode overlay:layoutSpec]; - [overlaySpec.style setSizeWithCGSize:maxSize]; + overlaySpec.style.preferredSize = maxSize; [children addObject:overlaySpec]; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:children]; @@ -732,8 +730,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext; - (ASLayoutSpec *)defaultLayoutSpecThatFits:(CGSize)maxSize { - _scrubberNode.style.width = ASDimensionMakeWithPoints(maxSize.width); - _scrubberNode.style.height = ASDimensionMakeWithPoints(44.0); + _scrubberNode.style.preferredSize = CGSizeMake(maxSize.width, 44.0); ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; spacer.style.flexGrow = 1; diff --git a/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm b/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm index b6d228a842..780f7eb07a 100644 --- a/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASAbsoluteLayoutSpec.mm @@ -12,6 +12,7 @@ #import "ASLayoutSpecUtilities.h" #import "ASLayout.h" +#import "ASLayoutElementStylePrivate.h" @implementation ASAbsoluteLayoutSpec diff --git a/AsyncDisplayKit/Layout/ASDimension.h b/AsyncDisplayKit/Layout/ASDimension.h index 963b070e19..7c424e6e92 100644 --- a/AsyncDisplayKit/Layout/ASDimension.h +++ b/AsyncDisplayKit/Layout/ASDimension.h @@ -172,6 +172,32 @@ ASDISPLAYNODE_INLINE CGFloat ASDimensionResolve(ASDimension dimension, CGFloat p @end +#pragma mark - ASRelativeSize + +/** + * Expresses a size with relative dimensions. Only used for calculations internally in ASDimension.h + */ +typedef struct { + ASDimension width; + ASDimension height; +} ASRelativeSize; + +/* + * Creates an ASRelativeSize with provided min and max dimensions. + */ +ASDISPLAYNODE_INLINE ASRelativeSize ASRelativeSizeMake(ASDimension width, ASDimension height) +{ + ASRelativeSize size; + size.width = width; + size.height = height; + return size; +} + +/* + * Returns a string representation of a relative size. + */ +ASDISPLAYNODE_INLINE NSString *NSStringFromASRelativeSize(ASRelativeSize size); + #pragma mark - ASSizeRange /** @@ -217,7 +243,7 @@ ASDISPLAYNODE_INLINE CGSize ASSizeRangeClamp(ASSizeRange sizeRange, CGSize size) extern ASSizeRange ASSizeRangeIntersect(ASSizeRange sizeRange, ASSizeRange otherSizeRange); /** - * Returns whether two size ranges are equal in min and max size + * Returns whether two size ranges are equal in min and max size. */ ASDISPLAYNODE_INLINE BOOL ASSizeRangeEqualToSizeRange(ASSizeRange lhs, ASSizeRange rhs) { diff --git a/AsyncDisplayKit/Layout/ASDimension.mm b/AsyncDisplayKit/Layout/ASDimension.mm index a51389a18c..c09662a607 100644 --- a/AsyncDisplayKit/Layout/ASDimension.mm +++ b/AsyncDisplayKit/Layout/ASDimension.mm @@ -79,22 +79,6 @@ NSString *NSStringFromASDimension(ASDimension dimension) #pragma mark - ASRelativeSize -/** - * Expresses a size with relative dimensions. Only used for calculations internally in ASDimension.h - */ -typedef struct { - ASDimension width; - ASDimension height; -} ASRelativeSize; - -ASDISPLAYNODE_INLINE ASRelativeSize ASRelativeSizeMake(ASDimension width, ASDimension height) -{ - ASRelativeSize size; - size.width = width; - size.height = height; - return size; -} - // ** Resolve this relative size relative to a parent size. */ ASDISPLAYNODE_INLINE CGSize ASRelativeSizeResolveSize(ASRelativeSize relativeSize, CGSize parentSize, CGSize autoSize) { diff --git a/AsyncDisplayKit/Layout/ASLayoutElement.h b/AsyncDisplayKit/Layout/ASLayoutElement.h index 894574e133..b3d5a76757 100644 --- a/AsyncDisplayKit/Layout/ASLayoutElement.h +++ b/AsyncDisplayKit/Layout/ASLayoutElement.h @@ -68,6 +68,7 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign, readonly) ASLayoutElementStyle *style; + #pragma mark - Calculate layout /** @@ -188,12 +189,8 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty; */ @property (nullable, nonatomic, weak, readonly) id delegate; -#pragma mark - Sizing -/** - * @abstract A size constraint that should apply to this ASLayoutElement. - */ -@property (nonatomic, assign, readwrite) ASLayoutElementSize size; +#pragma mark - Sizing /** * @abstract The width property specifies the height of the content area of an ASLayoutElement. @@ -241,15 +238,68 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty; */ @property (nonatomic, assign, readwrite) ASDimension maxWidth; -/** - * @abstract Set max and width properties from given size - */ -- (void)setSizeWithCGSize:(CGSize)size; + +#pragma mark - ASLayoutElementStyleSizeHelpers /** - * @abstract Set minHeight, maxHeight and minWidth, maxWidth properties from given size + * @abstract Provides a suggested size for a layout element. If the optional minSize or maxSize are provided, + * and the preferredSize exceeds these, the minSize or maxSize will be enforced. If this optional value is not + * provided, the layout element’s size will default to it’s intrinsic content size provided calculateSizeThatFits: + * + * @discussion This method is optional, but one of either preferredSize or preferredRelativeSize is required + * for nodes that either have no intrinsic content size or + * should be laid out at a different size than its intrinsic content size. For example, this property could be + * set on an ASImageNode to display at a size different from the underlying image size. */ -- (void)setExactSizeWithCGSize:(CGSize)size; +@property (nonatomic, assign) CGSize preferredSize; +- (CGSize)preferredSize UNAVAILABLE_ATTRIBUTE; + + /** + * @abstract An optional property that provides a minimum size bound for a layout element. If provided, this restriction will + * always be enforced. If a parent layout element’s minimum size is smaller than its child’s minimum size, the child’s + * minimum size will be enforced and its size will extend out of the layout spec’s. + * + * @discussion For example, if you set a preferred relative width of 50% and a minimum width of 200 points on an + * element in a full screen container, this would result in a width of 160 points on an iPhone screen. However, + * since 160 pts is lower than the minimum width of 200 pts, the minimum width would be used. + */ +@property (nonatomic, assign) CGSize minSize; +- (CGSize)minSize UNAVAILABLE_ATTRIBUTE; + +/** + * @abstract An optional property that provides a maximum size bound for a layout element. If provided, this restriction will + * always be enforced. If a child layout element’s maximum size is smaller than its parent, the child’s maximum size will + * be enforced and its size will extend out of the layout spec’s. + * + * @discussion For example, if you set a preferred relative width of 50% and a maximum width of 120 points on an + * element in a full screen container, this would result in a width of 160 points on an iPhone screen. However, + * since 160 pts is higher than the maximum width of 120 pts, the maximum width would be used. + */ +@property (nonatomic, assign) CGSize maxSize; +- (CGSize)maxSize UNAVAILABLE_ATTRIBUTE; + +/** + * @abstract Provides a suggested RELATIVE size for a layout element. An ASRelativeSize uses percentages rather + * than points to specify layout. E.g. width should be 50% of the parent’s width. If the optional minRelativeSize or + * maxRelativeSize are provided, and the preferredRelativeSize exceeds these, the minRelativeSize or maxRelativeSize + * will be enforced. If this optional value is not provided, the layout element’s size will default to its intrinsic content size + * provided calculateSizeThatFits: + */ +@property (nonatomic, assign, readwrite) ASRelativeSize preferredRelativeSize; + +/** + * @abstract An optional property that provides a minimum RELATIVE size bound for a layout element. If provided, this + * restriction will always be enforced. If a parent layout element’s minimum relative size is smaller than its child’s minimum + * relative size, the child’s minimum relative size will be enforced and its size will extend out of the layout spec’s. + */ +@property (nonatomic, assign, readwrite) ASRelativeSize minRelativeSize; + +/** + * @abstract An optional property that provides a maximum RELATIVE size bound for a layout element. If provided, this + * restriction will always be enforced. If a parent layout element’s maximum relative size is smaller than its child’s maximum + * relative size, the child’s maximum relative size will be enforced and its size will extend out of the layout spec’s. + */ +@property (nonatomic, assign, readwrite) ASRelativeSize maxRelativeSize; #pragma mark - ASStackLayoutElement @@ -303,6 +353,7 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty; */ @property (nonatomic, assign) CGFloat descender; + #pragma mark - ASAbsoluteLayoutElement /** diff --git a/AsyncDisplayKit/Layout/ASLayoutElement.mm b/AsyncDisplayKit/Layout/ASLayoutElement.mm index a7e85e747d..bd687e678d 100644 --- a/AsyncDisplayKit/Layout/ASLayoutElement.mm +++ b/AsyncDisplayKit/Layout/ASLayoutElement.mm @@ -10,10 +10,7 @@ // of patent rights can be found in the PATENTS file in the same directory. // -#import "ASLayoutElementPrivate.h" -#import "ASEnvironmentInternal.h" #import "ASDisplayNodeInternal.h" -#import "ASThread.h" #import @@ -110,16 +107,13 @@ do {\ [_delegate style:self propertyDidChange:propertyName];\ } while(0) -@interface ASLayoutElementStyle () -@property (nullable, nonatomic, weak) id delegate; -@end - @implementation ASLayoutElementStyle { ASDN::RecursiveMutex __instanceLock__; ASLayoutElementSize _size; } @dynamic width, height, minWidth, maxWidth, minHeight, maxHeight; +@dynamic preferredSize, minSize, maxSize, preferredRelativeSize, minRelativeSize, maxRelativeSize; #pragma mark - Lifecycle @@ -141,7 +135,21 @@ do {\ return self; } -#pragma mark - ASLayoutElementSizeForwarding +#pragma mark - ASLayoutElementStyleSize + +- (ASLayoutElementSize)size +{ + ASDN::MutexLocker l(__instanceLock__); + return _size; +} + +- (void)setSize:(ASLayoutElementSize)size +{ + ASDN::MutexLocker l(__instanceLock__); + _size = size; +} + +#pragma mark - ASLayoutElementStyleSizeForwarding - (ASDimension)width { @@ -221,20 +229,64 @@ do {\ ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty); } -- (void)setSizeWithCGSize:(CGSize)size + +#pragma mark - ASLayoutElementStyleSizeHelpers + +- (void)setPreferredSize:(CGSize)preferredSize { - self.width = ASDimensionMakeWithPoints(size.width); - self.height = ASDimensionMakeWithPoints(size.height); + self.width = ASDimensionMakeWithPoints(preferredSize.width); + self.height = ASDimensionMakeWithPoints(preferredSize.height); } -- (void)setExactSizeWithCGSize:(CGSize)size +- (void)setMinSize:(CGSize)minSize { - self.minWidth = ASDimensionMakeWithPoints(size.width); - self.minHeight = ASDimensionMakeWithPoints(size.height); - self.maxWidth = ASDimensionMakeWithPoints(size.width); - self.maxHeight = ASDimensionMakeWithPoints(size.height); + self.minWidth = ASDimensionMakeWithPoints(minSize.width); + self.minHeight = ASDimensionMakeWithPoints(minSize.height); } +- (void)setMaxSize:(CGSize)maxSize +{ + self.maxWidth = ASDimensionMakeWithPoints(maxSize.width); + self.maxHeight = ASDimensionMakeWithPoints(maxSize.height); +} + +- (ASRelativeSize)preferredRelativeSize +{ + ASDN::MutexLocker l(__instanceLock__); + return ASRelativeSizeMake(_size.width, _size.height); +} + +- (void)setPreferredRelativeSize:(ASRelativeSize)preferredRelativeSize +{ + self.width = preferredRelativeSize.width; + self.height = preferredRelativeSize.height; +} + +- (ASRelativeSize)minRelativeSize +{ + ASDN::MutexLocker l(__instanceLock__); + return ASRelativeSizeMake(_size.minWidth, _size.minHeight); +} + +- (void)setMinRelativeSize:(ASRelativeSize)minRelativeSize +{ + self.minWidth = minRelativeSize.width; + self.minHeight = minRelativeSize.height; +} + +- (ASRelativeSize)maxRelativeSize +{ + ASDN::MutexLocker l(__instanceLock__); + return ASRelativeSizeMake(_size.maxWidth, _size.maxHeight); +} + +- (void)setMaxRelativeSize:(ASRelativeSize)maxRelativeSize +{ + self.maxWidth = maxRelativeSize.width; + self.maxHeight = maxRelativeSize.height; +} + + #pragma mark - ASStackLayoutElement - (void)setSpacingBefore:(CGFloat)spacingBefore diff --git a/AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h b/AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h new file mode 100644 index 0000000000..57d0a3c347 --- /dev/null +++ b/AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h @@ -0,0 +1,27 @@ +// +// ASLayoutElementStylePrivate.h +// AsyncDisplayKit +// +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// + +#pragma once + +@interface ASLayoutElementStyle () + +/** + * @abstract The object that acts as the delegate of the style. + * + * @discussion The delegate must adopt the ASLayoutElementStyleDelegate protocol. The delegate is not retained. + */ +@property (nullable, nonatomic, weak) id delegate; + +/** + * @abstract A size constraint that should apply to this ASLayoutElement. + */ +@property (nonatomic, assign, readonly) ASLayoutElementSize size; + +@end diff --git a/AsyncDisplayKit/Layout/ASLayoutSpec.mm b/AsyncDisplayKit/Layout/ASLayoutSpec.mm index c5c226b5de..532847800c 100644 --- a/AsyncDisplayKit/Layout/ASLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASLayoutSpec.mm @@ -12,6 +12,8 @@ #import "ASLayoutSpecPrivate.h" #import "ASLayoutSpec+Subclasses.h" +#import "ASLayoutElementStylePrivate.h" + @implementation ASLayoutSpec // Dynamic properties for ASLayoutElements diff --git a/AsyncDisplayKit/Layout/ASRelativeSize.h b/AsyncDisplayKit/Layout/ASRelativeSize.h deleted file mode 100644 index 38c0a3b926..0000000000 --- a/AsyncDisplayKit/Layout/ASRelativeSize.h +++ /dev/null @@ -1,11 +0,0 @@ -// -// ASRelativeSize.h -// AsyncDisplayKit -// -// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. -// This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. -// - -// TODO: layout: Remove file diff --git a/AsyncDisplayKit/Layout/ASRelativeSize.mm b/AsyncDisplayKit/Layout/ASRelativeSize.mm deleted file mode 100644 index e43980af71..0000000000 --- a/AsyncDisplayKit/Layout/ASRelativeSize.mm +++ /dev/null @@ -1,11 +0,0 @@ -// -// ASRelativeSize.mm -// AsyncDisplayKit -// -// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. -// This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. -// - -// TODO: layout: Remove file diff --git a/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm b/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm index 98c4da8aca..395c2a2b8b 100644 --- a/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm +++ b/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm @@ -14,6 +14,7 @@ #import #import "ASLayoutSpecUtilities.h" +#import "ASLayoutElementStylePrivate.h" static CGFloat resolveCrossDimensionMaxForStretchChild(const ASStackLayoutSpecStyle &style, const idchild, diff --git a/AsyncDisplayKitTests/ASDisplayNodeLayoutTests.mm b/AsyncDisplayKitTests/ASDisplayNodeLayoutTests.mm index ee213fe86a..1862064fc3 100644 --- a/AsyncDisplayKitTests/ASDisplayNodeLayoutTests.mm +++ b/AsyncDisplayKitTests/ASDisplayNodeLayoutTests.mm @@ -80,7 +80,8 @@ CGSize nodeSize = CGSizeMake(100, 100); ASDisplayNode *displayNode = [ASDisplayNode new]; - [displayNode.style setSizeWithCGSize:nodeSize]; + displayNode.style.width = ASDimensionMake(nodeSize.width); + displayNode.style.height = ASDimensionMake(nodeSize.height); ASButtonNode *buttonNode = [ASButtonNode new]; [displayNode addSubnode:buttonNode]; diff --git a/AsyncDisplayKitTests/ASImageNodeSnapshotTests.m b/AsyncDisplayKitTests/ASImageNodeSnapshotTests.m index 5f724585b8..55706583a5 100644 --- a/AsyncDisplayKitTests/ASImageNodeSnapshotTests.m +++ b/AsyncDisplayKitTests/ASImageNodeSnapshotTests.m @@ -44,11 +44,13 @@ imageNode.image = [self testImage]; // Snapshot testing requires that node is formally laid out. - [imageNode.style setSizeWithCGSize:forcedImageSize]; + imageNode.style.width = ASDimensionMake(forcedImageSize.width); + imageNode.style.height = ASDimensionMake(forcedImageSize.height); [imageNode layoutThatFits:ASSizeRangeMake(CGSizeZero, forcedImageSize)]; ASSnapshotVerifyNode(imageNode, @"first"); - [imageNode.style setSizeWithCGSize:CGSizeMake(200, 200)]; + imageNode.style.width = ASDimensionMake(200); + imageNode.style.height = ASDimensionMake(200); [imageNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(200, 200))]; ASSnapshotVerifyNode(imageNode, @"second"); diff --git a/AsyncDisplayKitTests/ASLayoutElementStyleTests.m b/AsyncDisplayKitTests/ASLayoutElementStyleTests.m index e51dc6819b..ecdbeff6bf 100644 --- a/AsyncDisplayKitTests/ASLayoutElementStyleTests.m +++ b/AsyncDisplayKitTests/ASLayoutElementStyleTests.m @@ -34,34 +34,68 @@ @implementation ASLayoutElementStyleTests -- (void)testSettingSizeProperties +- (void)testSettingSize { ASLayoutElementStyle *style = [ASLayoutElementStyle new]; + style.width = ASDimensionMake(100); style.height = ASDimensionMake(100); + XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMake(100))); + XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(100))); + style.minWidth = ASDimensionMake(100); + style.minHeight = ASDimensionMake(100); + XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMake(100))); + XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(100))); + + style.maxWidth = ASDimensionMake(100); + style.maxHeight = ASDimensionMake(100); XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMake(100))); XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(100))); } -- (void)testSettingSizeViaHelper +- (void)testSettingSizeViaCGSize { ASLayoutElementStyle *style = [ASLayoutElementStyle new]; - [style setSizeWithCGSize:CGSizeMake(100, 100)]; - XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMake(100))); - XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(100))); + CGSize size = CGSizeMake(100, 100); + + style.preferredSize = size; + XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMakeWithPoints(size.width))); + XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMakeWithPoints(size.height))); + + style.minSize = size; + XCTAssertTrue(ASDimensionEqualToDimension(style.minWidth, ASDimensionMakeWithPoints(size.width))); + XCTAssertTrue(ASDimensionEqualToDimension(style.minHeight, ASDimensionMakeWithPoints(size.height))); + + style.maxSize = size; + XCTAssertTrue(ASDimensionEqualToDimension(style.maxWidth, ASDimensionMakeWithPoints(size.width))); + XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, ASDimensionMakeWithPoints(size.height))); } -- (void)testSettingExactSize +- (void)setSettingSizeViaRelativeSize { ASLayoutElementStyle *style = [ASLayoutElementStyle new]; - [style setExactSizeWithCGSize:CGSizeMake(100, 100)]; - XCTAssertTrue(ASDimensionEqualToDimension(style.minWidth, ASDimensionMake(100))); - XCTAssertTrue(ASDimensionEqualToDimension(style.minHeight, ASDimensionMake(100))); - XCTAssertTrue(ASDimensionEqualToDimension(style.maxWidth, ASDimensionMake(100))); - XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, ASDimensionMake(100))); + ASRelativeSize relativeSize = ASRelativeSizeMake(ASDimensionMake(100), ASDimensionMake(100)); + + style.preferredRelativeSize = relativeSize; + XCTAssertTrue(ASDimensionEqualToDimension(style.width, relativeSize.width)); + XCTAssertTrue(ASDimensionEqualToDimension(style.height, relativeSize.height)); + XCTAssertTrue(ASDimensionEqualToDimension(style.preferredRelativeSize.width, relativeSize.width)); + XCTAssertTrue(ASDimensionEqualToDimension(style.preferredRelativeSize.height, relativeSize.height)); + + style.minRelativeSize = relativeSize; + XCTAssertTrue(ASDimensionEqualToDimension(style.minWidth, relativeSize.width)); + XCTAssertTrue(ASDimensionEqualToDimension(style.minHeight, relativeSize.height)); + XCTAssertTrue(ASDimensionEqualToDimension(style.minRelativeSize.width, relativeSize.width)); + XCTAssertTrue(ASDimensionEqualToDimension(style.minRelativeSize.height, relativeSize.height)); + + style.maxRelativeSize = relativeSize; + XCTAssertTrue(ASDimensionEqualToDimension(style.maxWidth, relativeSize.width)); + XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, relativeSize.height)); + XCTAssertTrue(ASDimensionEqualToDimension(style.maxRelativeSize.width, relativeSize.width)); + XCTAssertTrue(ASDimensionEqualToDimension(style.maxRelativeSize.height, relativeSize.height)); } - (void)testSettingPropertiesWillCallDelegate diff --git a/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm b/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm index 18566e69c0..9a1771c7c8 100644 --- a/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm +++ b/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm @@ -799,7 +799,8 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node) ASStackLayoutSpec *stackLayoutSpec = [[ASStackLayoutSpec alloc] init]; // Default direction is horizontal stackLayoutSpec.direction = ASStackLayoutDirectionHorizontal; stackLayoutSpec.alignItems = ASStackLayoutAlignItemsStretch; - [stackLayoutSpec.style setSizeWithCGSize:{100, 100}]; + stackLayoutSpec.style.width = ASDimensionMake(100); + stackLayoutSpec.style.height = ASDimensionMake(100); ASDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50}); stackLayoutSpec.children = @[child]; diff --git a/examples/ASDKgram/Sample/PhotoCellNode.m b/examples/ASDKgram/Sample/PhotoCellNode.m index 6d23e83f13..4b22f0be4b 100644 --- a/examples/ASDKgram/Sample/PhotoCellNode.m +++ b/examples/ASDKgram/Sample/PhotoCellNode.m @@ -127,8 +127,7 @@ // header stack // constrain avatar image frame size - _userAvatarImageView.style.width = ASDimensionMakeWithPoints(USER_IMAGE_HEIGHT); - _userAvatarImageView.style.height = ASDimensionMakeWithPoints(USER_IMAGE_HEIGHT); + _userAvatarImageView.style.preferredSize = CGSizeMake(USER_IMAGE_HEIGHT, USER_IMAGE_HEIGHT); _photoTimeIntervalSincePostLabel.style.spacingBefore = HORIZONTAL_BUFFER; // to remove double spaces around spacer ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; // FIXME: long locations overflow post time - set max size? @@ -159,8 +158,7 @@ CGFloat cellWidth = constrainedSize.max.width; // constrain photo frame size - _photoImageView.style.width = ASDimensionMakeWithPoints(cellWidth); - _photoImageView.style.height = ASDimensionMakeWithPoints(cellWidth); + _photoImageView.style.preferredSize = CGSizeMake(cellWidth, cellWidth); ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec]; verticalStack.alignItems = ASStackLayoutAlignItemsStretch; // stretch headerStack to fill horizontal space diff --git a/examples/ASMapNode/Sample/MapHandlerNode.m b/examples/ASMapNode/Sample/MapHandlerNode.m index 45c871bb49..1a1cd8e314 100644 --- a/examples/ASMapNode/Sample/MapHandlerNode.m +++ b/examples/ASMapNode/Sample/MapHandlerNode.m @@ -117,14 +117,14 @@ #define HEIGHT 30 CGSize nodeSize = CGSizeMake(constrainedSize.max.width * 0.3, HEIGHT); - [_latEditableNode.style setSizeWithCGSize:nodeSize]; - [_lonEditableNode.style setSizeWithCGSize:nodeSize]; + _latEditableNode.style.preferredSize = nodeSize; + _lonEditableNode.style.preferredSize = nodeSize; - [_deltaLatEditableNode.style setSizeWithCGSize:nodeSize]; - [_deltaLonEditableNode.style setSizeWithCGSize:nodeSize]; + _deltaLatEditableNode.style.preferredSize = nodeSize; + _deltaLonEditableNode.style.preferredSize = nodeSize; - [_updateRegionButton.style setSizeWithCGSize:nodeSize]; - [_liveMapToggleButton.style setSizeWithCGSize:nodeSize]; + _updateRegionButton.style.preferredSize = nodeSize; + _liveMapToggleButton.style.preferredSize = nodeSize; _latEditableNode.style.flexGrow = _lonEditableNode.style.flexGrow = YES; _deltaLatEditableNode.style.flexGrow = _deltaLonEditableNode.style.flexGrow = YES; diff --git a/examples/ASViewController/Sample/DetailCellNode.m b/examples/ASViewController/Sample/DetailCellNode.m index adba6917ee..f2355fcbb9 100644 --- a/examples/ASViewController/Sample/DetailCellNode.m +++ b/examples/ASViewController/Sample/DetailCellNode.m @@ -39,7 +39,7 @@ - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { self.imageNode.position = CGPointZero; - [self.imageNode.style setSizeWithCGSize:constrainedSize.max]; + self.imageNode.style.preferredSize = constrainedSize.max; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.imageNode]]; } diff --git a/examples/ASViewController/Sample/DetailRootNode.m b/examples/ASViewController/Sample/DetailRootNode.m index 3292bfda6f..bec6b4dceb 100644 --- a/examples/ASViewController/Sample/DetailRootNode.m +++ b/examples/ASViewController/Sample/DetailRootNode.m @@ -63,7 +63,7 @@ static const NSInteger kImageHeight = 200; - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { self.collectionNode.position = CGPointZero; - [self.collectionNode.style setSizeWithCGSize:constrainedSize.max]; + self.collectionNode.style.preferredSize = constrainedSize.max; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.collectionNode]]; } diff --git a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m index 99934764a2..7dbe996d02 100644 --- a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m +++ b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m @@ -208,7 +208,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr CGSize imageNetworkImageNodeSize = (CGSize){imageNode.image.size.width / 7, imageNode.image.size.height / 7}; - [imageNode.style setSizeWithCGSize:imageNetworkImageNodeSize]; + imageNode.style.preferredSize = imageNetworkImageNodeSize; parentNode = [self centeringParentNodeWithChild:imageNode]; parentNode.entryTitle = @"ASImageNode"; @@ -218,7 +218,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr #pragma mark ASNetworkImageNode ASNetworkImageNode *networkImageNode = [ASNetworkImageNode new]; networkImageNode.URL = [NSURL URLWithString:@"http://i.imgur.com/FjOR9kX.jpg"]; - [networkImageNode.style setSizeWithCGSize:imageNetworkImageNodeSize]; + networkImageNode.style.preferredSize = imageNetworkImageNodeSize; parentNode = [self centeringParentNodeWithChild:networkImageNode]; parentNode.entryTitle = @"ASNetworkImageNode"; @@ -227,7 +227,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr #pragma mark ASMapNode ASMapNode *mapNode = [ASMapNode new]; - [mapNode.style setSizeWithCGSize:CGSizeMake(300.0, 300.0)]; + mapNode.style.preferredSize = CGSizeMake(300.0, 300.0); // San Francisco CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194); @@ -240,7 +240,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr #pragma mark ASVideoNode ASVideoNode *videoNode = [ASVideoNode new]; - [videoNode.style setSizeWithCGSize:CGSizeMake(300.0, 400.0)]; + videoNode.style.preferredSize = CGSizeMake(300.0, 400.0); AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:@"http://www.w3schools.com/html/mov_bbb.mp4"]]; videoNode.asset = asset; @@ -254,7 +254,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr UIImage *scrollNodeImage = [UIImage imageNamed:@"image"]; ASScrollNode *scrollNode = [ASScrollNode new]; - [scrollNode.style setSizeWithCGSize:CGSizeMake(300.0, 400.0)]; + scrollNode.style.preferredSize = CGSizeMake(300.0, 400.0); UIScrollView *scrollNodeView = scrollNode.view; [scrollNodeView addSubview:[[UIImageView alloc] initWithImage:scrollNodeImage]]; @@ -406,17 +406,17 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr #pragma mark Horizontal ASStackLayoutSpec childNode1 = [ASDisplayNode new]; - [childNode1.style setSizeWithCGSize:CGSizeMake(10.0, 20.0)]; + childNode1.style.preferredSize = CGSizeMake(10.0, 20.0); childNode1.style.flexGrow = YES; childNode1.backgroundColor = [UIColor greenColor]; childNode2 = [ASDisplayNode new]; - [childNode2.style setSizeWithCGSize:CGSizeMake(10.0, 20.0)]; + childNode2.style.preferredSize = CGSizeMake(10.0, 20.0); childNode2.style.alignSelf = ASStackLayoutAlignSelfStretch; childNode2.backgroundColor = [UIColor blueColor]; childNode3 = [ASDisplayNode new]; - [childNode3.style setSizeWithCGSize:CGSizeMake(10.0, 20.0)]; + childNode3.style.preferredSize = CGSizeMake(10.0, 20.0); childNode3.backgroundColor = [UIColor yellowColor]; parentNode = [self parentNodeWithChild:childNode]; @@ -467,7 +467,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr - (OverviewDisplayNodeWithSizeBlock *)parentNodeWithChild:(ASDisplayNode *)child { OverviewDisplayNodeWithSizeBlock *parentNode = [OverviewDisplayNodeWithSizeBlock new]; - [parentNode.style setSizeWithCGSize:CGSizeMake(100, 100)]; + parentNode.style.preferredSize = CGSizeMake(100, 100); parentNode.backgroundColor = [UIColor redColor]; return parentNode; } @@ -491,7 +491,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr - (ASDisplayNode *)childNode { ASDisplayNode *childNode = [ASDisplayNode new]; - [childNode.style setSizeWithCGSize:CGSizeMake(50, 50)]; + childNode.style.preferredSize = CGSizeMake(50, 50); childNode.backgroundColor = [UIColor blueColor]; return childNode; } diff --git a/examples/CatDealsCollectionView/Sample/LoadingNode.m b/examples/CatDealsCollectionView/Sample/LoadingNode.m index 408546418b..b9b4f9788f 100644 --- a/examples/CatDealsCollectionView/Sample/LoadingNode.m +++ b/examples/CatDealsCollectionView/Sample/LoadingNode.m @@ -53,7 +53,7 @@ static CGFloat kFixedHeight = 200.0f; [spinner startAnimating]; return spinner; }]; - [_loadingSpinner.style setSizeWithCGSize:CGSizeMake(50, 50)]; + _loadingSpinner.style.preferredSize = CGSizeMake(50, 50); // add it as a subnode, and we're done [self addSubnode:_loadingSpinner]; diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm b/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm index 7716001b40..e070c4fbe9 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm +++ b/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm @@ -79,7 +79,7 @@ static const CGFloat kInnerPadding = 10.0f; CGSize elementSize = _elementSize; return ^{ RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init]; - [elementNode.style setSizeWithCGSize:elementSize]; + elementNode.style.preferredSize = elementSize; return elementNode; }; } @@ -87,7 +87,7 @@ static const CGFloat kInnerPadding = 10.0f; - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { CGSize collectionNodeSize = CGSizeMake(constrainedSize.max.width, _elementSize.height); - [_collectionNode.style setSizeWithCGSize:collectionNodeSize]; + _collectionNode.style.preferredSize = collectionNodeSize; ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init]; insetSpec.insets = UIEdgeInsetsMake(kOuterPadding, 0.0, kOuterPadding, 0.0); diff --git a/examples/Kittens/Sample/KittenNode.mm b/examples/Kittens/Sample/KittenNode.mm index 6a92e0f1f0..2313338ea3 100644 --- a/examples/Kittens/Sample/KittenNode.mm +++ b/examples/Kittens/Sample/KittenNode.mm @@ -145,7 +145,7 @@ static const CGFloat kInnerPadding = 10.0f; { // Set an intrinsic size for the image node CGSize imageSize = _isImageEnlarged ? CGSizeMake(2.0 * kImageSize, 2.0 * kImageSize) : CGSizeMake(kImageSize, kImageSize); - [_imageNode.style setSizeWithCGSize:imageSize]; + _imageNode.style.preferredSize = imageSize; // Shrink the text node in case the image + text gonna be too wide _textNode.style.flexShrink = YES; diff --git a/examples/SocialAppLayout/Sample/PostNode.m b/examples/SocialAppLayout/Sample/PostNode.m index bf4f57c7a1..945635c733 100644 --- a/examples/SocialAppLayout/Sample/PostNode.m +++ b/examples/SocialAppLayout/Sample/PostNode.m @@ -20,7 +20,6 @@ #import "TextStyles.h" #import "LikesNode.h" #import "CommentsNode.h" -#import "ASRelativeSize.h" #define PostNodeDividerColor [UIColor lightGrayColor] diff --git a/examples/VerticalWithinHorizontalScrolling/Sample/GradientTableNode.mm b/examples/VerticalWithinHorizontalScrolling/Sample/GradientTableNode.mm index ea873564a8..907fa16a4e 100644 --- a/examples/VerticalWithinHorizontalScrolling/Sample/GradientTableNode.mm +++ b/examples/VerticalWithinHorizontalScrolling/Sample/GradientTableNode.mm @@ -68,7 +68,7 @@ - (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath { RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init]; - [elementNode.style setSizeWithCGSize:_elementSize]; + elementNode.style.preferredSize = _elementSize; elementNode.indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:_pageNumber]; return elementNode; } diff --git a/examples/VerticalWithinHorizontalScrolling/Sample/ViewController.m b/examples/VerticalWithinHorizontalScrolling/Sample/ViewController.m index fe759d4fc7..0e8be6ed5a 100644 --- a/examples/VerticalWithinHorizontalScrolling/Sample/ViewController.m +++ b/examples/VerticalWithinHorizontalScrolling/Sample/ViewController.m @@ -77,7 +77,7 @@ CGSize boundsSize = pagerNode.bounds.size; CGSize gradientRowSize = CGSizeMake(boundsSize.width, 100); GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize]; - [node.style setSizeWithCGSize:boundsSize]; + node.style.preferredSize = boundsSize; node.pageNumber = index; return node; } diff --git a/examples/Videos/Sample/ViewController.m b/examples/Videos/Sample/ViewController.m index a4a4dea5e2..b372b41786 100644 --- a/examples/Videos/Sample/ViewController.m +++ b/examples/Videos/Sample/ViewController.m @@ -54,16 +54,16 @@ _rootNode.layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) { // Layout all nodes absolute in a static layout spec - [guitarVideoNode.style setSizeWithCGSize:CGSizeMake(mainScreenBoundsSize.width, mainScreenBoundsSize.height / 3.0)]; + guitarVideoNode.style.preferredSize = CGSizeMake(mainScreenBoundsSize.width, mainScreenBoundsSize.height / 3.0); guitarVideoNode.style.layoutPosition = CGPointMake(0, 0); - [nicCageVideoNode.style setSizeWithCGSize:CGSizeMake(mainScreenBoundsSize.width/2, mainScreenBoundsSize.height / 3.0)]; + nicCageVideoNode.style.preferredSize = CGSizeMake(mainScreenBoundsSize.width/2, mainScreenBoundsSize.height / 3.0); nicCageVideoNode.style.layoutPosition = CGPointMake(mainScreenBoundsSize.width / 2.0, mainScreenBoundsSize.height / 3.0); - [simonVideoNode.style setSizeWithCGSize:CGSizeMake(mainScreenBoundsSize.width/2, mainScreenBoundsSize.height / 3.0)]; + simonVideoNode.style.preferredSize = CGSizeMake(mainScreenBoundsSize.width/2, mainScreenBoundsSize.height / 3.0); simonVideoNode.style.layoutPosition = CGPointMake(0.0, mainScreenBoundsSize.height - (mainScreenBoundsSize.height / 3.0)); - [hlsVideoNode.style setSizeWithCGSize:CGSizeMake(mainScreenBoundsSize.width / 2.0, mainScreenBoundsSize.height / 3.0)]; + hlsVideoNode.style.preferredSize = CGSizeMake(mainScreenBoundsSize.width / 2.0, mainScreenBoundsSize.height / 3.0); hlsVideoNode.style.layoutPosition = CGPointMake(0.0, mainScreenBoundsSize.height / 3.0); return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[guitarVideoNode, nicCageVideoNode, simonVideoNode, hlsVideoNode]];