Skip to content

Commit 69fdbe3

Browse files
committed
fix: providing unsupported value to hoverStyle crashed the app (#88)
1 parent ef21b18 commit 69fdbe3

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

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

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)