git.iko.soy/rowtype-yoga/purescript-yoga-react-native
on main help sign in
Custom borderless button with layer-based hover highlight
commit1bef37472a6118008653bfe99739df9715880089 authorMark <mark.eibes@gmail.com> dateThu 19 Feb 2026, 10:25 (7 months ago) parentcbf03a6
1 file changed+13−8
example-macos/macos/YogaReactExample-macOS/RCTMacOSControlsManager.m+13−8
example-macos/macos/YogaReactExample-macOS/RCTMacOSControlsManager.m+13−8
@@ -23,6 +23,7 @@
2323
2424@interface RCTNativeButtonView : NSView
2525@property (nonatomic, strong) NSButton *button;
26+@property (nonatomic, strong) CALayer *hoverLayer;
2627@property (nonatomic, copy) RCTDirectEventBlock onPressButton;
2728@property (nonatomic, copy) NSString *title;
2829@property (nonatomic, copy) NSString *sfSymbol;
@@ -49,17 +50,17 @@
4950}
5051
5152- (void)mouseEntered:(NSEvent *)event {
52− if (_button.wantsLayer) {
53+ if (_hoverLayer) {
5354 BOOL isDark = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameDarkAqua]] != nil;
54− _button.layer.backgroundColor = isDark
55+ _hoverLayer.backgroundColor = isDark
5556 ? [NSColor colorWithWhite:1.0 alpha:0.15].CGColor
5657 : [NSColor colorWithWhite:0.0 alpha:0.1].CGColor;
5758 }
5859}
5960
6061- (void)mouseExited:(NSEvent *)event {
61− if (_button.wantsLayer) {
62− _button.layer.backgroundColor = nil;
62+ if (_hoverLayer) {
63+ _hoverLayer.backgroundColor = nil;
6364 }
6465}
6566
@@ -98,15 +99,15 @@
9899 else if ([bezelStyle isEqualToString:@"accessoryBarAction"]) _button.bezelStyle = NSBezelStyleAccessoryBarAction;
99100 else if ([bezelStyle isEqualToString:@"borderless"]) {
100101 _button.bordered = NO;
101− _button.wantsLayer = YES;
102− _button.layer.cornerRadius = 6.0;
103− // Add tracking area for hover highlight
102+ self.wantsLayer = YES;
103+ _hoverLayer = [CALayer layer];
104+ [self.layer insertSublayer:_hoverLayer below:_button.layer];
104105 NSTrackingArea *ta = [[NSTrackingArea alloc]
105106 initWithRect:NSZeroRect
106107 options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect
107108 owner:self
108109 userInfo:nil];
109− [_button addTrackingArea:ta];
110+ [self addTrackingArea:ta];
110111 }
111112 else _button.bezelStyle = NSBezelStylePush;
112113}
@@ -131,6 +132,10 @@
131132- (void)layout {
132133 [super layout];
133134 _button.frame = self.bounds;
135+ if (_hoverLayer) {
136+ _hoverLayer.frame = self.bounds;
137+ _hoverLayer.cornerRadius = self.bounds.size.height / 2.0;
138+ }
134139}
135140@end
136141