Skip to content

Commit f9a0287

Browse files
authored
fix: providing unsupported value to hoverStyle crashed the app (#88)
1 parent 56de923 commit f9a0287

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

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

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)