diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 7308440b1..9af3a6ceb 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -758,7 +758,7 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag UIColor *backgroundColor = shadowView.backgroundColor; [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ - id view = [componentData createViewWithTag:reactTag]; + id view = [componentData createViewWithTag:reactTag props:props]; if ([view respondsToSelector:@selector(setBackgroundColor:)]) { ((UIView *)view).backgroundColor = backgroundColor; } diff --git a/React/Views/RCTComponentData.h b/React/Views/RCTComponentData.h index 20a54ad7b..d510956cd 100644 --- a/React/Views/RCTComponentData.h +++ b/React/Views/RCTComponentData.h @@ -22,7 +22,7 @@ - (instancetype)initWithManager:(RCTViewManager *)manager NS_DESIGNATED_INITIALIZER; -- (id)createViewWithTag:(NSNumber *)tag; +- (id)createViewWithTag:(NSNumber *)tag props:(NSDictionary *)props; - (RCTShadowView *)createShadowViewWithTag:(NSNumber *)tag; - (void)setProps:(NSDictionary *)props forView:(id)view; - (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView; diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index 8daff2a3d..b01b0268e 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -62,11 +62,11 @@ typedef void (^RCTPropBlock)(id view, id json); RCT_NOT_IMPLEMENTED(- (instancetype)init) -- (id)createViewWithTag:(NSNumber *)tag +- (id)createViewWithTag:(NSNumber *)tag props:(NSDictionary *)props { RCTAssertMainThread(); - id view = (id)[_manager view]; + id view = (id)(props ? [_manager viewWithProps:props] : [_manager view]); view.reactTag = tag; if ([view isKindOfClass:[UIView class]]) { ((UIView *)view).multipleTouchEnabled = YES; @@ -264,7 +264,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) } if (!_defaultView) { - _defaultView = [self createViewWithTag:nil]; + _defaultView = [self createViewWithTag:nil props:nil]; } [props enumerateKeysAndObjectsUsingBlock:^(NSString *key, id json, __unused BOOL *stop) { diff --git a/React/Views/RCTViewManager.h b/React/Views/RCTViewManager.h index 9e3316415..f3c370b94 100644 --- a/React/Views/RCTViewManager.h +++ b/React/Views/RCTViewManager.h @@ -39,6 +39,15 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *v */ - (UIView *)view; +/** + * This method instantiates a native view using the props passed into the component. + * This method should be used when you need to know about specific props in order to + * initialize a view. By default, this just calls the -view method. Each prop will + * still be set individually, after the view is created. Like the -view method, + * -viewWithProps: should return a fresh instance each time it is called. + */ +- (UIView *)viewWithProps:(NSDictionary *)props; + /** * This method instantiates a shadow view to be managed by the module. If omitted, * an ordinary RCTShadowView instance will be created, which is typically fine for diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index f6282b00b..b4562f689 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -54,6 +54,11 @@ RCT_EXPORT_MODULE() return _bridge.uiManager.methodQueue; } +- (UIView *)viewWithProps:(NSDictionary *)props +{ + return [self view]; +} + - (UIView *)view { return [RCTView new];