Skip to content

Commit e472ab4

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)