Skip to content

Commit 6a49aa5

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 ff45cdc commit 6a49aa5

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

287287
// `border`
288-
if (oldViewProps.borderStyles != newViewProps.borderStyles || oldViewProps.borderRadii != newViewProps.borderRadii ||
288+
if (oldViewProps.borderStyles != newViewProps.borderStyles ||
289289
oldViewProps.borderColors != newViewProps.borderColors) {
290290
needsInvalidateLayer = YES;
291291
}
292-
292+
// 'borderRadii'
293+
if (oldViewProps.borderRadii != newViewProps.borderRadii) {
294+
needsInvalidateLayer = YES;
295+
#if TARGET_OS_VISION
296+
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
297+
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
298+
#endif
299+
}
293300
#if TARGET_OS_VISION
294301
if (oldViewProps.visionos_hoverEffect != newViewProps.visionos_hoverEffect) {
295-
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()]];
302+
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
303+
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
296304
}
297305
#endif
298306

@@ -516,13 +524,13 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
516524
}
517525

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

525-
UIShape *shape = [UIShape rectShapeWithCornerRadius:self.layer.cornerRadius];
533+
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
526534
id<UIHoverEffect> effect;
527535

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