[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
This commit is contained in:
Michael Schneider 2016-10-04 09:35:45 -07:00 committed by Adlai Holler
parent f027a8be80
commit d6e5e27c39
30 changed files with 288 additions and 143 deletions

View File

@ -136,8 +136,6 @@
34EFC7621B701CA400AD841F /* ASBackgroundLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED021B17843500DA7C62 /* ASBackgroundLayoutSpec.mm */; }; 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, ); }; }; 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 */; }; 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, ); }; }; 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 */; }; 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, ); }; }; 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, ); }; }; 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, ); }; }; 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 */; }; 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 */; }; 69CB62AC1CB8165900024920 /* _ASDisplayViewAccessiblity.h in Headers */ = {isa = PBXBuildFile; fileRef = 69CB62A91CB8165900024920 /* _ASDisplayViewAccessiblity.h */; };
69CB62AD1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */; }; 69CB62AD1CB8165900024920 /* _ASDisplayViewAccessiblity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */; };
69CB62AE1CB8165900024920 /* _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 */; }; AC026B721BD57DBF00BBC17E /* _ASHierarchyChangeSet.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC026B6E1BD57DBF00BBC17E /* _ASHierarchyChangeSet.mm */; };
AC3C4A521A1139C100143C57 /* ASCollectionView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC3C4A501A1139C100143C57 /* ASCollectionView.mm */; }; AC3C4A521A1139C100143C57 /* ASCollectionView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC3C4A501A1139C100143C57 /* ASCollectionView.mm */; };
AC47D9421B3B891B00AAEE9D /* ASCellNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC6456071B0A335000CF11B8 /* ASCellNode.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 */; }; AC6145411D8AFAE8003D62A2 /* ASSection.h in Headers */ = {isa = PBXBuildFile; fileRef = AC6145401D8AFAE8003D62A2 /* ASSection.h */; };
AC6145431D8AFD4F003D62A2 /* ASSection.m in Sources */ = {isa = PBXBuildFile; fileRef = AC6145421D8AFD4F003D62A2 /* ASSection.m */; }; AC6145431D8AFD4F003D62A2 /* ASSection.m in Sources */ = {isa = PBXBuildFile; fileRef = AC6145421D8AFD4F003D62A2 /* ASSection.m */; };
AC6145441D8AFD4F003D62A2 /* 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 */; }; F7CE6C641D2CDB3E00BE4C15 /* ASOverlayLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED121B17843500DA7C62 /* ASOverlayLayoutSpec.h */; };
F7CE6C651D2CDB3E00BE4C15 /* ASRatioLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED141B17843500DA7C62 /* ASRatioLayoutSpec.h */; }; F7CE6C651D2CDB3E00BE4C15 /* ASRatioLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED141B17843500DA7C62 /* ASRatioLayoutSpec.h */; };
F7CE6C661D2CDB3E00BE4C15 /* ASRelativeLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7A06A7391C35F08800FE8DAA /* ASRelativeLayoutSpec.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 */; }; F7CE6C681D2CDB3E00BE4C15 /* ASStackLayoutElement.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */; };
F7CE6C691D2CDB3E00BE4C15 /* ASStackLayoutDefines.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */; }; F7CE6C691D2CDB3E00BE4C15 /* ASStackLayoutDefines.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */; };
F7CE6C6A1D2CDB3E00BE4C15 /* ASStackLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */; }; F7CE6C6A1D2CDB3E00BE4C15 /* ASStackLayoutSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */; };
@ -737,7 +734,6 @@
F7CE6C641D2CDB3E00BE4C15 /* ASOverlayLayoutSpec.h in CopyFiles */, F7CE6C641D2CDB3E00BE4C15 /* ASOverlayLayoutSpec.h in CopyFiles */,
F7CE6C651D2CDB3E00BE4C15 /* ASRatioLayoutSpec.h in CopyFiles */, F7CE6C651D2CDB3E00BE4C15 /* ASRatioLayoutSpec.h in CopyFiles */,
F7CE6C661D2CDB3E00BE4C15 /* ASRelativeLayoutSpec.h in CopyFiles */, F7CE6C661D2CDB3E00BE4C15 /* ASRelativeLayoutSpec.h in CopyFiles */,
F7CE6C671D2CDB3E00BE4C15 /* ASRelativeSize.h in CopyFiles */,
F7CE6C681D2CDB3E00BE4C15 /* ASStackLayoutElement.h in CopyFiles */, F7CE6C681D2CDB3E00BE4C15 /* ASStackLayoutElement.h in CopyFiles */,
F7CE6C691D2CDB3E00BE4C15 /* ASStackLayoutDefines.h in CopyFiles */, F7CE6C691D2CDB3E00BE4C15 /* ASStackLayoutDefines.h in CopyFiles */,
F7CE6C6A1D2CDB3E00BE4C15 /* ASStackLayoutSpec.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 = "<group>"; }; 698C8B601CAB49FC0052DC3F /* ASLayoutElementExtensibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASLayoutElementExtensibility.h; path = AsyncDisplayKit/Layout/ASLayoutElementExtensibility.h; sourceTree = "<group>"; };
69B225661D72535E00B25B22 /* ASDisplayNodeLayoutTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDisplayNodeLayoutTests.mm; sourceTree = "<group>"; }; 69B225661D72535E00B25B22 /* ASDisplayNodeLayoutTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDisplayNodeLayoutTests.mm; sourceTree = "<group>"; };
69B225681D7265DA00B25B22 /* ASXCTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASXCTExtensions.h; sourceTree = "<group>"; }; 69B225681D7265DA00B25B22 /* ASXCTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASXCTExtensions.h; sourceTree = "<group>"; };
69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASLayoutElementStylePrivate.h; path = AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h; sourceTree = "<group>"; };
69CB62A91CB8165900024920 /* _ASDisplayViewAccessiblity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _ASDisplayViewAccessiblity.h; sourceTree = "<group>"; }; 69CB62A91CB8165900024920 /* _ASDisplayViewAccessiblity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _ASDisplayViewAccessiblity.h; sourceTree = "<group>"; };
69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _ASDisplayViewAccessiblity.mm; sourceTree = "<group>"; }; 69CB62AA1CB8165900024920 /* _ASDisplayViewAccessiblity.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _ASDisplayViewAccessiblity.mm; sourceTree = "<group>"; };
69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASEnvironmentInternal.h; sourceTree = "<group>"; }; 69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASEnvironmentInternal.h; sourceTree = "<group>"; };
@ -1049,8 +1046,6 @@
AC3C4A4F1A1139C100143C57 /* ASCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ASCollectionView.h; sourceTree = "<group>"; }; AC3C4A4F1A1139C100143C57 /* ASCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ASCollectionView.h; sourceTree = "<group>"; };
AC3C4A501A1139C100143C57 /* ASCollectionView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = ASCollectionView.mm; sourceTree = "<group>"; }; AC3C4A501A1139C100143C57 /* ASCollectionView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = ASCollectionView.mm; sourceTree = "<group>"; };
AC3C4A531A113EEC00143C57 /* ASCollectionViewProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionViewProtocols.h; sourceTree = "<group>"; }; AC3C4A531A113EEC00143C57 /* ASCollectionViewProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionViewProtocols.h; sourceTree = "<group>"; };
AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASRelativeSize.h; path = AsyncDisplayKit/Layout/ASRelativeSize.h; sourceTree = "<group>"; };
AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASRelativeSize.mm; path = AsyncDisplayKit/Layout/ASRelativeSize.mm; sourceTree = "<group>"; };
AC6145401D8AFAE8003D62A2 /* ASSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASSection.h; path = ../Private/ASSection.h; sourceTree = "<group>"; }; AC6145401D8AFAE8003D62A2 /* ASSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASSection.h; path = ../Private/ASSection.h; sourceTree = "<group>"; };
AC6145421D8AFD4F003D62A2 /* ASSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ASSection.m; path = ../Private/ASSection.m; sourceTree = "<group>"; }; AC6145421D8AFD4F003D62A2 /* ASSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ASSection.m; path = ../Private/ASSection.m; sourceTree = "<group>"; };
AC6456071B0A335000CF11B8 /* ASCellNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCellNode.mm; sourceTree = "<group>"; }; AC6456071B0A335000CF11B8 /* ASCellNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCellNode.mm; sourceTree = "<group>"; };
@ -1669,6 +1664,9 @@
AC6456051B0A333200CF11B8 /* Layout */ = { AC6456051B0A333200CF11B8 /* Layout */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9C6BB3B01B8CC9C200F13F52 /* ASAbsoluteLayoutElement.h */,
ACF6ED181B17843500DA7C62 /* ASAbsoluteLayoutSpec.h */,
ACF6ED191B17843500DA7C62 /* ASAbsoluteLayoutSpec.mm */,
9C5586671BD549CB00B50E3A /* ASAsciiArtBoxCreator.h */, 9C5586671BD549CB00B50E3A /* ASAsciiArtBoxCreator.h */,
9C5586681BD549CB00B50E3A /* ASAsciiArtBoxCreator.m */, 9C5586681BD549CB00B50E3A /* ASAsciiArtBoxCreator.m */,
ACF6ED011B17843500DA7C62 /* ASBackgroundLayoutSpec.h */, ACF6ED011B17843500DA7C62 /* ASBackgroundLayoutSpec.h */,
@ -1685,6 +1683,7 @@
E55D86311CA8A14000A0C26F /* ASLayoutElement.mm */, E55D86311CA8A14000A0C26F /* ASLayoutElement.mm */,
698C8B601CAB49FC0052DC3F /* ASLayoutElementExtensibility.h */, 698C8B601CAB49FC0052DC3F /* ASLayoutElementExtensibility.h */,
9CDC18CB1B910E12004965E2 /* ASLayoutElementPrivate.h */, 9CDC18CB1B910E12004965E2 /* ASLayoutElementPrivate.h */,
69C4CAF51DA3147000B1EC9B /* ASLayoutElementStylePrivate.h */,
ACF6ED0D1B17843500DA7C62 /* ASLayoutSpec.h */, ACF6ED0D1B17843500DA7C62 /* ASLayoutSpec.h */,
ACF6ED0E1B17843500DA7C62 /* ASLayoutSpec.mm */, ACF6ED0E1B17843500DA7C62 /* ASLayoutSpec.mm */,
6977965D1D8AC8D3007E93D7 /* ASLayoutSpec+Subclasses.h */, 6977965D1D8AC8D3007E93D7 /* ASLayoutSpec+Subclasses.h */,
@ -1695,15 +1694,10 @@
ACF6ED151B17843500DA7C62 /* ASRatioLayoutSpec.mm */, ACF6ED151B17843500DA7C62 /* ASRatioLayoutSpec.mm */,
7A06A7391C35F08800FE8DAA /* ASRelativeLayoutSpec.h */, 7A06A7391C35F08800FE8DAA /* ASRelativeLayoutSpec.h */,
7A06A7381C35F08800FE8DAA /* ASRelativeLayoutSpec.mm */, 7A06A7381C35F08800FE8DAA /* ASRelativeLayoutSpec.mm */,
AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */,
AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */,
9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */,
AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */, AC21EC0F1B3D0BF600C8B19A /* ASStackLayoutDefines.h */,
9C49C36E1B853957000B0DD5 /* ASStackLayoutElement.h */,
ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */, ACF6ED161B17843500DA7C62 /* ASStackLayoutSpec.h */,
ACF6ED171B17843500DA7C62 /* ASStackLayoutSpec.mm */, ACF6ED171B17843500DA7C62 /* ASStackLayoutSpec.mm */,
9C6BB3B01B8CC9C200F13F52 /* ASAbsoluteLayoutElement.h */,
ACF6ED181B17843500DA7C62 /* ASAbsoluteLayoutSpec.h */,
ACF6ED191B17843500DA7C62 /* ASAbsoluteLayoutSpec.mm */,
); );
name = Layout; name = Layout;
path = ..; path = ..;
@ -1808,6 +1802,7 @@
B35062191B010EFD0018CF92 /* ASDealloc2MainObject.h in Headers */, B35062191B010EFD0018CF92 /* ASDealloc2MainObject.h in Headers */,
34EFC75B1B701BAF00AD841F /* ASDimension.h in Headers */, 34EFC75B1B701BAF00AD841F /* ASDimension.h in Headers */,
68FC85EA1CE29C7D00EDD713 /* ASVisibilityProtocols.h in Headers */, 68FC85EA1CE29C7D00EDD713 /* ASVisibilityProtocols.h in Headers */,
69C4CAF61DA3147000B1EC9B /* ASLayoutElementStylePrivate.h in Headers */,
A37320101C571B740011FC94 /* ASTextNode+Beta.h in Headers */, A37320101C571B740011FC94 /* ASTextNode+Beta.h in Headers */,
DBABFAFC1C6A8D2F0039EA4A /* _ASTransitionContext.h in Headers */, DBABFAFC1C6A8D2F0039EA4A /* _ASTransitionContext.h in Headers */,
9C70F2061CDA4F0C007D6C76 /* ASTraitCollection.h in Headers */, 9C70F2061CDA4F0C007D6C76 /* ASTraitCollection.h in Headers */,
@ -1859,7 +1854,6 @@
34EFC76C1B701CED00AD841F /* ASOverlayLayoutSpec.h in Headers */, 34EFC76C1B701CED00AD841F /* ASOverlayLayoutSpec.h in Headers */,
B35062261B010EFD0018CF92 /* ASRangeController.h in Headers */, B35062261B010EFD0018CF92 /* ASRangeController.h in Headers */,
34EFC76E1B701CF400AD841F /* ASRatioLayoutSpec.h in Headers */, 34EFC76E1B701CF400AD841F /* ASRatioLayoutSpec.h in Headers */,
34EFC7651B701CCC00AD841F /* ASRelativeSize.h in Headers */,
254C6B741BF94DF4003EC431 /* ASTextNodeWordKerner.h in Headers */, 254C6B741BF94DF4003EC431 /* ASTextNodeWordKerner.h in Headers */,
DB55C2671C641AE4004EDCF5 /* ASContextTransitioning.h in Headers */, DB55C2671C641AE4004EDCF5 /* ASContextTransitioning.h in Headers */,
68B0277B1C1A79D60041016B /* ASDisplayNode+Beta.h in Headers */, 68B0277B1C1A79D60041016B /* ASDisplayNode+Beta.h in Headers */,
@ -2202,7 +2196,6 @@
044285091BAA63FE00D16268 /* ASBatchFetching.m in Sources */, 044285091BAA63FE00D16268 /* ASBatchFetching.m in Sources */,
257754AE1BEE44CD00737CA5 /* ASTextKitRenderer+Positioning.mm in Sources */, 257754AE1BEE44CD00737CA5 /* ASTextKitRenderer+Positioning.mm in Sources */,
ACF6ED2E1B17843500DA7C62 /* ASRatioLayoutSpec.mm in Sources */, ACF6ED2E1B17843500DA7C62 /* ASRatioLayoutSpec.mm in Sources */,
AC47D9461B3BB41900AAEE9D /* ASRelativeSize.mm in Sources */,
CC4C2A781D88E3BF0039ACAB /* ASTraceEvent.m in Sources */, CC4C2A781D88E3BF0039ACAB /* ASTraceEvent.m in Sources */,
205F0E121B371BD7007741D0 /* ASScrollDirection.m in Sources */, 205F0E121B371BD7007741D0 /* ASScrollDirection.m in Sources */,
9C8898BB1C738B9800D6B02E /* ASTextKitFontSizeAdjuster.mm in Sources */, 9C8898BB1C738B9800D6B02E /* ASTextKitFontSizeAdjuster.mm in Sources */,
@ -2390,7 +2383,6 @@
CC4C2A791D88E3BF0039ACAB /* ASTraceEvent.m in Sources */, CC4C2A791D88E3BF0039ACAB /* ASTraceEvent.m in Sources */,
34EFC76F1B701CF700AD841F /* ASRatioLayoutSpec.mm in Sources */, 34EFC76F1B701CF700AD841F /* ASRatioLayoutSpec.mm in Sources */,
254C6B8B1BF94F8A003EC431 /* ASTextKitShadower.mm in Sources */, 254C6B8B1BF94F8A003EC431 /* ASTextKitShadower.mm in Sources */,
34EFC7661B701CD200AD841F /* ASRelativeSize.mm in Sources */,
254C6B851BF94F8A003EC431 /* ASTextKitAttributes.mm in Sources */, 254C6B851BF94F8A003EC431 /* ASTextKitAttributes.mm in Sources */,
509E68601B3AED8E009B9150 /* ASScrollDirection.m in Sources */, 509E68601B3AED8E009B9150 /* ASScrollDirection.m in Sources */,
B35062091B010EFD0018CF92 /* ASScrollNode.m in Sources */, B35062091B010EFD0018CF92 /* ASScrollNode.m in Sources */,

