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
{
[_bridge.eventDispatcher sendScrollEventWithType:RCTScrollEventTypeMove
reactTag:self.reactTag
scrollView:nil
userData:nil
coalescingKey:0];
[_bridge.eventDispatcher sendFakeScrollEvent:self.reactTag];
}
/**

View File

@ -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

View File

@ -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