Skip to content

Commit 5946c51

Browse files
committed
fix: providing unsupported value to hoverStyle crashed the app (#88)
1 parent 2dc9fb3 commit 5946c51

File tree

2 files changed

+52
-46
lines changed

2 files changed

+52
-46
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -525,23 +525,26 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
525525

526526
#if TARGET_OS_VISION
527527
- (void) updateHoverEffect:(NSString*)hoverEffect withCornerRadius:(CGFloat)cornerRadius {
528-
if (hoverEffect == nil || [hoverEffect isEqualToString:@""]) {
529-
self.hoverStyle = nil;
530-
return;
531-
}
532-
533-
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
534-
id<UIHoverEffect> effect;
535-
536-
if ([hoverEffect isEqualToString:@"lift"]) {
537-
effect = [UIHoverLiftEffect effect];
538-
} else if ([hoverEffect isEqualToString:@"highlight"]) {
539-
effect = [UIHoverHighlightEffect effect];
540-
}
541-
542-
if (hoverEffect != nil) {
543-
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
544-
}
528+
if (hoverEffect == nil) {
529+
self.hoverStyle = nil;
530+
return;
531+
}
532+
533+
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
534+
id<UIHoverEffect> effect;
535+
536+
if ([hoverEffect isEqualToString:@"lift"]) {
537+
effect = [UIHoverLiftEffect effect];
538+
} else if ([hoverEffect isEqualToString:@"highlight"]) {
539+
effect = [UIHoverHighlightEffect effect];
540+
}
541+
542+
if (effect == nil) {
543+
self.hoverStyle = nil;
544+
return;
545+
}
546+
547+
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
545548
}
546549
#endif
547550

packages/react-native/React/Views/RCTView.m

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -669,36 +669,39 @@ - (UIEdgeInsets)bordersAsInsets
669669

670670
#if TARGET_OS_VISION
671671
- (void)setHoverEffect:(NSString *)hoverEffect {
672-
_hoverEffect = hoverEffect;
673-
674-
if (hoverEffect == nil) {
675-
self.hoverStyle = nil;
676-
return;
677-
}
678-
679-
CGFloat cornerRadius = 0.0;
680-
RCTCornerRadii cornerRadii = [self cornerRadii];
681-
682-
if (RCTCornerRadiiAreEqual(cornerRadii)) {
683-
cornerRadius = cornerRadii.topLeft;
684-
685-
} else {
686-
// TODO: Handle a case when corner radius is different for each corner.
687-
cornerRadius = cornerRadii.topLeft;
688-
}
689-
690-
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
691-
id<UIHoverEffect> effect;
692-
693-
if ([hoverEffect isEqualToString:@"lift"]) {
694-
effect = [UIHoverLiftEffect effect];
695-
} else if ([hoverEffect isEqualToString:@"highlight"]) {
696-
effect = [UIHoverHighlightEffect effect];
697-
}
672+
_hoverEffect = hoverEffect;
673+
674+
if (hoverEffect == nil) {
675+
self.hoverStyle = nil;
676+
return;
677+
}
678+
679+
CGFloat cornerRadius = 0.0;
680+
RCTCornerRadii cornerRadii = [self cornerRadii];
681+
682+
if (RCTCornerRadiiAreEqual(cornerRadii)) {
683+
cornerRadius = cornerRadii.topLeft;
698684

699-
if (hoverEffect != nil) {
700-
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
701-
}
685+
} else {
686+
// TODO: Handle a case when corner radius is different for each corner.
687+
cornerRadius = cornerRadii.topLeft;
688+
}
689+
690+
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
691+
id<UIHoverEffect> effect;
692+
693+
if ([hoverEffect isEqualToString:@"lift"]) {
694+
effect = [UIHoverLiftEffect effect];
695+
} else if ([hoverEffect isEqualToString:@"highlight"]) {
696+
effect = [UIHoverHighlightEffect effect];
697+
}
698+
699+
if (effect == nil) {
700+
self.hoverStyle = nil;
701+
return;
702+
}
703+
704+
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
702705
}
703706
#endif
704707

0 commit comments

Comments
 (0)