Skip to content

Commit

Permalink
fix(ios): avoid zero size crash when using UIGraphics api in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed May 10, 2024
1 parent 0aa7901 commit 48573ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ios/sdk/component/view/HippyView.m
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ - (BOOL)getLayerContentForColor:(UIColor *)color completionBlock:(void (^)(UIIma
return YES;
}
else if (self.backgroundImageUrl) {
CGSize size = theFrame.size;
if (0 >= size.width || 0 >= size.height) {
contentBlock(nil);
return YES;
}
CGFloat backgroundPositionX = self.backgroundPositionX;
CGFloat backgroundPositionY = self.backgroundPositionY;
HippyBackgroundImageCacheManager *weakBackgroundCacheManager = [self backgroundCachemanager];
Expand Down
8 changes: 6 additions & 2 deletions ios/sdk/debug/devtools/inspector/model/HippyPageModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ - (BOOL)screencastJSONWithManager:(HippyUIManager *)manager
if (!rootView) {
HippyLogWarn(@"PageModel, screen cast, root view is nil");
completion(@{});
return;
}
CGFloat viewWidth = rootView.frame.size.width;
CGFloat viewHeight = rootView.frame.size.height;
Expand All @@ -118,6 +119,10 @@ - (BOOL)screencastJSONWithManager:(HippyUIManager *)manager
CGFloat scaleX = self.maxSize.width / viewWidth;
CGFloat scaleY = self.maxSize.height / viewHeight;
scale = MIN(scaleX, scaleY);
} else {
HippyLogWarn(@"PageModel, screen cast, root view size is 0");
completion(@{});
return;
}
// root view snapshot
UIGraphicsBeginImageContextWithOptions(rootView.frame.size, NO, scale);
Expand All @@ -141,8 +146,7 @@ - (BOOL)screencastJSONWithManager:(HippyUIManager *)manager
resultJSON[HippyPageKeySessionId] = @(timestamp);
self.lastTimestamp = timestamp;
completion(resultJSON);
}
else {
} else {
completion(@{});
}
});
Expand Down

0 comments on commit 48573ef

Please sign in to comment.