View File

@ -27,6 +27,7 @@
#import "ASRunLoopQueue.h" #import "ASRunLoopQueue.h"
#import "ASEnvironmentInternal.h" #import "ASEnvironmentInternal.h"
#import "ASDimension.h" #import "ASDimension.h"
#import "ASLayoutElementStylePrivate.h"
#import "ASInternalHelpers.h" #import "ASInternalHelpers.h"
#import "ASLayout.h" #import "ASLayout.h"
@ -3478,8 +3479,7 @@ ASEnvironmentLayoutExtensibilityForwarding
ASDN::MutexLocker l(__instanceLock__); ASDN::MutexLocker l(__instanceLock__);
// Deprecated preferredFrameSize just calls through to set width and height // Deprecated preferredFrameSize just calls through to set width and height
_style.width = ASDimensionMake(preferredFrameSize.width); _style.preferredSize = preferredFrameSize;
_style.height = ASDimensionMake(preferredFrameSize.height);
[self invalidateCalculatedLayout]; [self invalidateCalculatedLayout];
} }

View File

@ -250,8 +250,7 @@ static NSString * const kRate = @"rate";
} }
if (_playerNode) { if (_playerNode) {
_playerNode.style.width = ASDimensionMake(calculatedSize.width); _playerNode.style.preferredSize = calculatedSize;
_playerNode.style.height = ASDimensionMake(calculatedSize.height);
[_playerNode layoutThatFits:ASSizeRangeMake(CGSizeZero, calculatedSize)]; [_playerNode layoutThatFits:ASSizeRangeMake(CGSizeZero, calculatedSize)];
} }

