react-native: Pressable gets stuck under the new architecture
Description
I’ve noticed that using the new architecture under a brand new app (expo app) the pressable button gets stuck. The example is from the Pressable documentation, with a minor change on how it shows the components. Disabling the new architecture it works as expected Using a Pixel_3a_API_34_extension_level_7_x86_64 emulator
Steps to reproduce
npx create-expo-app@latest -e with-new-arch
import React, {useState} from 'react';
import {Pressable, StyleSheet, Text, View} from 'react-native';
const App = () => {
const [timesPressed, setTimesPressed] = useState(0);
let textLog = '';
if (timesPressed > 1) {
textLog = timesPressed + 'x onPress';
} else if (timesPressed > 0) {
textLog = 'onPress';
}
return (
<View style={styles.container}>
<Pressable
onPress={() => {
setTimesPressed(current => current + 1);
}}
style={({pressed}) => [
{
backgroundColor: pressed ? 'rgb(210, 230, 255)' : 'white',
},
styles.wrapperCustom,
]}>
{({pressed}) => (
<>
{pressed && <Text style={styles.text}>Pressed!</Text>}
{!pressed && <Text style={styles.text}>Press Me</Text>}
</>
)}
</Pressable>
<View style={styles.logBox}>
<Text testID="pressable_press_console">{textLog}</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
text: {
fontSize: 16,
},
wrapperCustom: {
borderRadius: 8,
padding: 6,
},
logBox: {
padding: 20,
margin: 10,
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#f0f0f0',
backgroundColor: '#f9f9f9',
},
});
export default App;
React Native Version
0.74.1
Affected Platforms
Runtime - Android
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: Linux 6.8 Arch Linux
CPU: (16) x64 AMD Ryzen 7 PRO 4750U with Radeon Graphics
Memory: 7.84 GB / 29.11 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.11.0
path: ~/.nodenv/versions/20.11.0/bin/node
Yarn:
version: 1.22.22
path: /usr/bin/yarn
npm:
version: 10.2.4
path: ~/.nodenv/versions/20.11.0/bin/npm
Watchman:
version: 20240414.112832.0
path: /usr/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: AI-232.10300.40.2321.11668458
Languages:
Java:
version: 17.0.11
path: /usr/bin/javac
Ruby:
version: 3.3.0
path: /home/user/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.74.1
wanted: 0.74.1
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
### Stacktrace or Logs
```text
N/A
Reproducer
https://gist.github.com/xdmx/483cb093f59c23b1dee57b8b64c63696
https://github.com/xdmx/rn-pressable-bug
Screenshots and Videos
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (8 by maintainers)
Commits related to this issue
- Add reproducer to RN-Tester for #44610 Summary: I'm justing adding a repro to RN-Tester to furhter investigate: https://github.com/facebook/react-native/issues/44610 Changelog: [Internal] [Changed] ... — committed to cortinico/react-native by cortinico 2 years ago
- Add reproducer to RN-Tester for #44610 Summary: I'm justing adding a repro to RN-Tester to furhter investigate: https://github.com/facebook/react-native/issues/44610 Changelog: [Internal] [Changed] ... — committed to cortinico/react-native by cortinico 2 years ago
- Add reproducer to RN-Tester for #44610 Summary: I'm justing adding a repro to RN-Tester to furhter investigate: https://github.com/facebook/react-native/issues/44610 Changelog: [Internal] [Changed] ... — committed to cortinico/react-native by cortinico 2 years ago
- Add reproducer to RN-Tester for #44610 (#45293) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45293 I'm justing adding a repro to RN-Tester to further investigate: ht... — committed to facebook/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture Summary: This diff introduces the logic to defer the destruction of ViewState (and EventEmitter) for views that are currently ... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture (#45865) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45865 This diff introduces the logic t... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture (#45865) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45865 This diff introduces the logic t... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture Summary: This diff introduces the logic to defer the destruction of ViewState (and EventEmitter) for views that are currently ... — committed to cortinico/react-native by cortinico 2 years ago
- Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to gate the Pressable fix Summary: This introduces the `enableEventEmitterRetentionDuringGesturesOnAndroid` that allows us to gate the... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture Summary: This diff introduces the logic to defer the destruction of ViewState (and EventEmitter) for views that are currently ... — committed to cortinico/react-native by cortinico 2 years ago
- Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to gate the Pressable fix (#45930) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45930 This introduce... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture Summary: This diff introduces the logic to defer the destruction of ViewState (and EventEmitter) for views that are currently ... — committed to cortinico/react-native by cortinico 2 years ago
- Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to gate the Pressable fix (#45930) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45930 This introduce... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture (#45865) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45865 This diff introduces the logic t... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture (#45865) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45865 This diff introduces the logic t... — committed to cortinico/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture Summary: This diff introduces the logic to defer the destruction of ViewState (and EventEmitter) for views that are currently ... — committed to cortinico/react-native by cortinico 2 years ago
- Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to gate the Pressable fix (#45930) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45930 This introduce... — committed to cortinico/react-native by cortinico 2 years ago
- Introduce the enableEventEmitterRetentionDuringGesturesOnAndroid to gate the Pressable fix (#45930) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45930 This introduce... — committed to facebook/react-native by cortinico 2 years ago
- Do not destroy views when there is a touch going on for New Architecture (#45865) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45865 This diff introduces the logic t... — committed to huntie/react-native by cortinico 2 years ago
- Quick print of feature flags definitions Summary: Changelog: [internal] Adding a new option for the feature flags script to print the current definitions of feature flags. ``` yarn featureflags --p... — committed to rubennorte/react-native by rubennorte 2 years ago
Thank you all for your patience.
The issue was caused by the event emitter getting destroyed when the view was going off-screen. This PR should fix it and will be shipped in 0.76:
Just a heads up that we found the root cause of this issue and we’re discussing a couple of potential fixes. See:
The issue described in #44643 is happening with plain pressable - no dynamic child (as shown in the reproducer). If the thing you described above fixes the issue, then these two issues are not related.
Adding another datapoint as I’m investigating. This definitely fixes the issue:
as the problem seems related to scenarios where
Pressablehave dynamic child.This also fixes the issue:
as there seems to be something going on with react reconciliation. Surprisingly this doens’t happen on iOS
Hey all, I’ve continued investigating here, and the issue is related to
Pressableitself and is unrelated to Expo.Reproducer for React Native Community CLI app that uses no libraries at all is here: https://github.com/reprodu/cer-react-native-44610
Also the issue is more evident on Android Physical devices as is more likely the
onPressInis followed by a finger movement. It can be reproduced on emulators if you click, move the cursor, and release the mouse.https://github.com/xdmx/rn-pressable-bug