From 31bb85a210e8a6edba4f59df6eb36ccc5cc58d9e Mon Sep 17 00:00:00 2001 From: Martin Kralik Date: Fri, 1 Apr 2016 06:53:13 -0700 Subject: [PATCH] limit fake scroll event emitting Summary:A need for sending a scroll events outside of scrollview made D3092854 a bit clunky. This diff kinda fixes it by tightening up emitting of fake scroll events just to the only usecase we have right now. Why not just simply construct the event in `RCTNavigator`, so we can drop the code from `RCTScrollView` altogether? `RCTScrollEvent` is private to `RCTScrollView`, and that's good. We don't want anyone have an ability to make up scroll events. Even this existing functionality should be sunset one day when we better integrate with native gesture recognizers. Depends on D3092867. Reviewed By: javache Differential Revision: D3120751 fb-gh-sync-id: 6519c055b983cfd48c4b4a9d619c4452e12efda1 fbshipit-source-id: 6519c055b983cfd48c4b4a9d619c4452e12efda1 --- React/Views/RCTNavigator.m | 6 +----- React/Views/RCTScrollView.h | 9 ++------- React/Views/RCTScrollView.m | 27 ++++++++++++--------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/React/Views/RCTNavigator.m b/React/Views/RCTNavigator.m index 77b02730fc7..03b4a79b7c8 100644 --- a/React/Views/RCTNavigator.m +++ b/React/Views/RCTNavigator.m @@ -449,11 +449,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (void)dispatchFakeScrollEvent { - [_bridge.eventDispatcher sendScrollEventWithType:RCTScrollEventTypeMove - reactTag:self.reactTag - scrollView:nil - userData:nil - coalescingKey:0]; + [_bridge.eventDispatcher sendFakeScrollEvent:self.reactTag]; } /** diff --git a/React/Views/RCTScrollView.h b/React/Views/RCTScrollView.h index 655e8eb7059..056e0040f5c 100644 --- a/React/Views/RCTScrollView.h +++ b/React/Views/RCTScrollView.h @@ -56,13 +56,8 @@ @interface RCTEventDispatcher (RCTScrollView) /** - * Send a scroll event. - * (You can send a fake scroll event by passing nil for scrollView). + * Send a fake scroll event. */ -- (void)sendScrollEventWithType:(RCTScrollEventType)type - reactTag:(NSNumber *)reactTag - scrollView:(UIScrollView *)scrollView - userData:(NSDictionary *)userData - coalescingKey:(uint16_t)coalescingKey; +- (void)sendFakeScrollEvent:(NSNumber *)reactTag; @end diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 5440084e6ad..703de4db301 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -931,29 +931,26 @@ RCT_SET_AND_PRESERVE_OFFSET(setScrollIndicatorInsets, scrollIndicatorInsets, UIE _coalescingKey++; _lastEmittedEventType = type; } - [_eventDispatcher sendScrollEventWithType:type - reactTag:reactTag - scrollView:scrollView - userData:userData - coalescingKey:_coalescingKey]; + RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type + reactTag:reactTag + scrollView:scrollView + userData:userData + coalescingKey:_coalescingKey]; + [_eventDispatcher sendEvent:scrollEvent]; } @end @implementation RCTEventDispatcher (RCTScrollView) -- (void)sendScrollEventWithType:(RCTScrollEventType)type - reactTag:(NSNumber *)reactTag - scrollView:(UIScrollView *)scrollView - userData:(NSDictionary *)userData - coalescingKey:(uint16_t)coalescingKey +- (void)sendFakeScrollEvent:(NSNumber *)reactTag { - RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type + RCTScrollEvent *fakeScrollEvent = [[RCTScrollEvent alloc] initWithType:RCTScrollEventTypeMove reactTag:reactTag - scrollView:scrollView - userData:userData - coalescingKey:coalescingKey]; - [self sendEvent:scrollEvent]; + scrollView:nil + userData:nil + coalescingKey:0]; + [self sendEvent:fakeScrollEvent]; } @end