View File

@ -324,8 +324,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
{ {
if (_playbackButtonNode == nil) { if (_playbackButtonNode == nil) {
_playbackButtonNode = [[ASDefaultPlaybackButton alloc] init]; _playbackButtonNode = [[ASDefaultPlaybackButton alloc] init];
_playbackButtonNode.style.width = ASDimensionMakeWithPoints(16.0); _playbackButtonNode.style.preferredSize = CGSizeMake(16.0, 22.0);
_playbackButtonNode.style.height = ASDimensionMakeWithPoints(22.0);
if (_delegateFlags.delegatePlaybackButtonTint) { if (_delegateFlags.delegatePlaybackButtonTint) {
_playbackButtonNode.tintColor = [_delegate videoPlayerNodePlaybackButtonTint:self]; _playbackButtonNode.tintColor = [_delegate videoPlayerNodePlaybackButtonTint:self];
@ -601,8 +600,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
return spinnnerView; return spinnnerView;
}]; }];
_spinnerNode.style.width = ASDimensionMakeWithPoints(44.0); _spinnerNode.style.preferredSize = CGSizeMake(44.0, 44.0);
_spinnerNode.style.height = ASDimensionMakeWithPoints(44.0);
[self addSubnode:_spinnerNode]; [self addSubnode:_spinnerNode];
[self setNeedsLayout]; [self setNeedsLayout];
@ -706,7 +704,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
maxSize = CGSizeZero; maxSize = CGSizeZero;
} }
[_videoNode.style setSizeWithCGSize:maxSize]; _videoNode.style.preferredSize = maxSize;
ASLayoutSpec *layoutSpec; ASLayoutSpec *layoutSpec;
if (_delegateFlags.delegateLayoutSpecForControls) { if (_delegateFlags.delegateLayoutSpecForControls) {
@ -719,12 +717,12 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
if (_spinnerNode) { if (_spinnerNode) {
ASCenterLayoutSpec *centerLayoutSpec = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionDefault child:_spinnerNode]; ASCenterLayoutSpec *centerLayoutSpec = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionDefault child:_spinnerNode];
[centerLayoutSpec.style setSizeWithCGSize:maxSize]; centerLayoutSpec.style.preferredSize = maxSize;
[children addObject:centerLayoutSpec]; [children addObject:centerLayoutSpec];
} }
ASOverlayLayoutSpec *overlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_videoNode overlay:layoutSpec]; ASOverlayLayoutSpec *overlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_videoNode overlay:layoutSpec];
[overlaySpec.style setSizeWithCGSize:maxSize]; overlaySpec.style.preferredSize = maxSize;
[children addObject:overlaySpec]; [children addObject:overlaySpec];
return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:children]; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:children];
@ -732,8 +730,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
- (ASLayoutSpec *)defaultLayoutSpecThatFits:(CGSize)maxSize - (ASLayoutSpec *)defaultLayoutSpecThatFits:(CGSize)maxSize
{ {
_scrubberNode.style.width = ASDimensionMakeWithPoints(maxSize.width); _scrubberNode.style.preferredSize = CGSizeMake(maxSize.width, 44.0);
_scrubberNode.style.height = ASDimensionMakeWithPoints(44.0);
ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init];
spacer.style.flexGrow = 1; spacer.style.flexGrow = 1;

View File

@ -12,6 +12,7 @@
#import "ASLayoutSpecUtilities.h" #import "ASLayoutSpecUtilities.h"
#import "ASLayout.h" #import "ASLayout.h"
#import "ASLayoutElementStylePrivate.h"
@implementation ASAbsoluteLayoutSpec @implementation ASAbsoluteLayoutSpec

View File

@ -172,6 +172,32 @@ ASDISPLAYNODE_INLINE CGFloat ASDimensionResolve(ASDimension dimension, CGFloat p
@end @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 #pragma mark - ASSizeRange
/** /**
@ -217,7 +243,7 @@ ASDISPLAYNODE_INLINE CGSize ASSizeRangeClamp(ASSizeRange sizeRange, CGSize size)
extern ASSizeRange ASSizeRangeIntersect(ASSizeRange sizeRange, ASSizeRange otherSizeRange); 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) ASDISPLAYNODE_INLINE BOOL ASSizeRangeEqualToSizeRange(ASSizeRange lhs, ASSizeRange rhs)
{ {

View File

@ -79,22 +79,6 @@ NSString *NSStringFromASDimension(ASDimension dimension)
#pragma mark - ASRelativeSize #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. */ // ** Resolve this relative size relative to a parent size. */
ASDISPLAYNODE_INLINE CGSize ASRelativeSizeResolveSize(ASRelativeSize relativeSize, CGSize parentSize, CGSize autoSize) ASDISPLAYNODE_INLINE CGSize ASRelativeSizeResolveSize(ASRelativeSize relativeSize, CGSize parentSize, CGSize autoSize)
{ {

View File

@ -68,6 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@property (nonatomic, assign, readonly) ASLayoutElementStyle *style; @property (nonatomic, assign, readonly) ASLayoutElementStyle *style;
#pragma mark - Calculate layout #pragma mark - Calculate layout
/** /**
@ -188,12 +189,8 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
*/ */
@property (nullable, nonatomic, weak, readonly) id<ASLayoutElementStyleDelegate> delegate; @property (nullable, nonatomic, weak, readonly) id<ASLayoutElementStyleDelegate> delegate;
#pragma mark - Sizing
/** #pragma mark - Sizing
* @abstract A size constraint that should apply to this ASLayoutElement.
*/
@property (nonatomic, assign, readwrite) ASLayoutElementSize size;
/** /**
* @abstract The width property specifies the height of the content area of an ASLayoutElement. * @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; @property (nonatomic, assign, readwrite) ASDimension maxWidth;
/**
* @abstract Set max and width properties from given size #pragma mark - ASLayoutElementStyleSizeHelpers
*/
- (void)setSizeWithCGSize:(CGSize)size;
/** /**
* @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 elements size will default to its 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 elements minimum size is smaller than its childs minimum size, the childs
* minimum size will be enforced and its size will extend out of the layout specs.
*
* @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 elements maximum size is smaller than its parent, the childs maximum size will
* be enforced and its size will extend out of the layout specs.
*
* @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 parents 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 elements 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 elements minimum relative size is smaller than its childs minimum
* relative size, the childs minimum relative size will be enforced and its size will extend out of the layout specs.
*/
@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 elements maximum relative size is smaller than its childs maximum
* relative size, the childs maximum relative size will be enforced and its size will extend out of the layout specs.
*/
@property (nonatomic, assign, readwrite) ASRelativeSize maxRelativeSize;
#pragma mark - ASStackLayoutElement #pragma mark - ASStackLayoutElement
@ -303,6 +353,7 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
*/ */
@property (nonatomic, assign) CGFloat descender; @property (nonatomic, assign) CGFloat descender;
#pragma mark - ASAbsoluteLayoutElement #pragma mark - ASAbsoluteLayoutElement
/** /**

View File

@ -10,10 +10,7 @@
// of patent rights can be found in the PATENTS file in the same directory. // of patent rights can be found in the PATENTS file in the same directory.
// //
#import "ASLayoutElementPrivate.h"
#import "ASEnvironmentInternal.h"
#import "ASDisplayNodeInternal.h" #import "ASDisplayNodeInternal.h"
#import "ASThread.h"
#import <map> #import <map>
@ -110,16 +107,13 @@ do {\
[_delegate style:self propertyDidChange:propertyName];\ [_delegate style:self propertyDidChange:propertyName];\
} while(0) } while(0)
@interface ASLayoutElementStyle ()
@property (nullable, nonatomic, weak) id<ASLayoutElementStyleDelegate> delegate;
@end
@implementation ASLayoutElementStyle { @implementation ASLayoutElementStyle {
ASDN::RecursiveMutex __instanceLock__; ASDN::RecursiveMutex __instanceLock__;
ASLayoutElementSize _size; ASLayoutElementSize _size;
} }
@dynamic width, height, minWidth, maxWidth, minHeight, maxHeight; @dynamic width, height, minWidth, maxWidth, minHeight, maxHeight;
@dynamic preferredSize, minSize, maxSize, preferredRelativeSize, minRelativeSize, maxRelativeSize;
#pragma mark - Lifecycle #pragma mark - Lifecycle
@ -141,7 +135,21 @@ do {\
return self; 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 - (ASDimension)width
{ {
@ -221,20 +229,64 @@ do {\
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty); ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
} }
- (void)setSizeWithCGSize:(CGSize)size
#pragma mark - ASLayoutElementStyleSizeHelpers
- (void)setPreferredSize:(CGSize)preferredSize
{ {
self.width = ASDimensionMakeWithPoints(size.width); self.width = ASDimensionMakeWithPoints(preferredSize.width);
self.height = ASDimensionMakeWithPoints(size.height); self.height = ASDimensionMakeWithPoints(preferredSize.height);
} }
- (void)setExactSizeWithCGSize:(CGSize)size - (void)setMinSize:(CGSize)minSize
{ {
self.minWidth = ASDimensionMakeWithPoints(size.width); self.minWidth = ASDimensionMakeWithPoints(minSize.width);
self.minHeight = ASDimensionMakeWithPoints(size.height); self.minHeight = ASDimensionMakeWithPoints(minSize.height);
self.maxWidth = ASDimensionMakeWithPoints(size.width);
self.maxHeight = ASDimensionMakeWithPoints(size.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 #pragma mark - ASStackLayoutElement
- (void)setSpacingBefore:(CGFloat)spacingBefore - (void)setSpacingBefore:(CGFloat)spacingBefore

View File

@ -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<ASLayoutElementStyleDelegate> delegate;
/**
* @abstract A size constraint that should apply to this ASLayoutElement.
*/
@property (nonatomic, assign, readonly) ASLayoutElementSize size;
@end

View File

@ -12,6 +12,8 @@
#import "ASLayoutSpecPrivate.h" #import "ASLayoutSpecPrivate.h"
#import "ASLayoutSpec+Subclasses.h" #import "ASLayoutSpec+Subclasses.h"
#import "ASLayoutElementStylePrivate.h"
@implementation ASLayoutSpec @implementation ASLayoutSpec
// Dynamic properties for ASLayoutElements // Dynamic properties for ASLayoutElements

View File

@ -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

View File

@ -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

View File

@ -14,6 +14,7 @@
#import <numeric> #import <numeric>
#import "ASLayoutSpecUtilities.h" #import "ASLayoutSpecUtilities.h"
#import "ASLayoutElementStylePrivate.h"
static CGFloat resolveCrossDimensionMaxForStretchChild(const ASStackLayoutSpecStyle &style, static CGFloat resolveCrossDimensionMaxForStretchChild(const ASStackLayoutSpecStyle &style,
const id<ASLayoutElement>child, const id<ASLayoutElement>child,

View File

@ -80,7 +80,8 @@
CGSize nodeSize = CGSizeMake(100, 100); CGSize nodeSize = CGSizeMake(100, 100);
ASDisplayNode *displayNode = [ASDisplayNode new]; ASDisplayNode *displayNode = [ASDisplayNode new];
[displayNode.style setSizeWithCGSize:nodeSize]; displayNode.style.width = ASDimensionMake(nodeSize.width);
displayNode.style.height = ASDimensionMake(nodeSize.height);
ASButtonNode *buttonNode = [ASButtonNode new]; ASButtonNode *buttonNode = [ASButtonNode new];
[displayNode addSubnode:buttonNode]; [displayNode addSubnode:buttonNode];

View File

@ -44,11 +44,13 @@
imageNode.image = [self testImage]; imageNode.image = [self testImage];
// Snapshot testing requires that node is formally laid out. // 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)]; [imageNode layoutThatFits:ASSizeRangeMake(CGSizeZero, forcedImageSize)];
ASSnapshotVerifyNode(imageNode, @"first"); 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))]; [imageNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(200, 200))];
ASSnapshotVerifyNode(imageNode, @"second"); ASSnapshotVerifyNode(imageNode, @"second");

View File

@ -34,34 +34,68 @@
@implementation ASLayoutElementStyleTests @implementation ASLayoutElementStyleTests
- (void)testSettingSizeProperties - (void)testSettingSize
{ {
ASLayoutElementStyle *style = [ASLayoutElementStyle new]; ASLayoutElementStyle *style = [ASLayoutElementStyle new];
style.width = ASDimensionMake(100); style.width = ASDimensionMake(100);
style.height = 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.width, ASDimensionMake(100)));
XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(100))); XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(100)));
} }
- (void)testSettingSizeViaHelper - (void)testSettingSizeViaCGSize
{ {
ASLayoutElementStyle *style = [ASLayoutElementStyle new]; ASLayoutElementStyle *style = [ASLayoutElementStyle new];
[style setSizeWithCGSize:CGSizeMake(100, 100)];
XCTAssertTrue(ASDimensionEqualToDimension(style.width, ASDimensionMake(100))); CGSize size = CGSizeMake(100, 100);
XCTAssertTrue(ASDimensionEqualToDimension(style.height, ASDimensionMake(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]; ASLayoutElementStyle *style = [ASLayoutElementStyle new];
[style setExactSizeWithCGSize:CGSizeMake(100, 100)];
XCTAssertTrue(ASDimensionEqualToDimension(style.minWidth, ASDimensionMake(100))); ASRelativeSize relativeSize = ASRelativeSizeMake(ASDimensionMake(100), ASDimensionMake(100));
XCTAssertTrue(ASDimensionEqualToDimension(style.minHeight, ASDimensionMake(100)));
XCTAssertTrue(ASDimensionEqualToDimension(style.maxWidth, ASDimensionMake(100))); style.preferredRelativeSize = relativeSize;
XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, ASDimensionMake(100))); 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 - (void)testSettingPropertiesWillCallDelegate

View File

@ -799,7 +799,8 @@ static void setCGSizeToNode(CGSize size, ASDisplayNode *node)
ASStackLayoutSpec *stackLayoutSpec = [[ASStackLayoutSpec alloc] init]; // Default direction is horizontal ASStackLayoutSpec *stackLayoutSpec = [[ASStackLayoutSpec alloc] init]; // Default direction is horizontal
stackLayoutSpec.direction = ASStackLayoutDirectionHorizontal; stackLayoutSpec.direction = ASStackLayoutDirectionHorizontal;
stackLayoutSpec.alignItems = ASStackLayoutAlignItemsStretch; 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}); ASDisplayNode *child = ASDisplayNodeWithBackgroundColor([UIColor redColor], {50, 50});
stackLayoutSpec.children = @[child]; stackLayoutSpec.children = @[child];

