Skip to content

Commit 7adf3bc

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 8509a8c commit 7adf3bc

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
@@ -296,14 +296,22 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
296296
}
297297

298298
// `border`
299-
if (oldViewProps.borderStyles != newViewProps.borderStyles || oldViewProps.borderRadii != newViewProps.borderRadii ||
299+
if (oldViewProps.borderStyles != newViewProps.borderStyles ||
300300
oldViewProps.borderColors != newViewProps.borderColors) {
301301
needsInvalidateLayer = YES;
302302
}
303-
303+
// 'borderRadii'
304+
if (oldViewProps.borderRadii != newViewProps.borderRadii) {
305+
needsInvalidateLayer = YES;
306+
#if TARGET_OS_VISION
307+
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
308+
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
309+
#endif
310+
}
304311
#if TARGET_OS_VISION
305312
if (oldViewProps.visionos_hoverEffect != newViewProps.visionos_hoverEffect) {
306-
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()]];
313+
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
314+
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
307315
}
308316
#endif
309317

@@ -521,13 +529,13 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
521529
}
522530

523531
#if TARGET_OS_VISION
524-
- (void) updateHoverEffect:(NSString*)hoverEffect {
532+
- (void) updateHoverEffect:(NSString*)hoverEffect withCornerRadius:(CGFloat)cornerRadius {
525533
if (hoverEffect == nil || [hoverEffect isEqualToString:@""]) {
526534
self.hoverStyle = nil;
527535
return;
528536
}
529537

530-
UIShape *shape = [UIShape rectShapeWithCornerRadius:self.layer.cornerRadius];
538+
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
531539
id<UIHoverEffect> effect;
532540

533541
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)