Skip to content

[Fabric] Convert UIScrollView to RCTUIScrollView shim #1526

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 6 commits into from
Dec 1, 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 @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ - (void)setDelegate:(id<UIScrollViewDelegate>)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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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];
Expand All @@ -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];

Expand All @@ -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];

Expand All @@ -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];

Expand All @@ -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];

Expand All @@ -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];
Expand All @@ -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];

Expand All @@ -530,7 +530,7 @@ - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable
std::static_pointer_cast<ScrollViewEventEmitter const>(_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];

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextInputEventEmitter const>(_eventEmitter)->onScroll([self _textInputMetrics]);
Expand Down
2 changes: 1 addition & 1 deletion React/Views/RefreshControl/RCTRefreshControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion React/Views/ScrollView/RCTScrollableProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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