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
This commit is contained in:
Martin Kralik 2015-11-27 02:51:58 -08:00 committed by facebook-github-bot-0
parent 2c0679bed1
commit f86691a449
2 changed files with 14 additions and 0 deletions

View File

@ -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<NSString *> *)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.

View File

@ -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<NSString *, id> *)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];
}