Skip to content

Commit

Permalink
T183626616 - [KP][WP iOS v] App crashes after rotation in landscape v…
Browse files Browse the repository at this point in the history
…iew during playing a video. (#45846)

Summary:
Pull Request resolved: #45846

In general this diff fixes all crashes related to RTCImageUtills happened because of uncovered cases in switch.

In this current bug the problem was in this part of code
RCTTargetSize(imageSize, imageScale, frame.size, RCTScreenScale(), (RCTResizeMode)self.contentMode, YES);

when we cast UIViewContentMode to RCTResizeMode. RCTResizeMode doesnt cover all of UIViewContentMode values.

So just added default cases to swithces in places where it was lost.

Changelog:
[iOS][Fixed] - fixed crash in RCTImageUtils

Reviewed By: philIip

Differential Revision: D60523540

fbshipit-source-id: b8027537c600a7ca226e62238d16a6b05301d4de
  • Loading branch information
pavelgurkovskiy authored and facebook-github-bot committed Aug 6, 2024
1 parent 67367a0 commit 3572ef3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ - (void)reactSetFrame:(CGRect)frame
} else if ([self shouldReloadImageSourceAfterResize]) {
CGSize imageSize = self.image.size;
CGFloat imageScale = self.image.scale;
CGSize idealSize =
RCTTargetSize(imageSize, imageScale, frame.size, RCTScreenScale(), (RCTResizeMode)self.contentMode, YES);
CGSize idealSize = RCTTargetSize(
imageSize, imageScale, frame.size, RCTScreenScale(), RCTResizeModeFromUIViewContentMode(self.contentMode), YES);

// Don't reload if the current image or target image size is close enough
if (!RCTShouldReloadImageForSizeChange(imageSize, idealSize) ||
Expand Down
28 changes: 28 additions & 0 deletions packages/react-native/Libraries/Image/RCTResizeMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ typedef NS_ENUM(NSInteger, RCTResizeMode) {
RCTResizeModeRepeat = -1, // Use negative values to avoid conflicts with iOS enum values.
};

static inline RCTResizeMode RCTResizeModeFromUIViewContentMode(UIViewContentMode mode)
{
switch (mode) {
case UIViewContentModeScaleToFill:
return RCTResizeModeStretch;
break;
case UIViewContentModeScaleAspectFit:
return RCTResizeModeContain;
break;
case UIViewContentModeScaleAspectFill:
return RCTResizeModeCover;
break;
case UIViewContentModeCenter:
return RCTResizeModeCenter;
break;
case UIViewContentModeRedraw:
case UIViewContentModeTop:
case UIViewContentModeBottom:
case UIViewContentModeLeft:
case UIViewContentModeRight:
case UIViewContentModeTopLeft:
case UIViewContentModeTopRight:
case UIViewContentModeBottomLeft:
case UIViewContentModeBottomRight:
return RCTResizeModeRepeat;
}
};

@interface RCTConvert (RCTResizeMode)

+ (RCTResizeMode)RCTResizeMode:(id)json;
Expand Down

0 comments on commit 3572ef3

Please sign in to comment.