Commit d194d8b
Stop remounting the app when toggling Touchables in the Element Inspector (#58705)
Summary:
Pressing **Touchables** in the Element Inspector remounts the whole app. All component state is lost, including navigation state, so the app jumps back to its first screen, away from the screen whose press targets you wanted to see. While Inspect is on, touches are intercepted, so you can't navigate back either.
The remount is how the toggle is applied. `PressabilityDebug` keeps the flag in a module variable that React can't observe, so `Inspector` asks `AppContainer` to change the `key` of the root view:
```js
const setTouchTargeting = (val: boolean) => {
PressabilityDebug.setEnabled(val);
onRequestRerenderApp(); // AppContainer: setKey(k => k + 1)
};
```
This has been in place since d5c1de7 (2016). The only related report I found, #26354, was closed with a workaround.
This change:
- makes `PressabilityDebug` notify subscribers when the flag changes, and adds `useIsEnabled()`, which reads it with `useSyncExternalStore`
- uses it in `PressabilityDebugView`, which `Pressable` and every `Touchable*` already render in `__DEV__`, so those components don't change
- moves the magenta color of pressable `Text` into `PressableText` / `PressableVirtualText`, so `Text` that isn't pressable gets no extra hook
- uses it in the Inspector panel for the state of the Touchables button
- removes `onRequestRerenderApp`, and the root `key` in `AppContainer` that only existed for it
In production `useIsEnabled` is `isEnabled`, so no hooks are added. No public API changes.
One difference: `Text` with both `onPress` and `disabled` no longer turns magenta, since it isn't pressable.
## Changelog:
[GENERAL] [FIXED] - Toggling Touchables in the Element Inspector no longer remounts the app and resets its state
Pull Request resolved: #58705
Test Plan:
| Before | After |
| --- | --- |
| <video src="https://github.com/user-attachments/assets/bb8b819b-256d-4ecf-9504-da974af3ad31" width="260"></video> | <video src="https://github.com/user-attachments/assets/23048e00-e252-467b-85d6-9503cfd10e56" width="260"></video> |
Before, the app remounts and goes back to its first screen. After, it stays on the screen and the press targets are outlined. Recorded in an Expo SDK 57 app (React Native 0.86.3, New Architecture) with this change applied as a patch: open a screen other than the first one, then Dev Menu → Toggle Element Inspector → **Touchables**.
The new Fantom test `PressabilityDebug-itest.js` checks that the press target outline appears and disappears without remounting, that pressable `Text` (top-level and nested) turns magenta, and that disabled `Text` does not. All four tests fail without this change.
- `yarn fantom PressabilityDebug-itest` → 4 passed
- `yarn fantom` → 182 suites passed, 22 skipped, 0 failed
- `yarn test packages/react-native` → 146 suites, 5232 tests passed
- `yarn flow-check` → 0 errors
- `yarn lint`, `yarn format-check-javascript` → clean
- `yarn build-types` → `ReactNativeApi.d.ts` unchanged
Reviewed By: javache
Differential Revision: D122144366
Pulled By: fabriziocucci
fbshipit-source-id: 8e6a204a7ca3814ad0a34d09211f7e27985f7b341 parent f1d97ff commit d194d8b
5 files changed
Lines changed: 196 additions & 22 deletions
File tree
- packages/react-native
- Libraries
- Pressability
- __tests__
- ReactNative
- Text
Lines changed: 27 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
83 | 88 | | |
| 89 | + | |
84 | 90 | | |
85 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
Lines changed: 137 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
Lines changed: 1 addition & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | | - | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
| |||
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
75 | | - | |
76 | 73 | | |
77 | 74 | | |
78 | 75 | | |
| |||
118 | 115 | | |
119 | 116 | | |
120 | 117 | | |
121 | | - | |
122 | 118 | | |
123 | 119 | | |
124 | 120 | | |
| |||
157 | 153 | | |
158 | 154 | | |
159 | 155 | | |
160 | | - | |
161 | 156 | | |
162 | 157 | | |
163 | 158 | | |
| |||
172 | 167 | | |
173 | 168 | | |
174 | 169 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | 170 | | |
181 | 171 | | |
182 | 172 | | |
| |||
198 | 188 | | |
199 | 189 | | |
200 | 190 | | |
201 | | - | |
202 | 191 | | |
203 | 192 | | |
204 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | 169 | | |
175 | 170 | | |
176 | 171 | | |
| |||
471 | 466 | | |
472 | 467 | | |
473 | 468 | | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
474 | 487 | | |
475 | 488 | | |
476 | 489 | | |
| |||
485 | 498 | | |
486 | 499 | | |
487 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
488 | 505 | | |
489 | 506 | | |
490 | 507 | | |
491 | 508 | | |
| 509 | + | |
492 | 510 | | |
493 | 511 | | |
494 | 512 | | |
| |||
513 | 531 | | |
514 | 532 | | |
515 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
516 | 539 | | |
517 | 540 | | |
518 | 541 | | |
519 | 542 | | |
520 | 543 | | |
521 | 544 | | |
| 545 | + | |
522 | 546 | | |
523 | 547 | | |
524 | 548 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
| |||
79 | 77 | | |
80 | 78 | | |
81 | 79 | | |
| 80 | + | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
160 | 159 | | |
161 | 160 | | |
162 | 161 | | |
163 | | - | |
164 | 162 | | |
165 | 163 | | |
166 | 164 | | |
| |||
188 | 186 | | |
189 | 187 | | |
190 | 188 | | |
191 | | - | |
| 189 | + | |
192 | 190 | | |
193 | 191 | | |
194 | 192 | | |
| |||
0 commit comments