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
This commit is contained in:
Samuel Susla
2019-10-11 06:55:21 -07:00
committed by Facebook Github Bot
parent 90977b0e00
commit ffc7ec992c
2 changed files with 36 additions and 1 deletions
@@ -8,6 +8,8 @@
#import "RCTScrollViewComponentView.h"
#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTScrollEvent.h>
#import <react/components/scrollview/ScrollViewComponentDescriptor.h>
#import <react/components/scrollview/ScrollViewEventEmitter.h>
@@ -20,6 +22,21 @@
using namespace facebook::react;
static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteger tag)
{
static uint16_t coalescingKey = 0;
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithEventName:@"onScroll"
reactTag:[NSNumber numberWithInt:tag]
scrollViewContentOffset:scrollView.contentOffset
scrollViewContentInset:scrollView.contentInset
scrollViewContentSize:scrollView.contentSize
scrollViewFrame:scrollView.frame
scrollViewZoomScale:scrollView.zoomScale
userData:nil
coalescingKey:coalescingKey];
[[RCTBridge currentBridge].eventDispatcher sendEvent:scrollEvent];
}
@interface RCTScrollViewComponentView () <UIScrollViewDelegate>
@end
@@ -211,6 +228,9 @@ using namespace facebook::react;
if ((_lastScrollEventDispatchTime == 0) || (now - _lastScrollEventDispatchTime > _scrollEventThrottle)) {
_lastScrollEventDispatchTime = now;
std::static_pointer_cast<ScrollViewEventEmitter const>(_eventEmitter)->onScroll([self _scrollViewMetrics]);
// Once Fabric implements proper NativeAnimationDriver, this should be removed.
// This is just a workaround to allow animations based on onScroll event.
RCTSendPaperScrollEvent_DEPRECATED(scrollView, self.tag);
}
}
+16 -1
View File
@@ -335,7 +335,22 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
- (NSString *)viewNameForReactTag:(NSNumber *)reactTag
{
RCTAssertUIManagerQueue();
return _shadowViewRegistry[reactTag].viewName;
NSString *name = _shadowViewRegistry[reactTag].viewName;
if (name) {
return name;
}
UIView *view = _viewRegistry[reactTag];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
if ([view respondsToSelector:@selector(componentViewName_DO_NOT_USE_THIS_IS_BROKEN)]) {
return [view performSelector:@selector(componentViewName_DO_NOT_USE_THIS_IS_BROKEN)];
}
#pragma clang diagnostic pop
return nil;
}
- (UIView *)viewForReactTag:(NSNumber *)reactTag