Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fe71e06
feat(macos): add RCTUITableView compatibility primitive to RCTUIKit
Saadnajmi Jul 28, 2026
553f1a2
fix(macos): implement RCTUILabel compatibility properties
Saadnajmi Jul 28, 2026
7e3c010
feat(macos): add narrow RCTUIButton action bridge
Saadnajmi Jul 28, 2026
f7f6fa4
test(macos): add offscreen RCTUITableView compatibility tests
Saadnajmi Jul 28, 2026
786ebf4
refactor(macos): migrate RedBox table to RCTUITableView
Saadnajmi Jul 28, 2026
5734e2d
refactor(macos): migrate RedBox buttons to RCTUIButton
Saadnajmi Jul 28, 2026
bbc3c8a
fix(macos): correct RCTUITableView lifecycle and sizing
Saadnajmi Jul 28, 2026
d9d3cc5
fix(macos): constrain RCTUITableViewCell content
Saadnajmi Jul 28, 2026
6f7039b
fix(macos): preserve fixed RCTUITableView row heights
Saadnajmi Jul 28, 2026
b82f4de
test(macos): strengthen RCTUITableView behavior coverage
Saadnajmi Jul 28, 2026
9d8dd2a
fix(macos): preserve RedBox edge behavior
Saadnajmi Jul 28, 2026
d2b18ce
fix(macos): update table label wrapping on resize
Saadnajmi Jul 28, 2026
a3f1e51
fix(macos): preserve RCTUITableView header heights
Saadnajmi Jul 28, 2026
f47aa23
fix(macos): preserve custom RCTUITableViewCell layout
Saadnajmi Jul 28, 2026
f20f454
fix(macos): restore RedBox message card rounding
Saadnajmi Jul 28, 2026
ddaf239
fix(macos): reuse RCTUITableView header constraints
Saadnajmi Jul 28, 2026
16689a3
fix(macos): preserve table cell content insets
Saadnajmi Jul 28, 2026
19d39e5
test(macos): cover table cell visual layout regressions
Saadnajmi Jul 28, 2026
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
403 changes: 95 additions & 308 deletions packages/react-native/React/CoreModules/RCTRedBox.mm

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#include <TargetConditionals.h>

#import "RCTUIKitCompat.h"

#if !TARGET_OS_OSX
#import <UIKit/UIKit.h>
#else
#import <AppKit/AppKit.h>
#endif

NS_ASSUME_NONNULL_BEGIN

#if !TARGET_OS_OSX

@compatibility_alias RCTUIButton UIButton;
#define RCTUIControlStateNormal UIControlStateNormal
#define RCTUIControlStateHighlighted UIControlStateHighlighted
typedef UIControlState RCTUIControlState;

#else // TARGET_OS_OSX [

typedef NS_OPTIONS(NSUInteger, RCTUIControlState) {
RCTUIControlStateNormal = 0,
RCTUIControlStateHighlighted = 1 << 0,
};

@interface RCTUIButtonTitleProxy : NSObject

@property (nonatomic, strong, nullable) UIFont *font;
@property (nonatomic, assign) NSLineBreakMode lineBreakMode;
@property (nonatomic, assign) NSTextAlignment textAlignment;

@end

@interface RCTUIButton : NSButton

@property (nonatomic, readonly) RCTUIButtonTitleProxy *titleLabel;
@property (nonatomic, copy, nullable) RCTUIColor *backgroundColor;

- (void)setTitle:(nullable NSString *)title forState:(RCTUIControlState)state;
- (void)setTitleColor:(nullable RCTUIColor *)color forState:(RCTUIControlState)state;

@end

#endif // ] TARGET_OS_OSX

typedef void (^RCTUIActionHandler)(void);

@interface RCTUIAction : NSObject

+ (instancetype)actionWithHandler:(RCTUIActionHandler)handler;
@property (nonatomic, readonly, copy) RCTUIActionHandler handler;

@end

@interface RCTUIButton (RCTUIAction)

- (void)rct_setPrimaryAction:(RCTUIAction *)action;

@end

NS_ASSUME_NONNULL_END
197 changes: 197 additions & 0 deletions packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#import "RCTUIButton.h"

#import <objc/runtime.h>

@interface RCTUIAction ()

- (instancetype)initWithHandler:(RCTUIActionHandler)handler;
- (void)invoke;

@end

@implementation RCTUIAction

+ (instancetype)actionWithHandler:(RCTUIActionHandler)handler
{
return [[self alloc] initWithHandler:handler];
}

- (instancetype)initWithHandler:(RCTUIActionHandler)handler
{
if (self = [super init]) {
_handler = [handler copy];
}
return self;
}

- (void)invoke
{
self.handler();
}

@end

#if TARGET_OS_OSX

@class RCTUIButton;

@interface RCTUIButtonTitleProxy ()

