Skip to content

Commit ffc7ec9

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Add support for ScrollView.onScroll animations
Summary: To enable onScroll animations with Fabric's scrollView on iOS, we dispatch onScroll event to Paper's eventDispatcher as well as to Fabric's one. One we have a proper NativeAnimationDriver in place, we will get rid of this. Reviewed By: shergin Differential Revision: D17814260 fbshipit-source-id: f04faf59cdfd4ea5cede513388e30500b4cb2ad5
1 parent 90977b0 commit ffc7ec9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#import "RCTScrollViewComponentView.h"
99

1010
#import <React/RCTAssert.h>
11+
#import <React/RCTBridge+Private.h>
12+
#import <React/RCTScrollEvent.h>
1113

1214
#import <react/components/scrollview/ScrollViewComponentDescriptor.h>
1315
#import <react/components/scrollview/ScrollViewEventEmitter.h>
@@ -20,6 +22,21 @@
2022

2123
using namespace facebook::react;
2224

25+
static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteger tag)
26+
{
27+
static uint16_t coalescingKey = 0;
28+
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithEventName:@"onScroll"
29+
reactTag:[NSNumber numberWithInt:tag]
30+
scrollViewContentOffset:scrollView.contentOffset
31+
scrollViewContentInset:scrollView.contentInset
32+
scrollViewContentSize:scrollView.contentSize
33+
scrollViewFrame:scrollView.frame
34+
scrollViewZoomScale:scrollView.zoomScale
35+
userData:nil
36+
coalescingKey:coalescingKey];
37+
[[RCTBridge currentBridge].eventDispatcher sendEvent:scrollEvent];
38+
}
39+
2340
@interface RCTScrollViewComponentView () <UIScrollViewDelegate>
2441

2542
@end
@@ -211,6 +228,9 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
211228
if ((_lastScrollEventDispatchTime == 0) || (now - _lastScrollEventDispatchTime > _scrollEventThrottle)) {
212229
_lastScrollEventDispatchTime = now;
213230
std::static_pointer_cast<ScrollViewEventEmitter const>(_eventEmitter)->onScroll([self _scrollViewMetrics]);
231+
// Once Fabric implements proper NativeAnimationDriver, this should be removed.
232+
// This is just a workaround to allow animations based on onScroll event.
233+
RCTSendPaperScrollEvent_DEPRECATED(scrollView, self.tag);
214234
}
215235
}
216236

React/Modules/RCTUIManager.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,22 @@ - (void)registerRootView:(RCTRootContentView *)rootView
335335
- (NSString *)viewNameForReactTag:(NSNumber *)reactTag
336336
{
337337
RCTAssertUIManagerQueue();
338-
return _shadowViewRegistry[reactTag].viewName;
338+
NSString *name = _shadowViewRegistry[reactTag].viewName;
339+
if (name) {
340+
return name;
341+
}
342+
343+
UIView *view = _viewRegistry[reactTag];
344+
345+
#pragma clang diagnostic push
346+
#pragma clang diagnostic ignored "-Wundeclared-selector"
347+
348+
if ([view respondsToSelector:@selector(componentViewName_DO_NOT_USE_THIS_IS_BROKEN)]) {
349+
return [view performSelector:@selector(componentViewName_DO_NOT_USE_THIS_IS_BROKEN)];
350+
}
351+
352+
#pragma clang diagnostic pop
353+
return nil;
339354
}
340355

341356
- (UIView *)viewForReactTag:(NSNumber *)reactTag

0 commit comments

Comments
 (0)