Commit 4a6c933
Fix Keyboard events and KeyboardAvoidingView on Android (edge-to-edge) (#55855)
Summary:
`KeyboardAvoidingView` has several issues on Android 15+ and when `edgeToEdgeEnabled` is set to `true` on Android < 15:
1. **Keyboard events relied on a legacy detection path for Android < 30** (`checkForKeyboardEventsLegacy`), which used height heuristics (`heightDiff > mMinKeyboardHeightDetected`) to guess whether the keyboard was visible.
2. **`keyboardDidHide` reported incorrect `screenY` values.** It used `mVisibleViewArea.height()`, which in edge-to-edge mode doesn't correspond to the actual screen bottom.
3. **`KeyboardAvoidingView` used `_onKeyboardChange` for `keyboardDidHide` on Android**, which stores the event instead of nullifying it. After keyboard dismissal, any subsequent `onLayout` would re-enter `_updateBottomIfNecessary` with stale coordinates, causing a render loop (especially visible with `behavior="height"` in edge-to-edge mode, where `frame.y` shifts slightly on each layout cycle).
This PR:
- Removes `checkForKeyboardEventsLegacy` and uses `WindowInsetsCompat` APIs (via AndroidX)
- Fixes `keyboardDidHide` to report `screenY` as `mVisibleViewArea.bottom + barInsets.bottom`
- Fixes the Android `keyboardDidHide` listener in `KeyboardAvoidingView` to use `_onKeyboardHide`, matching the iOS behavior and breaking the render loop.
Closes #49759
## Changelog:
[ANDROID] [FIXED] - Fix `KeyboardAvoidingView` on Android 15+ / with `edgeToEdgeEnabled`
Pull Request resolved: #55855
Test Plan:
Tested with `rn-tester` KeyboardAvoidingView example on:
- Android 16 (API 36) (edge-to-edge is enforced)
- Android 14 (API 34) with `edgeToEdgeEnabled` set to `true` or `false`
- Android 7 (API 24) with `edgeToEdgeEnabled` set to `true` or `false`
For each, verified:
- `behavior="padding"`: keyboard open/close adjusts padding correctly
- `behavior="position"`: keyboard open/close translates content correctly
- `behavior="height"`: keyboard open/close works without render loop or glitching
- `keyboardDidShow` and `keyboardDidHide` events report correct coordinates
Reviewed By: mdvacca
Differential Revision: D100437445
Pulled By: alanleedev
fbshipit-source-id: 23b89a4380d02a0f524d587f89d023d21782406c1 parent a8d44bc commit 4a6c933
File tree
2 files changed
+11
-73
lines changed- packages/react-native
- Libraries/Components/Keyboard
- ReactAndroid/src/main/java/com/facebook/react
2 files changed
+11
-73
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| |||
Lines changed: 10 additions & 72 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | 27 | | |
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
35 | | - | |
36 | 33 | | |
37 | 34 | | |
38 | 35 | | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
801 | 800 | | |
802 | 801 | | |
803 | 802 | | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
| 803 | + | |
809 | 804 | | |
810 | 805 | | |
811 | 806 | | |
| |||
934 | 929 | | |
935 | 930 | | |
936 | 931 | | |
937 | | - | |
938 | 932 | | |
939 | 933 | | |
940 | | - | |
941 | 934 | | |
942 | 935 | | |
943 | 936 | | |
944 | 937 | | |
945 | 938 | | |
946 | | - | |
947 | 939 | | |
948 | 940 | | |
949 | 941 | | |
| |||
952 | 944 | | |
953 | 945 | | |
954 | 946 | | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
| 947 | + | |
961 | 948 | | |
962 | 949 | | |
963 | 950 | | |
964 | 951 | | |
965 | | - | |
966 | 952 | | |
967 | 953 | | |
968 | | - | |
| 954 | + | |
969 | 955 | | |
970 | 956 | | |
971 | 957 | | |
972 | 958 | | |
973 | | - | |
| 959 | + | |
974 | 960 | | |
975 | 961 | | |
| 962 | + | |
976 | 963 | | |
977 | 964 | | |
978 | | - | |
979 | | - | |
| 965 | + | |
980 | 966 | | |
981 | 967 | | |
982 | 968 | | |
| |||
999 | 985 | | |
1000 | 986 | | |
1001 | 987 | | |
1002 | | - | |
| 988 | + | |
1003 | 989 | | |
1004 | 990 | | |
1005 | 991 | | |
1006 | 992 | | |
1007 | 993 | | |
1008 | 994 | | |
1009 | 995 | | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | 996 | | |
1059 | 997 | | |
1060 | 998 | | |
| |||
0 commit comments