View File

@ -127,8 +127,7 @@
// header stack // header stack
// constrain avatar image frame size // constrain avatar image frame size
_userAvatarImageView.style.width = ASDimensionMakeWithPoints(USER_IMAGE_HEIGHT); _userAvatarImageView.style.preferredSize = CGSizeMake(USER_IMAGE_HEIGHT, USER_IMAGE_HEIGHT);
_userAvatarImageView.style.height = ASDimensionMakeWithPoints(USER_IMAGE_HEIGHT);
_photoTimeIntervalSincePostLabel.style.spacingBefore = HORIZONTAL_BUFFER; // to remove double spaces around spacer _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? ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; // FIXME: long locations overflow post time - set max size?
@ -159,8 +158,7 @@
CGFloat cellWidth = constrainedSize.max.width; CGFloat cellWidth = constrainedSize.max.width;
// constrain photo frame size // constrain photo frame size
_photoImageView.style.width = ASDimensionMakeWithPoints(cellWidth); _photoImageView.style.preferredSize = CGSizeMake(cellWidth, cellWidth);
_photoImageView.style.height = ASDimensionMakeWithPoints(cellWidth);
ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec]; ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec];
verticalStack.alignItems = ASStackLayoutAlignItemsStretch; // stretch headerStack to fill horizontal space verticalStack.alignItems = ASStackLayoutAlignItemsStretch; // stretch headerStack to fill horizontal space

