iOS:fix NSNull Crash

This commit is contained in:
pengfei.zhou 2020-03-20 15:27:31 +08:00 committed by osborn
parent 3eda0358d1
commit 4d6884098c

View File

@ -138,6 +138,9 @@ - (void)blend:(NSDictionary *)props {
self.view.layoutConfig = self.layoutConfig; self.view.layoutConfig = self.layoutConfig;
for (NSString *key in props) { for (NSString *key in props) {
id value = props[key]; id value = props[key];
if (!value || [value isKindOfClass:[NSNull class]]) {
continue;
}
[self blendView:self.view forPropName:key propValue:value]; [self blendView:self.view forPropName:key propValue:value];
} }
[self transformProperties]; [self transformProperties];
@ -190,12 +193,12 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
_gradientLayer = [[CAGradientLayer alloc] init]; _gradientLayer = [[CAGradientLayer alloc] init];
[view.layer addSublayer:self.gradientLayer]; [view.layer addSublayer:self.gradientLayer];
} }
NSDictionary *dict = prop; NSDictionary *dict = prop;
UIColor *start = DoricColor(dict[@"start"]); UIColor *start = DoricColor(dict[@"start"]);
UIColor *end = DoricColor(dict[@"end"]); UIColor *end = DoricColor(dict[@"end"]);
int orientation = [dict[@"orientation"] intValue]; int orientation = [dict[@"orientation"] intValue];
if (orientation == 0) { if (orientation == 0) {
self.gradientLayer.startPoint = CGPointMake(0, 0); self.gradientLayer.startPoint = CGPointMake(0, 0);
self.gradientLayer.endPoint = CGPointMake(0, 1); self.gradientLayer.endPoint = CGPointMake(0, 1);
@ -221,7 +224,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
self.gradientLayer.startPoint = CGPointMake(0, 0); self.gradientLayer.startPoint = CGPointMake(0, 0);
self.gradientLayer.endPoint = CGPointMake(1, 1); self.gradientLayer.endPoint = CGPointMake(1, 1);
} }
self.gradientLayer.colors = @[(__bridge id)start.CGColor, (__bridge id)end.CGColor]; self.gradientLayer.colors = @[(__bridge id) start.CGColor, (__bridge id) end.CGColor];
} }
} else if ([name isEqualToString:@"alpha"]) { } else if ([name isEqualToString:@"alpha"]) {
view.alpha = [prop floatValue]; view.alpha = [prop floatValue];