Commit ba2e187
authored
fix: keep shadow nodes in sync (#950)
## 📜 Description
Fixed a problem when `Pressable` doesn't trigger `onPress` callback if
it's located in `KeyboardStickyView` (`KeyboardToolbar`).
## 💡 Motivation and Context
The problem stems from the fact that C++ shadow nodes do not know about
changes caused by `useKeyboardAnimation` hook (we drive animation by
native driver, so C++ thinks that view hasn't changed its position).
I found out that `ScrollView` had the same problem:
facebook/react-native#36504 (comment)
Basically the fix is next:
- after finishing the animation we dispatch
`onUserDrivenAnimationEnded`;
- in `useAnimatedProps`:
```ts
NativeAnimatedHelper.nativeEventEmitter.addListener(
'onUserDrivenAnimationEnded',
data => {
node.update();
},
);
```
Where:
```ts
new AnimatedProps(
props,
() => onUpdateRef.current?.(),
allowlistIfEnabled,
),
```
Which in turns calls:
```ts
const isFabricNode = isFabricInstance(instance);
if (node.__isNative) {
// Check 2: this is an animation driven by native.
// In native driven animations, this callback is only called once the animation completes.
if (isFabricNode) {
// Call `scheduleUpdate` to synchronise Fiber and Shadow tree.
// Must not be called in Paper.
scheduleUpdate();
}
return;
}
```
And it triggers re-render and synchronizes C++ state with latest react
state.
Probably not the best solution, but it fixes the problem. Also we have
to gather all connected nodes that depends on animated value, but at the
moment this data is unused:
```ts
data => {
node.update();
},
```
So for now it's safe to skip connected nodes 🙃 (maybe later I'll revisit
this)
Closes
#947
#916
#588
## 📢 Changelog
<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->
### Android
- added `keepShadowNodesInSync` function extension for
`ThemedReactContext`;
- call `keepShadowNodesInSync` in the end of keyboard animation.
## 🤔 How Has This Been Tested?
Tested manually in FabricExample.
## 📸 Screenshots (if appropriate):
|KeyboardStickyView|KeyboardToolbar|
|---------------------|----------------|
|<video
src="https://github.com/user-attachments/assets/3950ec69-338e-4f2e-9301-b5c64efb808e">|<video
src="https://github.com/user-attachments/assets/291e846e-3bf8-46fd-9f64-d53ec30c452b">|
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed1 parent be7ef24 commit ba2e187
4 files changed
Lines changed: 28 additions & 4 deletions
File tree
- android/src/main/java/com/reactnativekeyboardcontroller
- extensions
- listeners
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
40 | 60 | | |
41 | 61 | | |
42 | 62 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| 331 | + | |
| 332 | + | |
330 | 333 | | |
331 | 334 | | |
332 | 335 | | |
| |||
401 | 404 | | |
402 | 405 | | |
403 | 406 | | |
| 407 | + | |
404 | 408 | | |
405 | 409 | | |
406 | 410 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
0 commit comments