View File

@ -117,14 +117,14 @@
#define HEIGHT 30 #define HEIGHT 30
CGSize nodeSize = CGSizeMake(constrainedSize.max.width * 0.3, HEIGHT); CGSize nodeSize = CGSizeMake(constrainedSize.max.width * 0.3, HEIGHT);
[_latEditableNode.style setSizeWithCGSize:nodeSize]; _latEditableNode.style.preferredSize = nodeSize;
[_lonEditableNode.style setSizeWithCGSize:nodeSize]; _lonEditableNode.style.preferredSize = nodeSize;
[_deltaLatEditableNode.style setSizeWithCGSize:nodeSize]; _deltaLatEditableNode.style.preferredSize = nodeSize;
[_deltaLonEditableNode.style setSizeWithCGSize:nodeSize]; _deltaLonEditableNode.style.preferredSize = nodeSize;
[_updateRegionButton.style setSizeWithCGSize:nodeSize]; _updateRegionButton.style.preferredSize = nodeSize;
[_liveMapToggleButton.style setSizeWithCGSize:nodeSize]; _liveMapToggleButton.style.preferredSize = nodeSize;
_latEditableNode.style.flexGrow = _lonEditableNode.style.flexGrow = YES; _latEditableNode.style.flexGrow = _lonEditableNode.style.flexGrow = YES;
_deltaLatEditableNode.style.flexGrow = _deltaLonEditableNode.style.flexGrow = YES; _deltaLatEditableNode.style.flexGrow = _deltaLonEditableNode.style.flexGrow = YES;

