|
10 | 10 | #import <react/renderer/components/scrollview/ScrollViewProps.h> |
11 | 11 | #import <react/renderer/components/scrollview/ScrollViewShadowNode.h> |
12 | 12 | #import <react/renderer/core/LayoutMetrics.h> |
| 13 | +#import <react/renderer/core/PropsParserContext.h> |
| 14 | +#import <react/renderer/core/RawProps.h> |
| 15 | +#import <react/renderer/core/RawPropsParser.h> |
| 16 | +#import <react/utils/ContextContainer.h> |
13 | 17 |
|
| 18 | +using facebook::react::ContextContainer; |
14 | 19 | using facebook::react::EmptyLayoutMetrics; |
15 | 20 | using facebook::react::LayoutMetrics; |
16 | 21 | using facebook::react::Props; |
| 22 | +using facebook::react::PropsParserContext; |
| 23 | +using facebook::react::RawProps; |
| 24 | +using facebook::react::RawPropsParser; |
17 | 25 | using facebook::react::ScrollViewProps; |
18 | 26 | using facebook::react::ScrollViewShadowNode; |
19 | 27 |
|
|
34 | 42 | return props; |
35 | 43 | } |
36 | 44 |
|
| 45 | +static Props::Shared parseScrollViewProps(const folly::dynamic &rawValue, const ScrollViewProps &sourceProps) |
| 46 | +{ |
| 47 | + ContextContainer contextContainer{}; |
| 48 | + PropsParserContext parserContext{-1, contextContainer}; |
| 49 | + auto rawProps = RawProps(rawValue); |
| 50 | + auto parser = RawPropsParser(); |
| 51 | + parser.prepare<ScrollViewProps>(); |
| 52 | + rawProps.parse(parser); |
| 53 | + return std::make_shared<const ScrollViewProps>(parserContext, sourceProps, rawProps); |
| 54 | +} |
| 55 | + |
37 | 56 | @interface RCTScrollViewComponentView (Tests) |
38 | 57 | - (void)_keyboardWillChangeFrame:(NSNotification *)notification; |
39 | 58 | @end |
@@ -120,6 +139,24 @@ - (void)testHorizontalFadingEdgeLengthFadesAlongTheWidth |
120 | 139 | [self assertLocations:mask.locations equal:@[ @0, @0.2, @1, @1 ]]; |
121 | 140 | } |
122 | 141 |
|
| 142 | +- (void)testParsedFadingEdgeFollowsTheAxisWhenHorizontalIsRemoved |
| 143 | +{ |
| 144 | + RCTScrollViewComponentView *view = [[RCTScrollViewComponentView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)]; |
| 145 | + auto horizontalProps = |
| 146 | + parseScrollViewProps(folly::dynamic::object("fadingEdgeLength", 20)("horizontal", true), ScrollViewProps{}); |
| 147 | + [view updateProps:horizontalProps oldProps:ScrollViewShadowNode::defaultSharedProps()]; |
| 148 | + XCTAssertTrue(CGPointEqualToPoint([self fadingEdgeMaskOf:view].startPoint, CGPointMake(0, 0.5))); |
| 149 | + |
| 150 | + auto verticalProps = parseScrollViewProps( |
| 151 | + folly::dynamic::object("horizontal", nullptr), static_cast<const ScrollViewProps &>(*horizontalProps)); |
| 152 | + [view updateProps:verticalProps oldProps:horizontalProps]; |
| 153 | + |
| 154 | + CAGradientLayer *mask = [self fadingEdgeMaskOf:view]; |
| 155 | + XCTAssertTrue(CGPointEqualToPoint(mask.startPoint, CGPointMake(0.5, 0))); |
| 156 | + XCTAssertTrue(CGPointEqualToPoint(mask.endPoint, CGPointMake(0.5, 1))); |
| 157 | + [self assertLocations:mask.locations equal:@[ @0, @0.1, @0.9, @1 ]]; |
| 158 | +} |
| 159 | + |
123 | 160 | - (void)testFadingEdgesNeverOverlap |
124 | 161 | { |
125 | 162 | RCTScrollViewComponentView *view = [[RCTScrollViewComponentView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)]; |
|
0 commit comments