fix(ios): add protection when setting unsupported prop for component (#4237)

This commit is contained in:
wwwcg
2025-03-24 21:36:10 +08:00
committed by GitHub
parent c9927d4119
commit b4158769cd
2 changed files with 16 additions and 3 deletions
+13 -3
View File
@@ -548,7 +548,12 @@ NSString *const HippyFontChangeTriggerNotification = @"HippyFontChangeTriggerNot
view.rootTag = rootTag;
view.hippyShadowView = shadowView;
view.uiManager = self;
[componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default
@try {
[componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default
} @catch (NSException *exception) {
HippyLogError(@"Exception while setting props for view (%@ of %@), %@", view.class, view.hippyTag, props);
}
}
}
return view;
@@ -574,7 +579,11 @@ NSString *const HippyFontChangeTriggerNotification = @"HippyFontChangeTriggerNot
// Note: viewRegistry may be modified in the block, and it may be stored internally as NSMapTable
// so to ensure that it is up-to-date, it can only be retrieved each time.
NSDictionary<NSNumber *, UIView *> *viewRegistry = [self.viewRegistry componentsForRootTag:shadowView.rootTag];
block(viewRegistry, nil);
@try {
block(viewRegistry, nil);
} @catch (NSException *exception) {
HippyLogError(@"Exception while executing blocks when create list! %@", shadowView);
}
}
}
[self.viewRegistry clearTempCacheAfterAcquireAllStoredWeakComponentsForRootTag:shadowView.rootTag];
@@ -744,6 +753,7 @@ NSString *const HippyFontChangeTriggerNotification = @"HippyFontChangeTriggerNot
#pragma mark Schedule Block
- (void)addUIBlock:(HippyViewManagerUIBlock)block {
HippyAssertNotMainQueue();
if (!block || !_viewRegistry) {
return;
}
@@ -778,7 +788,7 @@ NSString *const HippyFontChangeTriggerNotification = @"HippyFontChangeTriggerNot
// Note: viewRegistry may be modified in the block, and it may be stored internally as NSMapTable
// so to ensure that it is up-to-date, it can only be retrieved each time.
NSDictionary* viewReg = [strongSelf.viewRegistry componentsForRootTag:@(rootTag)];
block(strongSelf, viewReg);
if (block) block(strongSelf, viewReg);
} @catch (NSException *exception) {
HippyLogError(@"Exception thrown while executing UI block: %@", exception);
}
@@ -287,6 +287,9 @@ HIPPY_CUSTOM_VIEW_PROPERTY(visibility, NSString, HippyView) {
}
HIPPY_CUSTOM_VIEW_PROPERTY(backgroundImage, NSString, HippyView) {
if (![view isKindOfClass:HippyView.class]) {
return;
}
if (json) {
NSString *imagePath = [HippyConvert NSString:json];
// Old background image need to be cleaned up in time due to view's reuse