View File

@ -39,7 +39,7 @@
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{ {
self.imageNode.position = CGPointZero; self.imageNode.position = CGPointZero;
[self.imageNode.style setSizeWithCGSize:constrainedSize.max]; self.imageNode.style.preferredSize = constrainedSize.max;
return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.imageNode]]; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.imageNode]];
} }

View File

@ -63,7 +63,7 @@ static const NSInteger kImageHeight = 200;
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{ {
self.collectionNode.position = CGPointZero; self.collectionNode.position = CGPointZero;
[self.collectionNode.style setSizeWithCGSize:constrainedSize.max]; self.collectionNode.style.preferredSize = constrainedSize.max;
return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.collectionNode]]; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[self.collectionNode]];
} }

View File

@ -208,7 +208,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
CGSize imageNetworkImageNodeSize = (CGSize){imageNode.image.size.width / 7, imageNode.image.size.height / 7}; 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 = [self centeringParentNodeWithChild:imageNode];
parentNode.entryTitle = @"ASImageNode"; parentNode.entryTitle = @"ASImageNode";
@ -218,7 +218,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASNetworkImageNode #pragma mark ASNetworkImageNode
ASNetworkImageNode *networkImageNode = [ASNetworkImageNode new]; ASNetworkImageNode *networkImageNode = [ASNetworkImageNode new];
networkImageNode.URL = [NSURL URLWithString:@"http://i.imgur.com/FjOR9kX.jpg"]; networkImageNode.URL = [NSURL URLWithString:@"http://i.imgur.com/FjOR9kX.jpg"];
[networkImageNode.style setSizeWithCGSize:imageNetworkImageNodeSize]; networkImageNode.style.preferredSize = imageNetworkImageNodeSize;
parentNode = [self centeringParentNodeWithChild:networkImageNode]; parentNode = [self centeringParentNodeWithChild:networkImageNode];
parentNode.entryTitle = @"ASNetworkImageNode"; parentNode.entryTitle = @"ASNetworkImageNode";
@ -227,7 +227,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASMapNode #pragma mark ASMapNode
ASMapNode *mapNode = [ASMapNode new]; ASMapNode *mapNode = [ASMapNode new];
[mapNode.style setSizeWithCGSize:CGSizeMake(300.0, 300.0)]; mapNode.style.preferredSize = CGSizeMake(300.0, 300.0);
// San Francisco // San Francisco
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194); CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194);
@ -240,7 +240,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark ASVideoNode #pragma mark ASVideoNode
ASVideoNode *videoNode = [ASVideoNode new]; 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"]]; AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:@"http://www.w3schools.com/html/mov_bbb.mp4"]];
videoNode.asset = asset; videoNode.asset = asset;
@ -254,7 +254,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
UIImage *scrollNodeImage = [UIImage imageNamed:@"image"]; UIImage *scrollNodeImage = [UIImage imageNamed:@"image"];
ASScrollNode *scrollNode = [ASScrollNode new]; ASScrollNode *scrollNode = [ASScrollNode new];
[scrollNode.style setSizeWithCGSize:CGSizeMake(300.0, 400.0)]; scrollNode.style.preferredSize = CGSizeMake(300.0, 400.0);
UIScrollView *scrollNodeView = scrollNode.view; UIScrollView *scrollNodeView = scrollNode.view;
[scrollNodeView addSubview:[[UIImageView alloc] initWithImage:scrollNodeImage]]; [scrollNodeView addSubview:[[UIImageView alloc] initWithImage:scrollNodeImage]];
@ -406,17 +406,17 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
#pragma mark Horizontal ASStackLayoutSpec #pragma mark Horizontal ASStackLayoutSpec
childNode1 = [ASDisplayNode new]; childNode1 = [ASDisplayNode new];
[childNode1.style setSizeWithCGSize:CGSizeMake(10.0, 20.0)]; childNode1.style.preferredSize = CGSizeMake(10.0, 20.0);
childNode1.style.flexGrow = YES; childNode1.style.flexGrow = YES;
childNode1.backgroundColor = [UIColor greenColor]; childNode1.backgroundColor = [UIColor greenColor];
childNode2 = [ASDisplayNode new]; childNode2 = [ASDisplayNode new];
[childNode2.style setSizeWithCGSize:CGSizeMake(10.0, 20.0)]; childNode2.style.preferredSize = CGSizeMake(10.0, 20.0);
childNode2.style.alignSelf = ASStackLayoutAlignSelfStretch; childNode2.style.alignSelf = ASStackLayoutAlignSelfStretch;
childNode2.backgroundColor = [UIColor blueColor]; childNode2.backgroundColor = [UIColor blueColor];
childNode3 = [ASDisplayNode new]; childNode3 = [ASDisplayNode new];
[childNode3.style setSizeWithCGSize:CGSizeMake(10.0, 20.0)]; childNode3.style.preferredSize = CGSizeMake(10.0, 20.0);
childNode3.backgroundColor = [UIColor yellowColor]; childNode3.backgroundColor = [UIColor yellowColor];
parentNode = [self parentNodeWithChild:childNode]; parentNode = [self parentNodeWithChild:childNode];
@ -467,7 +467,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
- (OverviewDisplayNodeWithSizeBlock *)parentNodeWithChild:(ASDisplayNode *)child - (OverviewDisplayNodeWithSizeBlock *)parentNodeWithChild:(ASDisplayNode *)child
{ {
OverviewDisplayNodeWithSizeBlock *parentNode = [OverviewDisplayNodeWithSizeBlock new]; OverviewDisplayNodeWithSizeBlock *parentNode = [OverviewDisplayNodeWithSizeBlock new];
[parentNode.style setSizeWithCGSize:CGSizeMake(100, 100)]; parentNode.style.preferredSize = CGSizeMake(100, 100);
parentNode.backgroundColor = [UIColor redColor]; parentNode.backgroundColor = [UIColor redColor];
return parentNode; return parentNode;
} }
@ -491,7 +491,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
- (ASDisplayNode *)childNode - (ASDisplayNode *)childNode
{ {
ASDisplayNode *childNode = [ASDisplayNode new]; ASDisplayNode *childNode = [ASDisplayNode new];
[childNode.style setSizeWithCGSize:CGSizeMake(50, 50)]; childNode.style.preferredSize = CGSizeMake(50, 50);
childNode.backgroundColor = [UIColor blueColor]; childNode.backgroundColor = [UIColor blueColor];
return childNode; return childNode;
} }

