Skip to content

Commit cfae3e3

Browse files
majakFacebook Github Bot 8
authored andcommitted
fixed crash when setting custom shadow props to null
Reviewed By: emilsjolander Differential Revision: D3923634 fbshipit-source-id: 005e316e70fa280960c796375b2e94f9967a089d
1 parent 0a0dd30 commit cfae3e3

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

React/Views/RCTComponentData.m

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,34 @@ - (RCTPropBlock)propBlockForKey:(NSString *)name
145145
// Check for custom setter
146146
if ([keyPath isEqualToString:@"__custom__"]) {
147147

148-
// Get custom setter
149-
SEL customSetter = NSSelectorFromString([NSString stringWithFormat:@"set_%@:for%@View:withDefaultView:", name, shadowView ? @"Shadow" : @""]);
148+
// Get custom setter. There is no default view in the shadow case, so the selector is different.
149+
NSString *selectorString;
150+
if (!shadowView) {
151+
selectorString = [NSString stringWithFormat:@"set_%@:for%@View:withDefaultView:", name, shadowView ? @"Shadow" : @""];
152+
} else {
153+
selectorString = [NSString stringWithFormat:@"set_%@:forShadowView:", name];
154+
}
155+
SEL customSetter = NSSelectorFromString(selectorString);
150156

151157
propBlock = ^(id<RCTComponent> view, id json) {
152158
RCTComponentData *strongSelf = weakSelf;
153159
if (!strongSelf) {
154160
return;
155161
}
156162
json = RCTNilIfNull(json);
157-
if (!json && !strongSelf->_defaultView) {
158-
// Only create default view if json is null
159-
strongSelf->_defaultView = [strongSelf createViewWithTag:nil];
163+
if (!shadowView) {
164+
if (!json && !strongSelf->_defaultView) {
165+
// Only create default view if json is null
166+
strongSelf->_defaultView = [strongSelf createViewWithTag:nil];
167+
}
168+
((void (*)(id, SEL, id, id, id))objc_msgSend)(
169+
strongSelf.manager, customSetter, json, view, strongSelf->_defaultView
170+
);
171+
} else {
172+
((void (*)(id, SEL, id, id))objc_msgSend)(
173+
strongSelf.manager, customSetter, json, view
174+
);
160175
}
161-
((void (*)(id, SEL, id, id, id))objc_msgSend)(
162-
strongSelf.manager, customSetter, json, view, strongSelf->_defaultView
163-
);
164176
};
165177

166178
} else {

React/Views/RCTViewManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ RCT_REMAP_VIEW_PROPERTY(name, __custom__, type) \
126126
/**
127127
* This macro can be used when you need to provide custom logic for setting
128128
* shadow view properties. The macro should be followed by a method body, which can
129-
* refer to "json", "view" and "defaultView" to implement the required logic.
129+
* refer to "json" and "view".
130130
*/
131131
#define RCT_CUSTOM_SHADOW_PROPERTY(name, type, viewClass) \
132132
RCT_REMAP_SHADOW_PROPERTY(name, __custom__, type) \
133-
- (void)set_##name:(id)json forShadowView:(viewClass *)view withDefaultView:(viewClass *)defaultView
133+
- (void)set_##name:(id)json forShadowView:(viewClass *)view
134134

135135
@end

0 commit comments

Comments
 (0)