Skip to content

[Fabric] Convert UIView to RCTUIView shim #1524

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

Merged
merged 10 commits into from
Dec 7, 2022
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 @@ -20,18 +20,18 @@

using namespace facebook::react;

static UIView<RCTBackedTextInputViewProtocol> *_Nullable RCTFindTextInputWithNativeId(UIView *view, NSString *nativeId)
static RCTUIView<RCTBackedTextInputViewProtocol> *_Nullable RCTFindTextInputWithNativeId(RCTUIView *view, NSString *nativeId) // TODO(macOS GH#774)
{
if ([view respondsToSelector:@selector(inputAccessoryViewID)] &&
[view respondsToSelector:@selector(setInputAccessoryView:)]) {
UIView<RCTBackedTextInputViewProtocol> *typed = (UIView<RCTBackedTextInputViewProtocol> *)view;
RCTUIView<RCTBackedTextInputViewProtocol> *typed = (RCTUIView<RCTBackedTextInputViewProtocol> *)view; // TODO(macOS GH#774)
if (!nativeId || [typed.inputAccessoryViewID isEqualToString:nativeId]) {
return typed;
}
}

for (UIView *subview in view.subviews) {
UIView<RCTBackedTextInputViewProtocol> *result = RCTFindTextInputWithNativeId(subview, nativeId);
for (RCTUIView *subview in view.subviews) { // TODO(macOS GH#774)
RCTUIView<RCTBackedTextInputViewProtocol> *result = RCTFindTextInputWithNativeId(subview, nativeId); // TODO(macOS GH#774)
if (result) {
return result;
}
Expand All @@ -44,7 +44,7 @@ @implementation RCTInputAccessoryComponentView {
InputAccessoryShadowNode::ConcreteState::Shared _state;
RCTInputAccessoryContentView *_contentView;
RCTSurfaceTouchHandler *_touchHandler;
UIView<RCTBackedTextInputViewProtocol> __weak *_textInput;
RCTUIView<RCTBackedTextInputViewProtocol> __weak *_textInput; // TODO(macOS GH#774)
}

- (instancetype)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -83,7 +83,7 @@ - (BOOL)canBecomeFirstResponder
return true;
}

- (UIView *)inputAccessoryView
- (RCTUIView *)inputAccessoryView // TODO(macOS GH#774)
{
return _contentView;
}
Expand All @@ -95,12 +95,12 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
return concreteComponentDescriptorProvider<InputAccessoryComponentDescriptor>();
}

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[_contentView insertSubview:childComponentView atIndex:index];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[childComponentView removeFromSuperview];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

#import <React/RCTUIKit.h> // TODO(macOS GH#774)

@interface RCTInputAccessoryContentView : UIView
@interface RCTInputAccessoryContentView : RCTUIView // TODO(macOS GH#774)

@end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#import "RCTInputAccessoryContentView.h"

@implementation RCTInputAccessoryContentView {
UIView *_safeAreaContainer;
RCTUIView *_safeAreaContainer; // TODO(macOS GH#774)
NSLayoutConstraint *_heightConstraint;
}

Expand All @@ -17,7 +17,7 @@ - (instancetype)init
if (self = [super init]) {
self.autoresizingMask = UIViewAutoresizingFlexibleHeight;

_safeAreaContainer = [UIView new];
_safeAreaContainer = [RCTUIView new]; // TODO(macOS GH#774)
_safeAreaContainer.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_safeAreaContainer];

Expand All @@ -40,7 +40,7 @@ - (CGSize)intrinsicContentSize
return CGSizeZero;
}

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
- (void)insertSubview:(RCTUIView *)view atIndex:(NSInteger)index // TODO(macOS GH#774)
{
[_safeAreaContainer insertSubview:view atIndex:index];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@implementation RCTLegacyViewManagerInteropComponentView {
NSMutableArray<NSDictionary *> *_viewsToBeMounted;
NSMutableArray<UIView *> *_viewsToBeUnmounted;
NSMutableArray<RCTUIView *> *_viewsToBeUnmounted; // TODO(macOS GH#774)
RCTLegacyViewManagerInteropCoordinatorAdapter *_adapter;
LegacyViewManagerInteropShadowNode::ConcreteState::Shared _state;
BOOL _hasInvokedForwardingWarning;
Expand All @@ -41,9 +41,9 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
- (RCTUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event // TODO(macOS GH#774)
{
UIView *result = [super hitTest:point withEvent:event];
RCTUIView *result = [super hitTest:point withEvent:event]; // TODO(macOS GH#774)

if (result == _adapter.paperView) {
return self;
Expand Down Expand Up @@ -149,15 +149,15 @@ - (void)prepareForRecycle
[super prepareForRecycle];
}

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[_viewsToBeMounted addObject:@{
kRCTLegacyInteropChildIndexKey : [NSNumber numberWithInteger:index],
kRCTLegacyInteropChildComponentKey : childComponentView
}];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
if (_adapter) {
[_adapter.paperView removeReactSubview:childComponentView];
Expand Down Expand Up @@ -208,7 +208,7 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask

[_viewsToBeMounted removeAllObjects];

for (UIView *view in _viewsToBeUnmounted) {
for (RCTUIView *view in _viewsToBeUnmounted) { // TODO(macOS GH#774)
[_adapter.paperView removeReactSubview:view];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithCoordinator:(RCTLegacyViewManagerInteropCoordinator *)coordinator reactTag:(NSInteger)tag;

@property (strong, nonatomic) UIView *paperView;
@property (strong, nonatomic) RCTUIView *paperView; // TODO(macOS GH#774)

@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (void)dealloc
[_coordinator removeObserveForTag:_tag];
}

- (UIView *)paperView
- (RCTUIView *)paperView // TODO(macOS GH#774)
{
if (!_paperView) {
_paperView = [_coordinator createPaperViewWithTag:_tag];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ @implementation RCTModalHostViewComponentView {
BOOL _shouldAnimatePresentation;
BOOL _shouldPresent;
BOOL _isPresented;
UIView *_modalContentsSnapshot;
RCTUIView *_modalContentsSnapshot; // TODO(macOS GH#774)
}

- (instancetype)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -165,7 +165,7 @@ - (void)ensurePresentedOnlyIfNeeded
_isPresented = NO;
// To animate dismissal of view controller, snapshot of
// view hierarchy needs to be added to the UIViewController.
UIView *snapshot = _modalContentsSnapshot;
RCTUIView *snapshot = _modalContentsSnapshot; // TODO(macOS GH#774)
[self.viewController.view addSubview:snapshot];

[self dismissViewController:self.viewController
Expand Down Expand Up @@ -269,12 +269,12 @@ - (void)updateState:(facebook::react::State::Shared const &)state
_state = std::static_pointer_cast<const ModalHostViewShadowNode::ConcreteState>(state);
}

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[self.viewController.view insertSubview:childComponentView atIndex:index];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[childComponentView removeFromSuperview];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@protocol RCTEnhancedScrollViewOverridingDelegate <NSObject>

- (BOOL)touchesShouldCancelInContentView:(UIView *)view;
- (BOOL)touchesShouldCancelInContentView:(RCTUIView *)view; // TODO(macOS GH#774)

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ - (void)setContentOffset:(CGPoint)contentOffset
RCTSanitizeNaNValue(contentOffset.y, @"scrollView.contentOffset.y"));
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view
- (BOOL)touchesShouldCancelInContentView:(RCTUIView *)view // TODO(macOS GH#774)
{
if ([_overridingDelegate respondsToSelector:@selector(touchesShouldCancelInContentView:)]) {
return [_overridingDelegate touchesShouldCancelInContentView:view];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
/*
* Finds and returns the closet RCTScrollViewComponentView component to the given view
*/
+ (nullable RCTScrollViewComponentView *)findScrollViewComponentViewForView:(UIView *)view;
+ (nullable RCTScrollViewComponentView *)findScrollViewComponentViewForView:(RCTUIView *)view; // TODO(macOS GH#774)

/*
* Returns an actual UIScrollView that this component uses under the hood.
Expand All @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
* separate component views from auxiliary views to be able to reliably implement pull-to-refresh- and RTL-related
* functionality.
*/
@property (nonatomic, strong, readonly) UIView *containerView;
@property (nonatomic, strong, readonly) RCTUIView *containerView; // TODO(macOS GH#774)

/*
* Returns a delegate splitter that can be used to subscribe for UIScrollView delegate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ @implementation RCTScrollViewComponentView {
CGPoint _contentOffsetWhenClipped;
}

+ (RCTScrollViewComponentView *_Nullable)findScrollViewComponentViewForView:(UIView *)view
+ (RCTScrollViewComponentView *_Nullable)findScrollViewComponentViewForView:(RCTUIView *)view // TODO(macOS GH#774)
{
do {
view = view.superview;
Expand All @@ -124,7 +124,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_shouldUpdateContentInsetAdjustmentBehavior = YES;
[self addSubview:_scrollView];

_containerView = [[UIView alloc] initWithFrame:CGRectZero];
_containerView = [[RCTUIView alloc] initWithFrame:CGRectZero]; // TODO(macOS GH#774)
[_scrollView addSubview:_containerView];

[self.scrollViewDelegateSplitter addDelegate:self];
Expand Down Expand Up @@ -334,12 +334,12 @@ - (void)_preserveContentOffsetIfNeededWithBlock:(void (^)())block
[((RCTEnhancedScrollView *)_scrollView) preserveContentOffsetWithBlock:block];
}

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[_containerView insertSubview:childComponentView atIndex:index];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // TODO(macOS GH#774)
{
[childComponentView removeFromSuperview];
}
Expand All @@ -350,11 +350,11 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
*/
- (BOOL)_shouldDisableScrollInteraction
{
UIView *ancestorView = self.superview;
RCTUIView *ancestorView = self.superview; // TODO(macOS GH#774)

while (ancestorView) {
if ([ancestorView respondsToSelector:@selector(isJSResponder)]) {
BOOL isJSResponder = ((UIView<RCTComponentViewProtocol> *)ancestorView).isJSResponder;
BOOL isJSResponder = ((RCTUIView<RCTComponentViewProtocol> *)ancestorView).isJSResponder; // TODO(macOS GH#774)
if (isJSResponder) {
return YES;
}
Expand Down Expand Up @@ -409,7 +409,7 @@ - (void)prepareForRecycle

#pragma mark - UIScrollViewDelegate

- (BOOL)touchesShouldCancelInContentView:(__unused UIView *)view
- (BOOL)touchesShouldCancelInContentView:(__unused RCTUIView *)view // TODO(macOS GH#774)
{
// Historically, `UIScrollView`s in React Native do not cancel touches
// started on `UIControl`-based views (as normal iOS `UIScrollView`s do).
Expand Down Expand Up @@ -519,7 +519,7 @@ - (void)_handleFinishedScrolling:(RCTUIScrollView *)scrollView // TODO(macOS GH#
[self _updateStateWithContentOffset];
}

- (void)scrollViewWillBeginZooming:(RCTUIScrollView *)scrollView withView:(nullable UIView *)view // TODO(macOS GH#774)
- (void)scrollViewWillBeginZooming:(RCTUIScrollView *)scrollView withView:(nullable RCTUIView *)view // TODO(macOS GH#774)
{
[self _forceDispatchNextScrollEvent];

Expand All @@ -530,7 +530,7 @@ - (void)scrollViewWillBeginZooming:(RCTUIScrollView *)scrollView withView:(nulla
std::static_pointer_cast<ScrollViewEventEmitter const>(_eventEmitter)->onScrollBeginDrag([self _scrollViewMetrics]);
}

- (void)scrollViewDidEndZooming:(RCTUIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale // TODO(macOS GH#774)
- (void)scrollViewDidEndZooming:(RCTUIScrollView *)scrollView withView:(nullable RCTUIView *)view atScale:(CGFloat)scale // TODO(macOS GH#774)
{
[self _forceDispatchNextScrollEvent];

Expand All @@ -542,7 +542,7 @@ - (void)scrollViewDidEndZooming:(RCTUIScrollView *)scrollView withView:(nullable
[self _updateStateWithContentOffset];
}

- (UIView *)viewForZoomingInScrollView:(__unused RCTUIScrollView *)scrollView // TODO(macOS GH#774)
- (RCTUIView *)viewForZoomingInScrollView:(__unused RCTUIScrollView *)scrollView // TODO(macOS GH#774)
{
return _containerView;
}
Expand Down Expand Up @@ -610,7 +610,7 @@ - (void)scrollToEnd:(BOOL)animated

#pragma mark - Child views mounting

- (void)updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(UIView *)clipView
- (void)updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(RCTUIView *)clipView // TODO(macOS GH#774)
{
// Do nothing. ScrollView manages its subview clipping individually in `_remountChildren`.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @implementation RCTAccessibilityElement

- (CGRect)accessibilityFrame
{
UIView *container = (UIView *)self.accessibilityContainer;
RCTUIView *container = (RCTUIView *)self.accessibilityContainer; // TODO(macOS GH#774)
if (CGRectEqualToRect(_frame, CGRectZero)) {
return UIAccessibilityConvertFrameToScreenCoordinates(container.bounds, container);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
layoutManager:(RCTTextLayoutManager *)layoutManager
paragraphAttributes:(facebook::react::ParagraphAttributes)paragraphAttributes
frame:(CGRect)frame
view:(UIView *)view;
view:(RCTUIView *)view; // TODO(macOS GH#774)

/*
* Returns an array of `UIAccessibilityElement`s to be used for `UIAccessibilityContainer` implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ @implementation RCTParagraphComponentAccessibilityProvider {
RCTTextLayoutManager *_layoutManager;
ParagraphAttributes _paragraphAttributes;
CGRect _frame;
__weak UIView *_view;
__weak RCTUIView *_view; // TODO(macOS GH#774)
}

- (instancetype)initWithString:(facebook::react::AttributedString)attributedString
layoutManager:(RCTTextLayoutManager *)layoutManager
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
frame:(CGRect)frame
view:(UIView *)view
view:(RCTUIView *)view // TODO(macOS GH#774)
{
if (self = [super init]) {
_attributedString = attributedString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ @interface RCTTextInputComponentView () <RCTBackedTextInputDelegate, RCTTextInpu

@implementation RCTTextInputComponentView {
TextInputShadowNode::ConcreteState::Shared _state;
UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
RCTUIView<RCTBackedTextInputViewProtocol> *_backedTextInputView; // TODO(macOS GH#774)
NSUInteger _mostRecentEventCount;
NSAttributedString *_lastStringStateWasUpdatedWith;

Expand Down Expand Up @@ -603,7 +603,7 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
- (void)_setMultiline:(BOOL)multiline
{
[_backedTextInputView removeFromSuperview];
UIView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTUITextView new] : [RCTUITextField new];
RCTUIView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTUITextView new] : [RCTUITextField new]; // TODO(macOS GH#774)
backedTextInputView.frame = _backedTextInputView.frame;
RCTCopyBackedTextInput(_backedTextInputView, backedTextInputView);
_backedTextInputView = backedTextInputView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
NS_ASSUME_NONNULL_BEGIN

void RCTCopyBackedTextInput(
UIView<RCTBackedTextInputViewProtocol> *fromTextInput,
UIView<RCTBackedTextInputViewProtocol> *toTextInput);
RCTUIView<RCTBackedTextInputViewProtocol> *fromTextInput,
RCTUIView<RCTBackedTextInputViewProtocol> *toTextInput); // TODO(macOS GH#774)

UITextAutocorrectionType RCTUITextAutocorrectionTypeFromOptionalBool(std::optional<bool> autoCorrect);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
}

void RCTCopyBackedTextInput(
UIView<RCTBackedTextInputViewProtocol> *fromTextInput,
UIView<RCTBackedTextInputViewProtocol> *toTextInput)
RCTUIView<RCTBackedTextInputViewProtocol> *fromTextInput,
RCTUIView<RCTBackedTextInputViewProtocol> *toTextInput) // TODO(macOS GH#774)
{
toTextInput.attributedText = RCTSanitizeAttributedString(fromTextInput.attributedText);
toTextInput.placeholder = fromTextInput.placeholder;
Expand Down
Loading