View File

@ -53,7 +53,7 @@ static CGFloat kFixedHeight = 200.0f;
[spinner startAnimating]; [spinner startAnimating];
return spinner; return spinner;
}]; }];
[_loadingSpinner.style setSizeWithCGSize:CGSizeMake(50, 50)]; _loadingSpinner.style.preferredSize = CGSizeMake(50, 50);
// add it as a subnode, and we're done // add it as a subnode, and we're done
[self addSubnode:_loadingSpinner]; [self addSubnode:_loadingSpinner];

View File

@ -79,7 +79,7 @@ static const CGFloat kInnerPadding = 10.0f;
CGSize elementSize = _elementSize; CGSize elementSize = _elementSize;
return ^{ return ^{
RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init]; RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init];
[elementNode.style setSizeWithCGSize:elementSize]; elementNode.style.preferredSize = elementSize;
return elementNode; return elementNode;
}; };
} }
@ -87,7 +87,7 @@ static const CGFloat kInnerPadding = 10.0f;
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{ {
CGSize collectionNodeSize = CGSizeMake(constrainedSize.max.width, _elementSize.height); CGSize collectionNodeSize = CGSizeMake(constrainedSize.max.width, _elementSize.height);
[_collectionNode.style setSizeWithCGSize:collectionNodeSize]; _collectionNode.style.preferredSize = collectionNodeSize;
ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init]; ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init];
insetSpec.insets = UIEdgeInsetsMake(kOuterPadding, 0.0, kOuterPadding, 0.0); insetSpec.insets = UIEdgeInsetsMake(kOuterPadding, 0.0, kOuterPadding, 0.0);

