mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Make ScrollView sticky headers work w/o dispatching RCTEventEmitter.receiveEvent
Summary:
# Context
ScrollView sticky headers rely on this bit of code to work:
```
AnimatedImplementation.attachNativeEvent(
this._scrollViewRef,
'onScroll',
[{nativeEvent: {contentOffset: {y: this._scrollAnimatedValue}}}],
);
```
What this code means:
When the ScrollView host component receives the "onScroll" event, assign event.nativeEvent.contentOffSet.y to the this._scrollAnimatedValue AnimatedValue.
How this subscription mechanism is set up:
NativeAnimatedTurboModule subscribes to events dispatched by RCTEventDispatcher sendEvent. Then, whenever RCTEventEmitter sendEvent executes, NativeAnimatedTurboModule also updates the AnimatedValue for that event.
# Problem
Previously, in bridgeless, we started dispatching RCTScrollView via the RCTEventDispatcher sendEvent to update the AnimatedValue for ScrollView. This meant that we started dispatching the onScroll event to JavaScript via RCTEventEmitter.receiveEvent JSModule, which isn't supported in the Fabric renderer.
With this diff, we dialed back that solution. Instead of (1) notifying NativeAnimatedTurboModule and (2) sending the onScroll event to JavaScript, we're only doing (1) (i.e: notifying NativeAnimatedTurboModule).
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D37257719
fbshipit-source-id: 7dea3cf8b9ae78f6b0fd40414b8f224d43367a5a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f97c6a5b49
commit
8dded42b68
@@ -102,6 +102,11 @@ typedef NS_ENUM(NSInteger, RCTTextEventType) {
|
||||
key:(NSString *)key
|
||||
eventCount:(NSInteger)eventCount;
|
||||
|
||||
/**
|
||||
* Notify Observers of event
|
||||
*/
|
||||
- (void)notifyObserversOfEvent:(id<RCTEvent>)event;
|
||||
|
||||
/**
|
||||
* Send a pre-prepared event object.
|
||||
*
|
||||
|
||||
@@ -110,7 +110,7 @@ RCT_EXPORT_MODULE()
|
||||
[self sendEvent:event];
|
||||
}
|
||||
|
||||
- (void)sendEvent:(id<RCTEvent>)event
|
||||
- (void)notifyObserversOfEvent:(id<RCTEvent>)event
|
||||
{
|
||||
[_observersLock lock];
|
||||
|
||||
@@ -119,6 +119,11 @@ RCT_EXPORT_MODULE()
|
||||
}
|
||||
|
||||
[_observersLock unlock];
|
||||
}
|
||||
|
||||
- (void)sendEvent:(id<RCTEvent>)event
|
||||
{
|
||||
[self notifyObserversOfEvent:event];
|
||||
|
||||
[_eventQueueLock lock];
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol
|
||||
[bridge.eventDispatcher sendEvent:scrollEvent];
|
||||
} else {
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:scrollEvent, @"event", nil];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTSendEventToLegacyEventDispatcher"
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED"
|
||||
object:nil
|
||||
userInfo:userInfo];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user