From 2cda73a3343baf3ba9d722cd26da465553588b85 Mon Sep 17 00:00:00 2001 From: appleguy Date: Sun, 2 Jul 2017 21:40:51 -0700 Subject: [PATCH] [ASTextNode2] Provide compiler flag to enable ASTextNode2 for all usages. (#410) * [ASTextNode2] Provide compiler flag to enable ASTextNode2 for all usages. The runtime switch is helpful, but is too slow to be shipped in a large production application where startup time is carefully optimized. Although this doesn't pass text-related snapshot tests when enabled, it does allow apps to rely on built-in components like ASButtonNode using the same text stack as when they are manually creating ASTextNode2 instances. A simpler approach would be to use a #define ASTextNode ASTextNode2, but this would create unusual keyword highlighting in code referencing ASTextNode. However, because it would be less invasive and this is not on by default, we could do that instead if preferred. * Update AsyncDisplayKit.h * [ASTextNode2] Improve naming and documentation of ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE * [ASTextNode2] CHANGELOG.md for #410. --- AsyncDisplayKit.xcodeproj/project.pbxproj | 16 ++++++++-------- CHANGELOG.md | 1 + Source/ASTextNode+Beta.h | 2 ++ Source/ASTextNode.h | 19 +++++++++++++++++-- Source/ASTextNode.mm | 9 +++++++++ Source/{Private => }/ASTextNode2.h | 19 +++++++++++++++++++ Source/{Private => }/ASTextNode2.mm | 1 + Source/AsyncDisplayKit.h | 1 + Source/Base/ASAvailability.h | 7 +++++++ 9 files changed, 65 insertions(+), 10 deletions(-) rename Source/{Private => }/ASTextNode2.h (95%) rename Source/{Private => }/ASTextNode2.mm (99%) diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index 4c4cbe3af..aa4b91640 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -184,6 +184,8 @@ 9019FBBE1ED8061D00C45F72 /* ASYogaLayoutSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */; }; 9019FBBF1ED8061D00C45F72 /* ASYogaUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */; }; 9019FBC01ED8061D00C45F72 /* ASYogaUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */; }; + 909C4C751F09C98B00D6B76F /* ASTextNode2.h in Headers */ = {isa = PBXBuildFile; fileRef = 909C4C731F09C98B00D6B76F /* ASTextNode2.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 909C4C761F09C98B00D6B76F /* ASTextNode2.mm in Sources */ = {isa = PBXBuildFile; fileRef = 909C4C741F09C98B00D6B76F /* ASTextNode2.mm */; }; 90FC784F1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm in Sources */ = {isa = PBXBuildFile; fileRef = 90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */; }; 92DD2FE61BF4D05E0074C9DD /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DD2FE51BF4D05E0074C9DD /* MapKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 92DD2FE71BF4D0850074C9DD /* ASMapNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */; }; @@ -394,8 +396,6 @@ CCCCCCE41EC3EF060087FE10 /* NSParagraphStyle+ASText.m in Sources */ = {isa = PBXBuildFile; fileRef = CCCCCCD41EC3EF060087FE10 /* NSParagraphStyle+ASText.m */; }; CCCCCCE71EC3F0FC0087FE10 /* NSAttributedString+ASText.h in Headers */ = {isa = PBXBuildFile; fileRef = CCCCCCE51EC3F0FC0087FE10 /* NSAttributedString+ASText.h */; }; CCCCCCE81EC3F0FC0087FE10 /* NSAttributedString+ASText.m in Sources */ = {isa = PBXBuildFile; fileRef = CCCCCCE61EC3F0FC0087FE10 /* NSAttributedString+ASText.m */; }; - CCD523111EBD658C001F2191 /* ASTextNode2.h in Headers */ = {isa = PBXBuildFile; fileRef = CCD5230F1EBD658C001F2191 /* ASTextNode2.h */; }; - CCD523121EBD658C001F2191 /* ASTextNode2.mm in Sources */ = {isa = PBXBuildFile; fileRef = CCD523101EBD658C001F2191 /* ASTextNode2.mm */; }; CCDD148B1EEDCD9D0020834E /* ASCollectionModernDataSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CCDD148A1EEDCD9D0020834E /* ASCollectionModernDataSourceTests.m */; }; CCF18FF41D2575E300DF5895 /* NSIndexSet+ASHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = CC4981BA1D1C7F65004E13CC /* NSIndexSet+ASHelpers.h */; settings = {ATTRIBUTES = (Private, ); }; }; DB55C2671C641AE4004EDCF5 /* ASContextTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = DB55C2651C641AE4004EDCF5 /* ASContextTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -690,6 +690,8 @@ 9019FBBA1ED8061D00C45F72 /* ASYogaLayoutSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASYogaLayoutSpec.mm; sourceTree = ""; }; 9019FBBB1ED8061D00C45F72 /* ASYogaUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASYogaUtilities.h; sourceTree = ""; }; 9019FBBC1ED8061D00C45F72 /* ASYogaUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASYogaUtilities.mm; sourceTree = ""; }; + 909C4C731F09C98B00D6B76F /* ASTextNode2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTextNode2.h; sourceTree = ""; }; + 909C4C741F09C98B00D6B76F /* ASTextNode2.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASTextNode2.mm; sourceTree = ""; }; 90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "ASDisplayNode+Yoga.mm"; sourceTree = ""; }; 92DD2FE11BF4B97E0074C9DD /* ASMapNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASMapNode.h; sourceTree = ""; }; 92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASMapNode.mm; sourceTree = ""; }; @@ -862,8 +864,6 @@ CCCCCCD41EC3EF060087FE10 /* NSParagraphStyle+ASText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSParagraphStyle+ASText.m"; sourceTree = ""; }; CCCCCCE51EC3F0FC0087FE10 /* NSAttributedString+ASText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAttributedString+ASText.h"; sourceTree = ""; }; CCCCCCE61EC3F0FC0087FE10 /* NSAttributedString+ASText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAttributedString+ASText.m"; sourceTree = ""; }; - CCD5230F1EBD658C001F2191 /* ASTextNode2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTextNode2.h; sourceTree = ""; }; - CCD523101EBD658C001F2191 /* ASTextNode2.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASTextNode2.mm; sourceTree = ""; }; CCDD148A1EEDCD9D0020834E /* ASCollectionModernDataSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCollectionModernDataSourceTests.m; sourceTree = ""; }; CCE04B1E1E313EA7006AEBBB /* ASSectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASSectionController.h; sourceTree = ""; }; CCE04B201E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "IGListAdapter+AsyncDisplayKit.h"; sourceTree = ""; }; @@ -1089,6 +1089,8 @@ 058D09DF195D050800B7D73C /* ASTextNode.h */, A373200E1C571B050011FC94 /* ASTextNode+Beta.h */, 058D09E0195D050800B7D73C /* ASTextNode.mm */, + 909C4C731F09C98B00D6B76F /* ASTextNode2.h */, + 909C4C741F09C98B00D6B76F /* ASTextNode2.mm */, ACC945A81BA9E7A0005E1FB8 /* ASViewController.h */, 9CFFC6BF1CCAC73C006A6476 /* ASViewController.mm */, 6BDC61F51978FEA400E50D21 /* AsyncDisplayKit.h */, @@ -1297,8 +1299,6 @@ 058D0A01195D050800B7D73C /* Private */ = { isa = PBXGroup; children = ( - CCD5230F1EBD658C001F2191 /* ASTextNode2.h */, - CCD523101EBD658C001F2191 /* ASTextNode2.mm */, CCA282CE1E9EBF6C0037E8B7 /* ASTipsWindow.h */, CCA282CF1E9EBF6C0037E8B7 /* ASTipsWindow.m */, CCA282C61E9EB64B0037E8B7 /* ASDisplayNodeTipState.h */, @@ -1680,7 +1680,6 @@ B13CA1011C52004900E031AB /* ASCollectionNode+Beta.h in Headers */, 68C215581DE10D330019C4BC /* ASCollectionViewLayoutInspector.h in Headers */, B35062411B010EFD0018CF92 /* _ASAsyncTransactionGroup.h in Headers */, - CCD523111EBD658C001F2191 /* ASTextNode2.h in Headers */, B350620F1B010EFD0018CF92 /* _ASDisplayLayer.h in Headers */, CCCCCCD71EC3EF060087FE10 /* ASTextInput.h in Headers */, B35062111B010EFD0018CF92 /* _ASDisplayView.h in Headers */, @@ -1818,6 +1817,7 @@ DECBD6E81BE56E1900CF4905 /* ASButtonNode.h in Headers */, B35062241B010EFD0018CF92 /* ASMutableAttributedStringBuilder.h in Headers */, B13CA0F81C519EBA00E031AB /* ASCollectionViewLayoutFacilitatorProtocol.h in Headers */, + 909C4C751F09C98B00D6B76F /* ASTextNode2.h in Headers */, B35062061B010EFD0018CF92 /* ASNetworkImageNode.h in Headers */, CCA282C81E9EB64B0037E8B7 /* ASDisplayNodeTipState.h in Headers */, 34EFC76C1B701CED00AD841F /* ASOverlayLayoutSpec.h in Headers */, @@ -2186,7 +2186,6 @@ B350624E1B010EFD0018CF92 /* ASDisplayNode+AsyncDisplay.mm in Sources */, 25E327591C16819500A2170C /* ASPagerNode.m in Sources */, 636EA1A41C7FF4EC00EE152F /* NSArray+Diffing.m in Sources */, - CCD523121EBD658C001F2191 /* ASTextNode2.mm in Sources */, B35062501B010EFD0018CF92 /* ASDisplayNode+DebugTiming.mm in Sources */, DEC146B91C37A16A004A0EE7 /* ASCollectionInternal.m in Sources */, 254C6B891BF94F8A003EC431 /* ASTextKitRenderer+Positioning.mm in Sources */, @@ -2258,6 +2257,7 @@ 34EFC7741B701D0A00AD841F /* ASAbsoluteLayoutSpec.mm in Sources */, CCCCCCE81EC3F0FC0087FE10 /* NSAttributedString+ASText.m in Sources */, 690C35621E055C5D00069B91 /* ASDimensionInternal.mm in Sources */, + 909C4C761F09C98B00D6B76F /* ASTextNode2.mm in Sources */, 68C2155A1DE10D330019C4BC /* ASCollectionViewLayoutInspector.m in Sources */, DB78412E1C6BCE1600A9E2B4 /* _ASTransitionContext.m in Sources */, B350620B1B010EFD0018CF92 /* ASTableView.mm in Sources */, diff --git a/CHANGELOG.md b/CHANGELOG.md index 86b62868f..da89e40e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Add your own contributions to the next release on the line below this with your name. - [ASTextNode2] Add initial implementation for link handling. [Scott Goodson](https://github.com/appleguy) [#396](https://github.com/TextureGroup/Texture/pull/396) +- [ASTextNode2] Provide compile flag to globally enable new implementation of ASTextNode: ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE. [Scott Goodson](https://github.com/appleguy) [#396](https://github.com/TextureGroup/Texture/pull/410) ##2.3.4 - [Yoga] Rewrite YOGA_TREE_CONTIGUOUS mode with improved behavior and cleaner integration [Scott Goodson](https://github.com/appleguy) diff --git a/Source/ASTextNode+Beta.h b/Source/ASTextNode+Beta.h index c296af0cb..8c7556811 100644 --- a/Source/ASTextNode+Beta.h +++ b/Source/ASTextNode+Beta.h @@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN +// When enabled, use ASTextNode2 for subclasses, random instances, or all instances of ASTextNode. +// See ASAvailability.h declaration of ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE for a compile-time option. typedef NS_OPTIONS(NSUInteger, ASTextNodeExperimentOptions) { // All subclass instances use the experimental implementation. ASTextNodeExperimentSubclasses = 1 << 0, diff --git a/Source/ASTextNode.h b/Source/ASTextNode.h index 2f0985834..f3670bb0f 100644 --- a/Source/ASTextNode.h +++ b/Source/ASTextNode.h @@ -15,12 +15,18 @@ // http://www.apache.org/licenses/LICENSE-2.0 // +#import #import +#if ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE + #import +#endif NS_ASSUME_NONNULL_BEGIN @protocol ASTextNodeDelegate; +#if !ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE + /** * Highlight styles. */ @@ -232,6 +238,13 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { @end +#else + +@interface ASTextNode : ASTextNode2 +@end + +#endif + /** * @abstract Text node delegate. */ @@ -287,6 +300,8 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { @end +#if !ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE + @interface ASTextNode (Unavailable) - (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable; @@ -319,6 +334,6 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { @end -NS_ASSUME_NONNULL_END - +#endif +NS_ASSUME_NONNULL_END diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index 5102ad6a0..acfe9e6bd 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -17,6 +17,8 @@ #import #import + +#if !ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE #import #include @@ -1471,3 +1473,10 @@ - (NSAttributedString *)truncationAttributedString } @end + +#else + +@implementation ASTextNode +@end + +#endif diff --git a/Source/Private/ASTextNode2.h b/Source/ASTextNode2.h similarity index 95% rename from Source/Private/ASTextNode2.h rename to Source/ASTextNode2.h index 81cb0837a..aef3ac468 100644 --- a/Source/Private/ASTextNode2.h +++ b/Source/ASTextNode2.h @@ -12,8 +12,27 @@ #import +#if !ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE // Import this to get ASTextNodeHighlightStyle #import +#else +@protocol ASTextNodeDelegate; + +/** + * Highlight styles. + */ +typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { + /** + * Highlight style for text on a light background. + */ + ASTextNodeHighlightStyleLight, + + /** + * Highlight style for text on a dark background. + */ + ASTextNodeHighlightStyleDark +}; +#endif NS_ASSUME_NONNULL_BEGIN diff --git a/Source/Private/ASTextNode2.mm b/Source/ASTextNode2.mm similarity index 99% rename from Source/Private/ASTextNode2.mm rename to Source/ASTextNode2.mm index d266d6cca..48ff3c4bb 100644 --- a/Source/Private/ASTextNode2.mm +++ b/Source/ASTextNode2.mm @@ -11,6 +11,7 @@ // #import +#import // Definition of ASTextNodeDelegate #import #import diff --git a/Source/AsyncDisplayKit.h b/Source/AsyncDisplayKit.h index 6d949b5a3..2c319b0f2 100644 --- a/Source/AsyncDisplayKit.h +++ b/Source/AsyncDisplayKit.h @@ -24,6 +24,7 @@ #import #import #import +#import #import #import #import diff --git a/Source/Base/ASAvailability.h b/Source/Base/ASAvailability.h index bb2defe24..ff7181602 100644 --- a/Source/Base/ASAvailability.h +++ b/Source/Base/ASAvailability.h @@ -41,6 +41,13 @@ #define YOGA __has_include(YOGA_HEADER_PATH) #endif +// When enabled, use ASTextNode2 for ALL instances of ASTextNode. +// This includes what ASButtonNode uses internally, as well as all app references to ASTextNode. +// See ASTextNode+Beta.h declaration of ASTextNodeExperimentOptions for more details. +#ifndef ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE + #define ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE 0 +#endif + #define AS_PIN_REMOTE_IMAGE __has_include() #define AS_IG_LIST_KIT __has_include()