View File

@ -145,7 +145,7 @@ static const CGFloat kInnerPadding = 10.0f;
{ {
// Set an intrinsic size for the image node // Set an intrinsic size for the image node
CGSize imageSize = _isImageEnlarged ? CGSizeMake(2.0 * kImageSize, 2.0 * kImageSize) : CGSizeMake(kImageSize, kImageSize); 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 // Shrink the text node in case the image + text gonna be too wide
_textNode.style.flexShrink = YES; _textNode.style.flexShrink = YES;

View File

@ -20,7 +20,6 @@
#import "TextStyles.h" #import "TextStyles.h"
#import "LikesNode.h" #import "LikesNode.h"
#import "CommentsNode.h" #import "CommentsNode.h"
#import "ASRelativeSize.h"
#define PostNodeDividerColor [UIColor lightGrayColor] #define PostNodeDividerColor [UIColor lightGrayColor]

View File

@ -68,7 +68,7 @@
- (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath - (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init]; RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init];
[elementNode.style setSizeWithCGSize:_elementSize]; elementNode.style.preferredSize = _elementSize;
elementNode.indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:_pageNumber]; elementNode.indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:_pageNumber];
return elementNode; return elementNode;
} }

View File

@ -77,7 +77,7 @@
CGSize boundsSize = pagerNode.bounds.size; CGSize boundsSize = pagerNode.bounds.size;
CGSize gradientRowSize = CGSizeMake(boundsSize.width, 100); CGSize gradientRowSize = CGSizeMake(boundsSize.width, 100);
GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize]; GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize];
[node.style setSizeWithCGSize:boundsSize]; node.style.preferredSize = boundsSize;
node.pageNumber = index; node.pageNumber = index;
return node; return node;
} }

View File

@ -54,16 +54,16 @@
_rootNode.layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) { _rootNode.layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
// Layout all nodes absolute in a static layout spec // 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); 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); 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)); 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); hlsVideoNode.style.layoutPosition = CGPointMake(0.0, mainScreenBoundsSize.height / 3.0);
return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[guitarVideoNode, nicCageVideoNode, simonVideoNode, hlsVideoNode]]; return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[guitarVideoNode, nicCageVideoNode, simonVideoNode, hlsVideoNode]];