Skip to content

Commit 31bb85a

Browse files
majakFacebook Github Bot 8
authored andcommitted
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
1 parent 1d3db4c commit 31bb85a

3 files changed

Lines changed: 15 additions & 27 deletions

File tree

React/Views/RCTNavigator.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,7 @@ - (void)handleTopOfStackChanged
449449

450450
- (void)dispatchFakeScrollEvent
451451
{
452-
[_bridge.eventDispatcher sendScrollEventWithType:RCTScrollEventTypeMove
453-
reactTag:self.reactTag
454-
scrollView:nil
455-
userData:nil
456-
coalescingKey:0];
452+
[_bridge.eventDispatcher sendFakeScrollEvent:self.reactTag];
457453
}
458454

459455
/**

React/Views/RCTScrollView.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,8 @@
5656
@interface RCTEventDispatcher (RCTScrollView)
5757

5858
/**
59-
* Send a scroll event.
60-
* (You can send a fake scroll event by passing nil for scrollView).
59+
* Send a fake scroll event.
6160
*/
62-
- (void)sendScrollEventWithType:(RCTScrollEventType)type
63-
reactTag:(NSNumber *)reactTag
64-
scrollView:(UIScrollView *)scrollView
65-
userData:(NSDictionary *)userData
66-
coalescingKey:(uint16_t)coalescingKey;
61+
- (void)sendFakeScrollEvent:(NSNumber *)reactTag;
6762

6863
@end

React/Views/RCTScrollView.m

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -931,29 +931,26 @@ - (void)sendScrollEventWithType:(RCTScrollEventType)type
931931
_coalescingKey++;
932932
_lastEmittedEventType = type;
933933
}
934-
[_eventDispatcher sendScrollEventWithType:type
935-
reactTag:reactTag
936-
scrollView:scrollView
937-
userData:userData
938-
coalescingKey:_coalescingKey];
934+
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type
935+
reactTag:reactTag
936+
scrollView:scrollView
937+
userData:userData
938+
coalescingKey:_coalescingKey];
939+
[_eventDispatcher sendEvent:scrollEvent];
939940
}
940941

941942
@end
942943

943944
@implementation RCTEventDispatcher (RCTScrollView)
944945

945-
- (void)sendScrollEventWithType:(RCTScrollEventType)type
946-
reactTag:(NSNumber *)reactTag
947-
scrollView:(UIScrollView *)scrollView
948-
userData:(NSDictionary *)userData
949-
coalescingKey:(uint16_t)coalescingKey
946+
- (void)sendFakeScrollEvent:(NSNumber *)reactTag
950947
{
951-
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type
948+
RCTScrollEvent *fakeScrollEvent = [[RCTScrollEvent alloc] initWithType:RCTScrollEventTypeMove
952949
reactTag:reactTag
953-
scrollView:scrollView
954-
userData:userData
955-
coalescingKey:coalescingKey];
956-
[self sendEvent:scrollEvent];
950+
scrollView:nil
951+
userData:nil
952+
coalescingKey:0];
953+
[self sendEvent:fakeScrollEvent];
957954
}
958955

959956
@end

0 commit comments

Comments
 (0)