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
This commit is contained in:
Martin Kralik 2016-04-01 06:53:13 -07:00 committed by Facebook Github Bot 8
parent 1d3db4c5dc
commit 31bb85a210
3 changed files with 15 additions and 27 deletions

View File

@ -449,11 +449,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (void)dispatchFakeScrollEvent - (void)dispatchFakeScrollEvent
{ {
[_bridge.eventDispatcher sendScrollEventWithType:RCTScrollEventTypeMove [_bridge.eventDispatcher sendFakeScrollEvent:self.reactTag];
reactTag:self.reactTag
scrollView:nil
userData:nil
coalescingKey:0];
} }
/** /**

View File

@ -56,13 +56,8 @@
@interface RCTEventDispatcher (RCTScrollView) @interface RCTEventDispatcher (RCTScrollView)
/** /**
* Send a scroll event. * Send a fake scroll event.
* (You can send a fake scroll event by passing nil for scrollView).
*/ */
- (void)sendScrollEventWithType:(RCTScrollEventType)type - (void)sendFakeScrollEvent:(NSNumber *)reactTag;
reactTag:(NSNumber *)reactTag
scrollView:(UIScrollView *)scrollView
userData:(NSDictionary *)userData
coalescingKey:(uint16_t)coalescingKey;
@end @end

View File

@ -931,29 +931,26 @@ RCT_SET_AND_PRESERVE_OFFSET(setScrollIndicatorInsets, scrollIndicatorInsets, UIE
_coalescingKey++; _coalescingKey++;
_lastEmittedEventType = type; _lastEmittedEventType = type;
} }
[_eventDispatcher sendScrollEventWithType:type RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type
reactTag:reactTag reactTag:reactTag
scrollView:scrollView scrollView:scrollView
userData:userData userData:userData
coalescingKey:_coalescingKey]; coalescingKey:_coalescingKey];
[_eventDispatcher sendEvent:scrollEvent];
} }
@end @end
@implementation RCTEventDispatcher (RCTScrollView) @implementation RCTEventDispatcher (RCTScrollView)
- (void)sendScrollEventWithType:(RCTScrollEventType)type - (void)sendFakeScrollEvent:(NSNumber *)reactTag
reactTag:(NSNumber *)reactTag
scrollView:(UIScrollView *)scrollView
userData:(NSDictionary *)userData
coalescingKey:(uint16_t)coalescingKey
{ {
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type RCTScrollEvent *fakeScrollEvent = [[RCTScrollEvent alloc] initWithType:RCTScrollEventTypeMove
reactTag:reactTag reactTag:reactTag
scrollView:scrollView scrollView:nil
userData:userData userData:nil
coalescingKey:coalescingKey]; coalescingKey:0];
[self sendEvent:scrollEvent]; [self sendEvent:fakeScrollEvent];
} }
@end @end