Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cornerRadius for hover style #66

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,22 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
}

// `border`
if (oldViewProps.borderStyles != newViewProps.borderStyles || oldViewProps.borderRadii != newViewProps.borderRadii ||
if (oldViewProps.borderStyles != newViewProps.borderStyles ||
oldViewProps.borderColors != newViewProps.borderColors) {
needsInvalidateLayer = YES;
}

// 'borderRadii'
if (oldViewProps.borderRadii != newViewProps.borderRadii) {
needsInvalidateLayer = YES;
#if TARGET_OS_VISION
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
#endif
}
#if TARGET_OS_VISION
if (oldViewProps.visionos_hoverEffect != newViewProps.visionos_hoverEffect) {
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()]];
CGFloat borderRadius = newViewProps.borderRadii.all ? newViewProps.borderRadii.all.value() : 0.0;
[self updateHoverEffect:[NSString stringWithUTF8String:newViewProps.visionos_hoverEffect.c_str()] withCornerRadius:borderRadius];
}
#endif

Expand Down Expand Up @@ -514,13 +522,13 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
}

#if TARGET_OS_VISION
- (void) updateHoverEffect:(NSString*)hoverEffect {
- (void) updateHoverEffect:(NSString*)hoverEffect withCornerRadius:(CGFloat)cornerRadius {
if (hoverEffect == nil || [hoverEffect isEqualToString:@""]) {
self.hoverStyle = nil;
return;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:self.layer.cornerRadius];
UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
id<UIHoverEffect> effect;

if ([hoverEffect isEqualToString:@"lift"]) {
Expand Down
13 changes: 12 additions & 1 deletion packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,18 @@ - (void)setHoverEffect:(NSString *)hoverEffect {
return;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:_borderRadius];
CGFloat cornerRadius = 0.0;
RCTCornerRadii cornerRadii = [self cornerRadii];

if (RCTCornerRadiiAreEqual(cornerRadii)) {
cornerRadius = cornerRadii.topLeft;

} else {
// TODO: Handle a case when corner radius is different for each corner.
cornerRadius = cornerRadii.topLeft;
}

UIShape *shape = [UIShape rectShapeWithCornerRadius:cornerRadius];
id<UIHoverEffect> effect;

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