@property (nonatomic, weak) RCTUIButton *button;

- (instancetype)initWithButton:(RCTUIButton *)button;

@end

@interface RCTUIButton ()

- (void)updateAttributedTitles;

@end

@implementation RCTUIButtonTitleProxy

- (instancetype)initWithButton:(RCTUIButton *)button
{
if (self = [super init]) {
_button = button;
_font = button.font;
_lineBreakMode = NSLineBreakByClipping;
_textAlignment = NSTextAlignmentNatural;
}
return self;
}

- (void)setFont:(UIFont *)font
{
_font = font;
[self.button updateAttributedTitles];
}

- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode
{
_lineBreakMode = lineBreakMode;
[self.button updateAttributedTitles];
}

- (void)setTextAlignment:(NSTextAlignment)textAlignment
{
_textAlignment = textAlignment;
[self.button updateAttributedTitles];
}

@end

@implementation RCTUIButton {
NSString *_normalTitle;
NSString *_highlightedTitle;
RCTUIColor *_normalTitleColor;
RCTUIColor *_highlightedTitleColor;
}

- (instancetype)initWithFrame:(NSRect)frameRect
{
if (self = [super initWithFrame:frameRect]) {
_titleLabel = [[RCTUIButtonTitleProxy alloc] initWithButton:self];
}
return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
if (self = [super initWithCoder:coder]) {
_titleLabel = [[RCTUIButtonTitleProxy alloc] initWithButton:self];
}
return self;
}

- (void)setTitle:(NSString *)title forState:(RCTUIControlState)state
{
if (state == RCTUIControlStateHighlighted) {
_highlightedTitle = [title copy];
} else {
_normalTitle = [title copy];
}
[self updateAttributedTitles];
}

- (void)setTitleColor:(RCTUIColor *)color forState:(RCTUIControlState)state
{
if (state == RCTUIControlStateHighlighted) {
_highlightedTitleColor = [color copy];
} else {
_normalTitleColor = [color copy];
}
[self updateAttributedTitles];
}

- (void)setBackgroundColor:(RCTUIColor *)backgroundColor
{
_backgroundColor = [backgroundColor copy];
self.wantsLayer = YES;
self.layer.backgroundColor = backgroundColor.CGColor;
self.bordered = NO;
}

- (void)updateAttributedTitles
{
self.attributedTitle = [self attributedTitleForTitle:_normalTitle ?: @""
color:_normalTitleColor];
self.attributedAlternateTitle = [self attributedTitleForTitle:_highlightedTitle ?: _normalTitle ?: @""
color:_highlightedTitleColor ?: _normalTitleColor];
}

- (NSAttributedString *)attributedTitleForTitle:(NSString *)title color:(RCTUIColor *)color
{
NSMutableDictionary<NSAttributedStringKey, id> *attributes = [NSMutableDictionary new];
if (color != nil) {
attributes[NSForegroundColorAttributeName] = color;
}
if (self.titleLabel.font != nil) {
attributes[NSFontAttributeName] = self.titleLabel.font;
}

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineBreakMode = self.titleLabel.lineBreakMode;
paragraphStyle.alignment = self.titleLabel.textAlignment;
attributes[NSParagraphStyleAttributeName] = paragraphStyle;

return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}

@end

#endif

@implementation RCTUIButton (RCTUIAction)

- (void)rct_setPrimaryAction:(RCTUIAction *)action
{
#if !TARGET_OS_OSX
RCTUIAction *previousAction = objc_getAssociatedObject(self, @selector(rct_setPrimaryAction:));
if (previousAction != nil) {
[self removeTarget:previousAction action:@selector(invoke) forControlEvents:UIControlEventTouchUpInside];
}
#endif

objc_setAssociatedObject(
self, @selector(rct_setPrimaryAction:), action, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

#if !TARGET_OS_OSX
[self addTarget:action action:@selector(invoke) forControlEvents:UIControlEventTouchUpInside];
#else
self.target = action;
self.action = @selector(invoke);
#endif
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#import "RCTUIView.h"
#import "RCTUIScrollView.h"
#import "RCTUISlider.h"
#import "RCTUITableView.h"
#import "RCTUIButton.h"
#import "RCTUILabel.h"
#import "RCTUISwitch.h"
#import "RCTUIActivityIndicatorView.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ - (void)setText:(NSString *)text
[self setStringValue:text];
}

- (NSString *)text
{
return self.stringValue;
}

- (void)setNumberOfLines:(NSInteger)numberOfLines
{
self.maximumNumberOfLines = numberOfLines;
}

- (NSInteger)numberOfLines
{
return self.maximumNumberOfLines;
}

- (void)setTextAlignment:(NSTextAlignment)textAlignment
{
self.alignment = textAlignment;
}

- (NSTextAlignment)textAlignment
{
return self.alignment;
}

@end

#endif
Loading
Loading