Skip to content

Commit

Permalink
[CK] Add async render mode to CKTextComponent
Browse files Browse the repository at this point in the history
This should be exposed imo
  • Loading branch information
Msegan committed May 27, 2016
1 parent b7a0c5e commit ec4c9e2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ComponentKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
D0B47D6E1CBD948E00BB33CE /* CKTextKitShadower.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C5C1CBD92C200BB33CE /* CKTextKitShadower.h */; };
D0B47D6F1CBD948E00BB33CE /* CKTextKitTailTruncater.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C5E1CBD92C200BB33CE /* CKTextKitTailTruncater.h */; settings = {ATTRIBUTES = (Private, ); }; };
D0B47D701CBD948E00BB33CE /* CKTextKitTruncating.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C601CBD92C200BB33CE /* CKTextKitTruncating.h */; settings = {ATTRIBUTES = (Private, ); }; };
D0B47D711CBD948E00BB33CE /* CKAsyncLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C621CBD92C200BB33CE /* CKAsyncLayer.h */; };
D0B47D711CBD948E00BB33CE /* CKAsyncLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C621CBD92C200BB33CE /* CKAsyncLayer.h */; settings = {ATTRIBUTES = (Private, ); }; };
D0B47D721CBD948E00BB33CE /* CKAsyncLayerInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C641CBD92C200BB33CE /* CKAsyncLayerInternal.h */; };
D0B47D731CBD948E00BB33CE /* CKAsyncLayerSubclass.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C651CBD92C200BB33CE /* CKAsyncLayerSubclass.h */; };
D0B47D741CBD948E00BB33CE /* CKAsyncTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B47C661CBD92C200BB33CE /* CKAsyncTransaction.h */; };
Expand Down
2 changes: 1 addition & 1 deletion ComponentTextKit/CKLabelComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ + (instancetype)newWithLabelAttributes:(const CKLabelAttributes &)attributes
[CKTextComponent
newWithTextAttributes:textKitAttributes(attributes)
viewAttributes:std::move(copiedMap)
accessibilityContext:{.isAccessibilityElement = @(YES)}
options:{.accessibilityContext = {.isAccessibilityElement = @(YES)}}
size:size]];
}

Expand Down
9 changes: 8 additions & 1 deletion ComponentTextKit/CKTextComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import <ComponentKit/CKComponent.h>

#import <ComponentKit/CKAsyncLayer.h>
#import <ComponentKit/CKTextKitAttributes.h>

struct CKTextComponentAccessibilityContext
Expand All @@ -23,11 +24,17 @@ struct CKTextComponentAccessibilityContext
CKComponentAccessibilityTextAttribute accessibilityLabel;
};

struct CKTextComponentOptions
{
CKAsyncLayerDisplayMode displayMode;
CKTextComponentAccessibilityContext accessibilityContext;
};

@interface CKTextComponent : CKComponent

+ (instancetype)newWithTextAttributes:(const CKTextKitAttributes &)attributes
viewAttributes:(const CKViewComponentAttributeValueMap &)viewAttributes
accessibilityContext:(const CKTextComponentAccessibilityContext &)accessibilityContext
options:(const CKTextComponentOptions &)options
size:(const CKComponentSize &)size;

@end
13 changes: 7 additions & 6 deletions ComponentTextKit/CKTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@ @implementation CKTextComponent

+ (instancetype)newWithTextAttributes:(const CKTextKitAttributes &)attributes
viewAttributes:(const CKViewComponentAttributeValueMap &)viewAttributes
accessibilityContext:(const CKTextComponentAccessibilityContext &)accessibilityContext
options:(const CKTextComponentOptions &)options
size:(const CKComponentSize &)size
{
CKTextKitAttributes copyAttributes = attributes.copy();
CKViewComponentAttributeValueMap copiedMap = viewAttributes;
copiedMap.insert({CKComponentViewAttribute::LayerAttribute(@selector(setDisplayMode:)), @(options.displayMode)});
CKTextComponent *c = [super newWithView:{
[CKTextComponentView class],
std::move(copiedMap),
{
.isAccessibilityElement = accessibilityContext.isAccessibilityElement,
.accessibilityIdentifier = accessibilityContext.accessibilityIdentifier,
.accessibilityLabel = accessibilityContext.accessibilityLabel.hasText()
? accessibilityContext.accessibilityLabel : ^{ return copyAttributes.attributedString.string; }
.isAccessibilityElement = options.accessibilityContext.isAccessibilityElement,
.accessibilityIdentifier = options.accessibilityContext.accessibilityIdentifier,
.accessibilityLabel = options.accessibilityContext.accessibilityLabel.hasText()
? options.accessibilityContext.accessibilityLabel : ^{ return copyAttributes.attributedString.string; }
}
} size:size];
if (c) {
c->_attributes = copyAttributes;
c->_accessibilityContext = accessibilityContext;
c->_accessibilityContext = options.accessibilityContext;
}
return c;
}
Expand Down
38 changes: 19 additions & 19 deletions ComponentTextKitApplicationTests/CKTextComponentTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (void)testSimpleString
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -90,7 +90,7 @@ - (void)testSimpleRTLString
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -112,7 +112,7 @@ - (void)testSimpleShadowedString
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -129,7 +129,7 @@ - (void)testMultilineString
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -147,7 +147,7 @@ - (void)testMultilineRTLString
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -166,7 +166,7 @@ - (void)testMaximumNumberOfLines
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -189,7 +189,7 @@ - (void)testMaximumNumberOfLinesWithTruncationString
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -213,7 +213,7 @@ - (void)testMaximumNumberOfLinesWithTruncationStringRTL
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -237,7 +237,7 @@ - (void)testNaturalTruncation
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand Down Expand Up @@ -266,7 +266,7 @@ - (void)testEmptyTruncationCharacterSet
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -287,7 +287,7 @@ - (void)testDoesNotClipDescenders
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -306,7 +306,7 @@ - (void)testDoesNotCrashWithArabicUnicodeSequenceThatUsedToCrashCoreText
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -327,7 +327,7 @@ - (void)testCenterAlignmentFlexibleBounds
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -348,7 +348,7 @@ - (void)testCenterAlignmentStrictBounds
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kStrictSize, @"");
}
Expand All @@ -368,7 +368,7 @@ - (void)testVerticallyLaidOutText
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -394,7 +394,7 @@ - (void)testDrawsUnderlinesAndStrikethroughs
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kFlexibleSize, @"");
}
Expand All @@ -415,7 +415,7 @@ - (void)testComplexLigatures
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kUnrestrictedSize, @"");
}
Expand All @@ -439,7 +439,7 @@ - (void)testTruncationStringLargerThanLastLine
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kUnrestrictedSize, @"");
}
Expand All @@ -466,7 +466,7 @@ - (void)testShouldUseCustomLayoutManagerClass
viewAttributes:{
{{@selector(setBackgroundColor:), [UIColor clearColor]}}
}
accessibilityContext:{ }
options:{ }
size:{ }];
CKSnapshotVerifyComponent(c, kUnrestrictedSize, @"");
}
Expand Down

0 comments on commit ec4c9e2

Please sign in to comment.