forked from react/react-native
-
Notifications
You must be signed in to change notification settings - Fork 170
feat(rctuikit): Add RCTUITableView for RedboxV1 and RedboxV2 #3056
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
Open
Saadnajmi
wants to merge
20
commits into
microsoft:main
Choose a base branch
from
Saadnajmi:saadnajmi/rctuikit-v1-executor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fe71e06
feat(macos): add RCTUITableView compatibility primitive to RCTUIKit
Saadnajmi 553f1a2
fix(macos): implement RCTUILabel compatibility properties
Saadnajmi 7e3c010
feat(macos): add narrow RCTUIButton action bridge
Saadnajmi f7f6fa4
test(macos): add offscreen RCTUITableView compatibility tests
Saadnajmi 786ebf4
refactor(macos): migrate RedBox table to RCTUITableView
Saadnajmi 5734e2d
refactor(macos): migrate RedBox buttons to RCTUIButton
Saadnajmi bbc3c8a
fix(macos): correct RCTUITableView lifecycle and sizing
Saadnajmi d9d3cc5
fix(macos): constrain RCTUITableViewCell content
Saadnajmi 6f7039b
fix(macos): preserve fixed RCTUITableView row heights
Saadnajmi b82f4de
test(macos): strengthen RCTUITableView behavior coverage
Saadnajmi 9d8dd2a
fix(macos): preserve RedBox edge behavior
Saadnajmi d2b18ce
fix(macos): update table label wrapping on resize
Saadnajmi a3f1e51
fix(macos): preserve RCTUITableView header heights
Saadnajmi f47aa23
fix(macos): preserve custom RCTUITableViewCell layout
Saadnajmi f20f454
fix(macos): restore RedBox message card rounding
Saadnajmi ddaf239
fix(macos): reuse RCTUITableView header constraints
Saadnajmi 16689a3
fix(macos): preserve table cell content insets
Saadnajmi 19d39e5
test(macos): cover table cell visual layout regressions
Saadnajmi 6f069fe
test(macos): remove RCTUITableView native unit tests
Saadnajmi 1c04c34
refactor(macos): tag and align RedBox upstream diffs
Saadnajmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIButton.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
197
packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIButton.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are hidden behind
RCT_DEV_MENUupstream. Should we also be doing that here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would Meta accept these changes so we can reduce our diffs?