forked from software-mansion/react-native-reanimated
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only intercept events with waiting handlers
Previously, NativeReanimatedModule::handleRawEvent would intercept all events received by the event listener. This resulted in an issue where onLayout would not fire in JS on the New Architecture. Instead, only intercept events with waiting handlers. This prevents asJSIValue from being called on the Reanimated event loop and allows onLayout to bubble up in JS. See https://github.com/facebook/react-native/blob/v0.76.2/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewEventEmitter.cpp#L82-L112, which prevents onLayout from being dispatched more than once. asJSIValue evaluates the lambda above in https://github.com/facebook/react-native/blob/v0.76.2/packages/react-native/ReactCommon/react/renderer/core/ValueFactoryEventPayload.cpp#L16. Fixes software-mansion#6684
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apps/common-app/src/examples/RuntimeTests/tests/core/onLayout.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useEffect } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import Animated, { runOnUI, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'; | ||
import { describe, expect, render, test, wait } from '../../ReJest/RuntimeTestsApi'; | ||
|
||
let height = 0; | ||
|
||
const TestComponent = ({}) => { | ||
const sv = useSharedValue(styles.smallBox.height); | ||
|
||
const onLayout = event => { | ||
height = event.nativeEvent.layout.height; | ||
}; | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
return { height: sv.value }; | ||
}); | ||
|
||
useEffect(() => { | ||
runOnUI(() => { | ||
sv.value += 100; | ||
})(); | ||
}); | ||
|
||
return ( | ||
<View onLayout={onLayout}> | ||
<Animated.View style={[styles.smallBox, animatedStyle]} /> | ||
</View> | ||
); | ||
}; | ||
|
||
describe('onLayout', () => { | ||
test('is not intercepted', async () => { | ||
await render(<TestComponent />); | ||
await wait(100); | ||
expect(height).toBe(200); | ||
}); | ||
}); | ||
|
||
const styles = StyleSheet.create({ | ||
smallBox: { | ||
width: 100, | ||
height: 100, | ||
backgroundColor: 'pink', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters