Skip to content

Commit f86691a

Browse files
majakfacebook-github-bot-0
authored andcommitted
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
1 parent 2c0679b commit f86691a

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

React/Views/RCTComponent.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ typedef void (^RCTBubblingEventBlock)(NSDictionary *body);
3636

3737
@optional
3838

39+
/**
40+
* Called each time props have been set.
41+
* Not all props have to be set - React can set only changed ones.
42+
* @param changedProps String names of all set props.
43+
*/
44+
- (void)didSetProps:(NSArray<NSString *> *)changedProps;
45+
3946
// TODO: Deprecate this
4047
// This method is called after layout has been performed for all views known
4148
// to the RCTViewManager. It is only called on UIViews, not shadow views.

React/Views/RCTComponentData.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>
302302
[props enumerateKeysAndObjectsUsingBlock:^(NSString *key, id json, __unused BOOL *stop) {
303303
[self propBlockForKey:key defaultView:_defaultView](view, json);
304304
}];
305+
306+
if ([view respondsToSelector:@selector(didSetProps:)]) {
307+
[view didSetProps:[props allKeys]];
308+
}
305309
}
306310

307311
- (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowView *)shadowView
@@ -318,6 +322,9 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
318322
[self propBlockForKey:key defaultView:_defaultShadowView](shadowView, json);
319323
}];
320324

325+
if ([shadowView respondsToSelector:@selector(didSetProps:)]) {
326+
[shadowView didSetProps:[props allKeys]];
327+
}
321328
[shadowView updateLayout];
322329
}
323330

0 commit comments

Comments
 (0)