RCTScrollEvent's init takes coalescing key
Reviewed By: javache Differential Revision: D3092854 fb-gh-sync-id: 5aaab55638871510e6a46797189c123a0ecef6b7 fbshipit-source-id: 5aaab55638871510e6a46797189c123a0ecef6b7
This commit is contained in:
parent
a496baa68c
commit
a37075dcec
|
@ -361,13 +361,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
|||
(RCTWrapperViewController *)[context viewControllerForKey:UITransitionContextFromViewControllerKey];
|
||||
RCTWrapperViewController *toController =
|
||||
(RCTWrapperViewController *)[context viewControllerForKey:UITransitionContextToViewControllerKey];
|
||||
|
||||
|
||||
// This may be triggered by a navigation controller unrelated to me: if so, ignore.
|
||||
if (fromController.navigationController != _navigationController ||
|
||||
toController.navigationController != _navigationController) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
NSUInteger indexOfFrom = [_currentViews indexOfObject:fromController.navItem];
|
||||
NSUInteger indexOfTo = [_currentViews indexOfObject:toController.navItem];
|
||||
CGFloat destination = indexOfFrom < indexOfTo ? 1.0 : -1.0;
|
||||
|
@ -450,9 +450,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
|||
- (void)dispatchFakeScrollEvent
|
||||
{
|
||||
[_bridge.eventDispatcher sendScrollEventWithType:RCTScrollEventTypeMove
|
||||
reactTag:self.reactTag
|
||||
scrollView:nil
|
||||
userData:nil];
|
||||
reactTag:self.reactTag
|
||||
scrollView:nil
|
||||
userData:nil
|
||||
coalescingKey:0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
- (void)sendScrollEventWithType:(RCTScrollEventType)type
|
||||
reactTag:(NSNumber *)reactTag
|
||||
scrollView:(UIScrollView *)scrollView
|
||||
userData:(NSDictionary *)userData;
|
||||
userData:(NSDictionary *)userData
|
||||
coalescingKey:(uint16_t)coalescingKey;
|
||||
|
||||
@end
|
||||
|
|
|
@ -28,7 +28,8 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
|
|||
- (instancetype)initWithType:(RCTScrollEventType)type
|
||||
reactTag:(NSNumber *)reactTag
|
||||
scrollView:(UIScrollView *)scrollView
|
||||
userData:(NSDictionary *)userData NS_DESIGNATED_INITIALIZER;
|
||||
userData:(NSDictionary *)userData
|
||||
coalescingKey:(uint16_t)coalescingKey NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -37,6 +38,7 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
|
|||
RCTScrollEventType _type;
|
||||
UIScrollView *_scrollView;
|
||||
NSDictionary *_userData;
|
||||
uint16_t _coalescingKey;
|
||||
}
|
||||
|
||||
@synthesize viewTag = _viewTag;
|
||||
|
@ -45,6 +47,7 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
|
|||
reactTag:(NSNumber *)reactTag
|
||||
scrollView:(UIScrollView *)scrollView
|
||||
userData:(NSDictionary *)userData
|
||||
coalescingKey:(uint16_t)coalescingKey
|
||||
{
|
||||
RCTAssertParam(reactTag);
|
||||
|
||||
|
@ -53,6 +56,7 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
|
|||
_viewTag = reactTag;
|
||||
_scrollView = scrollView;
|
||||
_userData = userData;
|
||||
_coalescingKey = coalescingKey;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -61,7 +65,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
|
||||
- (uint16_t)coalescingKey
|
||||
{
|
||||
return 0;
|
||||
return _coalescingKey;
|
||||
}
|
||||
|
||||
- (NSDictionary *)body
|
||||
|
@ -573,7 +577,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
|||
#define RCT_SCROLL_EVENT_HANDLER(delegateMethod, eventName) \
|
||||
- (void)delegateMethod:(UIScrollView *)scrollView \
|
||||
{ \
|
||||
[_eventDispatcher sendScrollEventWithType:eventName reactTag:self.reactTag scrollView:scrollView userData:nil]; \
|
||||
[self sendScrollEventWithType:eventName reactTag:self.reactTag scrollView:scrollView userData:nil]; \
|
||||
if ([_nativeScrollDelegate respondsToSelector:_cmd]) { \
|
||||
[_nativeScrollDelegate delegateMethod:scrollView]; \
|
||||
} \
|
||||
|
@ -609,7 +613,7 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
|
|||
NSArray<NSDictionary *> *childFrames = [self calculateChildFramesData];
|
||||
|
||||
// Dispatch event
|
||||
[_eventDispatcher sendScrollEventWithType:RCTScrollEventTypeMove
|
||||
[self sendScrollEventWithType:RCTScrollEventTypeMove
|
||||
reactTag:self.reactTag
|
||||
scrollView:scrollView
|
||||
userData:@{@"updatedChildFrames": childFrames}];
|
||||
|
@ -656,7 +660,7 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
|
|||
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
||||
{
|
||||
_allowNextScrollNoMatterWhat = YES; // Ensure next scroll event is recorded, regardless of throttle
|
||||
[_eventDispatcher sendScrollEventWithType:RCTScrollEventTypeStart reactTag:self.reactTag scrollView:scrollView userData:nil];
|
||||
[self sendScrollEventWithType:RCTScrollEventTypeStart reactTag:self.reactTag scrollView:scrollView userData:nil];
|
||||
RCT_FORWARD_SCROLL_EVENT(scrollViewWillBeginDragging:scrollView);
|
||||
}
|
||||
|
||||
|
@ -714,7 +718,7 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
|
|||
@"y": @(targetContentOffset->y)
|
||||
}
|
||||
};
|
||||
[_eventDispatcher sendScrollEventWithType:RCTScrollEventTypeEnd reactTag:self.reactTag scrollView:scrollView userData:userData];
|
||||
[self sendScrollEventWithType:RCTScrollEventTypeEnd reactTag:self.reactTag scrollView:scrollView userData:userData];
|
||||
|
||||
RCT_FORWARD_SCROLL_EVENT(scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset);
|
||||
}
|
||||
|
@ -726,13 +730,13 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
|
|||
|
||||
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
|
||||
{
|
||||
[_eventDispatcher sendScrollEventWithType:RCTScrollEventTypeStart reactTag:self.reactTag scrollView:scrollView userData:nil];
|
||||
[self sendScrollEventWithType:RCTScrollEventTypeStart reactTag:self.reactTag scrollView:scrollView userData:nil];
|
||||
RCT_FORWARD_SCROLL_EVENT(scrollViewWillBeginZooming:scrollView withView:view);
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
|
||||
{
|
||||
[_eventDispatcher sendScrollEventWithType:RCTScrollEventTypeEnd reactTag:self.reactTag scrollView:scrollView userData:nil];
|
||||
[self sendScrollEventWithType:RCTScrollEventTypeEnd reactTag:self.reactTag scrollView:scrollView userData:nil];
|
||||
RCT_FORWARD_SCROLL_EVENT(scrollViewDidEndZooming:scrollView withView:view atScale:scale);
|
||||
}
|
||||
|
||||
|
@ -916,6 +920,18 @@ RCT_SET_AND_PRESERVE_OFFSET(setScrollIndicatorInsets, scrollIndicatorInsets, UIE
|
|||
[_scrollView.refreshControl endRefreshing];
|
||||
}
|
||||
|
||||
- (void)sendScrollEventWithType:(RCTScrollEventType)type
|
||||
reactTag:(NSNumber *)reactTag
|
||||
scrollView:(UIScrollView *)scrollView
|
||||
userData:(NSDictionary *)userData
|
||||
{
|
||||
[_eventDispatcher sendScrollEventWithType:type
|
||||
reactTag:reactTag
|
||||
scrollView:scrollView
|
||||
userData:userData
|
||||
coalescingKey:0];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTEventDispatcher (RCTScrollView)
|
||||
|
@ -924,11 +940,13 @@ RCT_SET_AND_PRESERVE_OFFSET(setScrollIndicatorInsets, scrollIndicatorInsets, UIE
|
|||
reactTag:(NSNumber *)reactTag
|
||||
scrollView:(UIScrollView *)scrollView
|
||||
userData:(NSDictionary *)userData
|
||||
coalescingKey:(uint16_t)coalescingKey
|
||||
{
|
||||
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithType:type
|
||||
reactTag:reactTag
|
||||
scrollView:scrollView
|
||||
userData:userData];
|
||||
userData:userData
|
||||
coalescingKey:coalescingKey];
|
||||
[self sendEvent:scrollEvent];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue