Skip to content

Commit 36cae7e

Browse files
committed
fix: providing unsupported value to hoverStyle crashed the app (#88)
1 parent 7f27967 commit 36cae7e

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
@@ -530,23 +530,26 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
530530

531531
#if TARGET_OS_VISION
532532
- (void) updateHoverEffect:(NSString*)hoverEffect withCornerRadius:(CGFloat)cornerRadius {
533-
if (hoverEffect == nil || [hoverEffect isEqualToString:@""]) {
534-
self.hoverStyle = nil;
535-
return;
536-
}
537-
538-
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
539-
id<UIHoverEffect> effect;
540-
541-
if ([hoverEffect isEqualToString:@"lift"]) {
542-
effect = [UIHoverLiftEffect effect];
543-
} else if ([hoverEffect isEqualToString:@"highlight"]) {
544-
effect = [UIHoverHighlightEffect effect];
545-
}
546-
547-
if (hoverEffect != nil) {
548-
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
549-
}
533+
if (hoverEffect == nil) {
534+
self.hoverStyle = nil;
535+
return;
536+
}
537+
538+
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
539+
id<UIHoverEffect> effect;
540+
541+
if ([hoverEffect isEqualToString:@"lift"]) {
542+
effect = [UIHoverLiftEffect effect];
543+
} else if ([hoverEffect isEqualToString:@"highlight"]) {
544+
effect = [UIHoverHighlightEffect effect];
545+
}
546+
547+
if (effect == nil) {
548+
self.hoverStyle = nil;
549+
return;
550+
}
551+
552+
self.hoverStyle = [UIHoverStyle styleWithEffect:effect shape:shape];
550553
}
551554
#endif
552555

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)