Permalink
Browse files

fixed crash when setting custom shadow props to null

Reviewed By: emilsjolander

Differential Revision: D3923634

fbshipit-source-id: 005e316e70fa280960c796375b2e94f9967a089d
  • Loading branch information...
1 parent 0a0dd30 commit cfae3e376d96653e5ad48e0d0398674a954d3637 @majak majak committed with Facebook Github Bot 8 Sep 27, 2016
Showing with 22 additions and 10 deletions.
  1. +20 −8 React/Views/RCTComponentData.m
  2. +2 −2 React/Views/RCTViewManager.h
@@ -145,22 +145,34 @@ - (RCTPropBlock)propBlockForKey:(NSString *)name
// Check for custom setter
if ([keyPath isEqualToString:@"__custom__"]) {
- // Get custom setter
- SEL customSetter = NSSelectorFromString([NSString stringWithFormat:@"set_%@:for%@View:withDefaultView:", name, shadowView ? @"Shadow" : @""]);
+ // Get custom setter. There is no default view in the shadow case, so the selector is different.
+ NSString *selectorString;
+ if (!shadowView) {
+ selectorString = [NSString stringWithFormat:@"set_%@:for%@View:withDefaultView:", name, shadowView ? @"Shadow" : @""];
+ } else {
+ selectorString = [NSString stringWithFormat:@"set_%@:forShadowView:", name];
+ }
+ SEL customSetter = NSSelectorFromString(selectorString);
propBlock = ^(id<RCTComponent> view, id json) {
RCTComponentData *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
json = RCTNilIfNull(json);
- if (!json && !strongSelf->_defaultView) {
- // Only create default view if json is null
- strongSelf->_defaultView = [strongSelf createViewWithTag:nil];
+ if (!shadowView) {
+ if (!json && !strongSelf->_defaultView) {
+ // Only create default view if json is null
+ strongSelf->_defaultView = [strongSelf createViewWithTag:nil];
+ }
+ ((void (*)(id, SEL, id, id, id))objc_msgSend)(
+ strongSelf.manager, customSetter, json, view, strongSelf->_defaultView
+ );
+ } else {
+ ((void (*)(id, SEL, id, id))objc_msgSend)(
+ strongSelf.manager, customSetter, json, view
+ );
}
- ((void (*)(id, SEL, id, id, id))objc_msgSend)(
- strongSelf.manager, customSetter, json, view, strongSelf->_defaultView
- );
};
} else {
@@ -126,10 +126,10 @@ RCT_REMAP_VIEW_PROPERTY(name, __custom__, type) \
/**
* This macro can be used when you need to provide custom logic for setting
* shadow view properties. The macro should be followed by a method body, which can
- * refer to "json", "view" and "defaultView" to implement the required logic.
+ * refer to "json" and "view".
*/
#define RCT_CUSTOM_SHADOW_PROPERTY(name, type, viewClass) \
RCT_REMAP_SHADOW_PROPERTY(name, __custom__, type) \
-- (void)set_##name:(id)json forShadowView:(viewClass *)view withDefaultView:(viewClass *)defaultView
+- (void)set_##name:(id)json forShadowView:(viewClass *)view
@end

0 comments on commit cfae3e3

Please sign in to comment.