From e2ffa3f99728383d5983a2e3ab13f4bd3e076a99 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey <96719+shwanton@users.noreply.github.com> Date: Thu, 1 Dec 2022 11:52:34 -0800 Subject: [PATCH] [Fabric] Convert UIScrollView to RCTUIScrollView shim (#1526) * [Fabric] Replace UIKit with RCTUIKit * [Fabric] Convert UIScrollView with RCTUIScrollView shim * Undo comment change * Add macOS tags * Fix whitespace Co-authored-by: Shawn Dempsey --- .../ScrollView/RCTEnhancedScrollView.h | 2 +- .../ScrollView/RCTEnhancedScrollView.mm | 6 ++-- .../ScrollView/RCTScrollViewComponentView.h | 2 +- .../ScrollView/RCTScrollViewComponentView.mm | 28 +++++++++---------- .../TextInput/RCTTextInputComponentView.mm | 2 +- .../Views/RefreshControl/RCTRefreshControl.h | 2 +- .../Views/ScrollView/RCTScrollableProtocol.h | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.h b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.h index 3c85ab290f8494..b09d1bc1faeb51 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.h +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN * `UIScrollView` subclass which has some improvements and tweaks * which are not directly related to React Native. */ -@interface RCTEnhancedScrollView : UIScrollView +@interface RCTEnhancedScrollView : RCTUIScrollView // TODO(macOS GH#774) /* * Returns a delegate splitter that can be used to create as many `UIScrollView` delegates as needed. diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm index 93af874f451c58..5427e2bfbb7d02 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTEnhancedScrollView.mm @@ -130,9 +130,9 @@ - (void)setDelegate:(id)delegate #pragma mark - UIScrollViewDelegate -- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView +- (void)scrollViewWillEndDragging:(RCTUIScrollView *)scrollView withVelocity:(CGPoint)velocity - targetContentOffset:(inout CGPoint *)targetContentOffset + targetContentOffset:(inout CGPoint *)targetContentOffset // TODO(macOS GH#774) { if (self.snapToOffsets && self.snapToOffsets.count > 0) { // An alternative to enablePaging and snapToInterval which allows setting custom @@ -259,7 +259,7 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView #pragma mark - -- (BOOL)isHorizontal:(UIScrollView *)scrollView +- (BOOL)isHorizontal:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { return scrollView.contentSize.width > self.frame.size.width; } diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h index 785d28a47c79dd..5dbb7aed5bf3df 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN /* * Returns an actual UIScrollView that this component uses under the hood. */ -@property (nonatomic, strong, readonly) UIScrollView *scrollView; +@property (nonatomic, strong, readonly) RCTUIScrollView *scrollView; // TODO(macOS GH#774) /* * Returns the subview of the scroll view that the component uses to mount all subcomponents into. That's useful to diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 2ebbb0e82ac91e..da4bda87e93e55 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -56,7 +56,7 @@ static UIScrollViewIndicatorStyle RCTUIScrollViewIndicatorStyleFromProps(ScrollV // This is just a workaround to allow animations based on onScroll event. // This is only used to animate sticky headers in ScrollViews, and only the contentOffset and tag is used. // TODO: T116850910 [Fabric][iOS] Make Fabric not use legacy RCTEventDispatcher for native-driven AnimatedEvents -static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrollView, NSInteger tag) +static void RCTSendScrollEventForNativeAnimations_DEPRECATED(RCTUIScrollView *scrollView, NSInteger tag) // TODO(macOS GH#774) { static uint16_t coalescingKey = 0; RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithEventName:@"onScroll" @@ -416,7 +416,7 @@ - (BOOL)touchesShouldCancelInContentView:(__unused UIView *)view return ![self _shouldDisableScrollInteraction]; } -- (void)scrollViewDidScroll:(UIScrollView *)scrollView +- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { if (!_isUserTriggeredScrolling) { [self _updateStateWithContentOffset]; @@ -435,24 +435,24 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView [self _remountChildrenIfNeeded]; } -- (void)scrollViewDidZoom:(UIScrollView *)scrollView +- (void)scrollViewDidZoom:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { [self scrollViewDidScroll:scrollView]; } -- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView +- (BOOL)scrollViewShouldScrollToTop:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { _isUserTriggeredScrolling = YES; return YES; } -- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView +- (void)scrollViewDidScrollToTop:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { _isUserTriggeredScrolling = NO; [self _updateStateWithContentOffset]; } -- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView +- (void)scrollViewWillBeginDragging:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; @@ -464,7 +464,7 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView _isUserTriggeredScrolling = YES; } -- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate +- (void)scrollViewDidEndDragging:(RCTUIScrollView *)scrollView willDecelerate:(BOOL)decelerate // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; @@ -476,7 +476,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL [self _updateStateWithContentOffset]; } -- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView +- (void)scrollViewWillBeginDecelerating:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; @@ -488,7 +488,7 @@ - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView ->onMomentumScrollBegin([self _scrollViewMetrics]); } -- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +- (void)scrollViewDidEndDecelerating:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; @@ -501,12 +501,12 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView _isUserTriggeredScrolling = NO; } -- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView +- (void)scrollViewDidEndScrollingAnimation:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { [self _handleFinishedScrolling:scrollView]; } -- (void)_handleFinishedScrolling:(UIScrollView *)scrollView +- (void)_handleFinishedScrolling:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; [self scrollViewDidScroll:scrollView]; @@ -519,7 +519,7 @@ - (void)_handleFinishedScrolling:(UIScrollView *)scrollView [self _updateStateWithContentOffset]; } -- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view +- (void)scrollViewWillBeginZooming:(RCTUIScrollView *)scrollView withView:(nullable UIView *)view // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; @@ -530,7 +530,7 @@ - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable std::static_pointer_cast(_eventEmitter)->onScrollBeginDrag([self _scrollViewMetrics]); } -- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale +- (void)scrollViewDidEndZooming:(RCTUIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale // TODO(macOS GH#774) { [self _forceDispatchNextScrollEvent]; @@ -542,7 +542,7 @@ - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UI [self _updateStateWithContentOffset]; } -- (UIView *)viewForZoomingInScrollView:(__unused UIScrollView *)scrollView +- (UIView *)viewForZoomingInScrollView:(__unused RCTUIScrollView *)scrollView // TODO(macOS GH#774) { return _containerView; } diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index c78fe580dc429b..658ea391a134be 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -409,7 +409,7 @@ - (void)textInputDidChangeSelection #pragma mark - RCTBackedTextInputDelegate (UIScrollViewDelegate) -- (void)scrollViewDidScroll:(UIScrollView *)scrollView +- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // TODO(macOS GH#774) { if (_eventEmitter) { std::static_pointer_cast(_eventEmitter)->onScroll([self _textInputMetrics]); diff --git a/React/Views/RefreshControl/RCTRefreshControl.h b/React/Views/RefreshControl/RCTRefreshControl.h index a11b801f9ea895..f3d6b2cdc6e150 100644 --- a/React/Views/RefreshControl/RCTRefreshControl.h +++ b/React/Views/RefreshControl/RCTRefreshControl.h @@ -14,6 +14,6 @@ @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) RCTDirectEventBlock onRefresh; -@property (nonatomic, weak) UIScrollView *scrollView; +@property (nonatomic, weak) RCTUIScrollView *scrollView; // TODO(macOS GH#774) @end diff --git a/React/Views/ScrollView/RCTScrollableProtocol.h b/React/Views/ScrollView/RCTScrollableProtocol.h index 45610b457e303e..d1ff41cea33402 100644 --- a/React/Views/ScrollView/RCTScrollableProtocol.h +++ b/React/Views/ScrollView/RCTScrollableProtocol.h @@ -42,7 +42,7 @@ #if !TARGET_OS_OSX // TODO(macOS GH#774) @optional -@property (nonatomic, weak) UIScrollView *scrollView; +@property (nonatomic, weak) RCTUIScrollView *scrollView; #endif // TODO(macOS GH#774) @end