Skip to content

Commit

Permalink
fix: providing unsupported value to hoverStyle crashed the app (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Apr 5, 2024
1 parent ef21b18 commit 69fdbe3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,23 +523,26 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

#if TARGET_OS_VISION
- (void) updateHoverEffect:(NSString*)hoverEffect withCornerRadius:(CGFloat)cornerRadius {
if (hoverEffect == nil || [hoverEffect isEqualToString:@""]) {
self.hoverStyle = nil;
return;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
id<UIHoverEffect> effect;

if ([hoverEffect isEqualToString:@"lift"]) {
effect = [UIHoverLiftEffect effect];
} else if ([hoverEffect isEqualToString:@"highlight"]) {
effect = [UIHoverHighlightEffect effect];
}

if (hoverEffect != nil) {
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
}
if (hoverEffect == nil) {
self.hoverStyle = nil;
return;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
id<UIHoverEffect> effect;

if ([hoverEffect isEqualToString:@"lift"]) {
effect = [UIHoverLiftEffect effect];
} else if ([hoverEffect isEqualToString:@"highlight"]) {
effect = [UIHoverHighlightEffect effect];
}

if (effect == nil) {
self.hoverStyle = nil;
return;
}

self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
}
#endif

Expand Down
61 changes: 32 additions & 29 deletions packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -669,36 +669,39 @@ - (UIEdgeInsets)bordersAsInsets

#if TARGET_OS_VISION
- (void)setHoverEffect:(NSString *)hoverEffect {
_hoverEffect = hoverEffect;

if (hoverEffect == nil) {
self.hoverStyle = nil;
return;
}

CGFloat cornerRadius = 0.0;
RCTCornerRadii cornerRadii = [self cornerRadii];

if (RCTCornerRadiiAreEqual(cornerRadii)) {
cornerRadius = cornerRadii.topLeft;

} else {
// TODO: Handle a case when corner radius is different for each corner.
cornerRadius = cornerRadii.topLeft;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
id<UIHoverEffect> effect;

if ([hoverEffect isEqualToString:@"lift"]) {
effect = [UIHoverLiftEffect effect];
} else if ([hoverEffect isEqualToString:@"highlight"]) {
effect = [UIHoverHighlightEffect effect];
}
_hoverEffect = hoverEffect;

if (hoverEffect == nil) {
self.hoverStyle = nil;
return;
}

CGFloat cornerRadius = 0.0;
RCTCornerRadii cornerRadii = [self cornerRadii];

if (RCTCornerRadiiAreEqual(cornerRadii)) {
cornerRadius = cornerRadii.topLeft;

if (hoverEffect != nil) {
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
}
} else {
// TODO: Handle a case when corner radius is different for each corner.
cornerRadius = cornerRadii.topLeft;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
id<UIHoverEffect> effect;

if ([hoverEffect isEqualToString:@"lift"]) {
effect = [UIHoverLiftEffect effect];
} else if ([hoverEffect isEqualToString:@"highlight"]) {
effect = [UIHoverHighlightEffect effect];
}

if (effect == nil) {
self.hoverStyle = nil;
return;
}

self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
}
#endif

Expand Down

0 comments on commit 69fdbe3

Please sign in to comment.