Skip to content

Commit d429c92

Browse files
added cornerRadius for hover style (#66)
* added corner radius for hover style * fix: implement proper handling for old arch, reformat code --------- Co-authored-by: Oskar Kwaśniewski <[email protected]>
1 parent 60e72d7 commit d429c92

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,22 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
287287
}
288288

289289
// `border`
290-
if (oldViewProps.borderStyles != newViewProps.borderStyles || oldViewProps.borderRadii != newViewProps.borderRadii ||
290+
if (oldViewProps.borderStyles != newViewProps.borderStyles ||
291291
oldViewProps.borderColors != newViewProps.borderColors) {
292292
needsInvalidateLayer = YES;
293293
}
294-
294+
// 'borderRadii'
295+
if (oldViewProps.borderRadii != newViewProps.borderRadii) {
296+
needsInvalidateLayer = YES;
297+
#if TARGET_OS_VISION
298+
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
299+
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
300+
#endif
301+
}
295302
#if TARGET_OS_VISION
296303
if (oldViewProps.visionos_hoverEffect != newViewProps.visionos_hoverEffect) {
297-
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()]];
304+
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
305+
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
298306
}
299307
#endif
300308

@@ -514,13 +522,13 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
514522
}
515523

516524
#if TARGET_OS_VISION
517-
- (void) updateHoverEffect:(NSString*)hoverEffect {
525+
- (void) updateHoverEffect:(NSString*)hoverEffect withCornerRadius:(CGFloat)cornerRadius {
518526
if (hoverEffect == nil || [hoverEffect isEqualToString:@""]) {
519527
self.hoverStyle = nil;
520528
return;
521529
}
522530

523-
UIShape *shape = [UIShape rectShapeWithCornerRadius:self.layer.cornerRadius];
531+
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
524532
id<UIHoverEffect> effect;
525533

526534
if ([hoverEffect isEqualToString:@"lift"]) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,18 @@ - (void)setHoverEffect:(NSString *)hoverEffect {
676676
return;
677677
}
678678

679-
UIShape *shape = [UIShape rectShapeWithCornerRadius:_borderRadius];
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];
680691
id<UIHoverEffect> effect;
681692

682693
if ([hoverEffect isEqualToString:@"lift"]) {

0 commit comments

Comments
 (0)