From 7822b9cce2233db00b26eeab8a04e4812d0468b3 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Mon, 5 Oct 2026 14:42:14 +0100 Subject: [PATCH] Properly enable Pressable after disabled prop reset (#58799) Summary: JSI drops `undefined` keys, so reseting `disabled` from `true` to `undefined` on Touchables/Pressables never runs `setEnabled(true)` There is props diffing feature flag that fixes this, which is off by default Also added safety check against explicit `null` & reset on recycling Fixes https://github.com/react/react-native/issues/56777 and supersedes https://github.com/react/react-native/issues/58795 ## Changelog: [ANDROID] [FIXED] - Properly enable Pressable after `disabled` prop resets from `true` Pull Request resolved: https://github.com/react/react-native/pull/58799 Test Plan: Added BaseViewManagerTest as well as videos of testing it on Pressable: https://github.com/user-attachments/assets/e9a7dcd2-46d5-4cdc-88a3-728bff22e76b https://github.com/user-attachments/assets/043150ae-64f2-47c9-b13c-abfec5b61747 Reviewed By: javache Differential Revision: D122872380 Pulled By: zeyap fbshipit-source-id: f3f1cad378f36f006bbb6c7f3f2e4f9aa8e61541 (cherry picked from commit 357b6998c4df940f2450448a20478b11deaf741b) --- .../react/uimanager/BaseViewManager.java | 18 ++++++- .../main/res/views/uimanager/values/ids.xml | 3 ++ .../react/uimanager/BaseViewManagerTest.kt | 32 +++++++++++ .../js/examples/Pressable/PressableExample.js | 53 +++++++++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index d2747ebda57..c78d3151219 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -88,6 +88,8 @@ public abstract class BaseViewManager + + + diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt index 8915d91903a..95e47b23e9a 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt @@ -71,6 +71,38 @@ class BaseViewManagerTest { Assertions.assertThat(view.isSelected).isEqualTo(true) } + @Test + fun testAccessibilityStateDisabledRemovedReenablesView() { + viewManager.setViewState(view, JavaOnlyMap.of("disabled", true)) + Assertions.assertThat(view.isEnabled).isFalse() + + viewManager.setViewState(view, JavaOnlyMap()) + Assertions.assertThat(view.isEnabled).isTrue() + } + + @Test + fun testAccessibilityStateNullReenablesView() { + viewManager.setViewState(view, JavaOnlyMap.of("disabled", true)) + viewManager.setViewState(view, null) + Assertions.assertThat(view.isEnabled).isTrue() + } + + @Test + fun testAccessibilityStateDisabledNullDoesNotCrash() { + viewManager.setViewState(view, JavaOnlyMap.of("disabled", true)) + viewManager.setViewState(view, JavaOnlyMap.of("disabled", null)) + Assertions.assertThat(view.isEnabled).isTrue() + } + + @Test + fun testAccessibilityStateWithoutDisabledKeepsViewDisabledByOtherProps() { + view.isEnabled = false + viewManager.setViewState(view, JavaOnlyMap()) + Assertions.assertThat(view.isEnabled).isFalse() + viewManager.setViewState(view, null) + Assertions.assertThat(view.isEnabled).isFalse() + } + @Test fun testRoleList() { viewManager.setRole(view, "list") diff --git a/packages/rn-tester/js/examples/Pressable/PressableExample.js b/packages/rn-tester/js/examples/Pressable/PressableExample.js index b52f9f9ba05..fc7ba7bb800 100644 --- a/packages/rn-tester/js/examples/Pressable/PressableExample.js +++ b/packages/rn-tester/js/examples/Pressable/PressableExample.js @@ -255,7 +255,17 @@ function PressableNativeMethods() { ); } +const DISABLED_OPTIONS: Array<{label: string, value: ?boolean}> = [ + {label: 'true', value: true}, + {label: 'false', value: false}, + {label: 'undefined', value: undefined}, + {label: 'null', value: null}, +]; + function PressableDisabled() { + const [disabled, setDisabled] = useState(true); + const [timesPressed, setTimesPressed] = useState(0); + return ( <> @@ -271,6 +281,33 @@ function PressableDisabled() { ]}> Enabled Pressable + + + {DISABLED_OPTIONS.map(option => ( + setDisabled(option.value)} + style={[ + styles.disabledOption, + disabled === option.value && styles.disabledOptionSelected, + ]}> + {option.label} + + ))} + + setTimesPressed(current => current + 1)} + style={({pressed}) => [ + {opacity: pressed ? 0.5 : 1}, + styles.row, + styles.block, + styles.disabledToggleTarget, + ]}> + + {`disabled={${String(disabled)}}`} pressed {timesPressed} times + + ); } @@ -296,6 +333,22 @@ const styles = StyleSheet.create({ color: '#007AFF', opacity: 0.5, }, + disabledOption: { + paddingHorizontal: 8, + paddingVertical: 4, + marginHorizontal: 4, + borderRadius: 4, + borderWidth: StyleSheet.hairlineWidth, + borderColor: '#007AFF', + }, + disabledOptionSelected: { + backgroundColor: '#cce4ff', + }, + disabledToggleTarget: { + padding: 20, + borderWidth: StyleSheet.hairlineWidth, + borderColor: '#007AFF', + }, hitSlopButton: { color: 'white', },