From f86691a44914ce35fd328e278a960ce284a80da1 Mon Sep 17 00:00:00 2001 From: Martin Kralik Date: Fri, 27 Nov 2015 02:51:58 -0800 Subject: [PATCH] added `didSetProps` for views and shadow views Summary: Views and shadow views might want to configure themself once all of their props were set. So far there was no way to do it without writing some synchronization code. This diff adds a `didSetProps` call on both uiviews and shadow views, passing names of all props that were set for convenience. public Reviewed By: nicklockwood Differential Revision: D2699512 fb-gh-sync-id: 65f76e7bcbf5751d5b550261a953c463ed2f4e8a --- React/Views/RCTComponent.h | 7 +++++++ React/Views/RCTComponentData.m | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/React/Views/RCTComponent.h b/React/Views/RCTComponent.h index 2940b4311..5236f850b 100644 --- a/React/Views/RCTComponent.h +++ b/React/Views/RCTComponent.h @@ -36,6 +36,13 @@ typedef void (^RCTBubblingEventBlock)(NSDictionary *body); @optional +/** + * Called each time props have been set. + * Not all props have to be set - React can set only changed ones. + * @param changedProps String names of all set props. + */ +- (void)didSetProps:(NSArray *)changedProps; + // TODO: Deprecate this // This method is called after layout has been performed for all views known // to the RCTViewManager. It is only called on UIViews, not shadow views. diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index dbcbc10c9..8aa82bf28 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -302,6 +302,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [props enumerateKeysAndObjectsUsingBlock:^(NSString *key, id json, __unused BOOL *stop) { [self propBlockForKey:key defaultView:_defaultView](view, json); }]; + + if ([view respondsToSelector:@selector(didSetProps:)]) { + [view didSetProps:[props allKeys]]; + } } - (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView @@ -318,6 +322,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [self propBlockForKey:key defaultView:_defaultShadowView](shadowView, json); }]; + if ([shadowView respondsToSelector:@selector(didSetProps:)]) { + [shadowView didSetProps:[props allKeys]]; + } [shadowView updateLayout]; }