Commit e979dbf
authored
fix: don't modify edge-to-edge mode by default when module toggled on/off (#1412)
## 📜 Description
Don't hook up in insets calculation since it infers with many other
libraries (such as `react-native-screens`,
`react-native-safe-area-context` and other native libs such as
[RevenueCat
paywalls](https://www.revenuecat.com/docs/tools/paywalls/displaying-paywalls)).
## 💡 Motivation and Context
Original code has been introduced in
#227
The idea was simple - to use this library we need:
- enable edge-to-edge;
- set keyboard callbacks;
So when we turn off functionality we need:
- disable edge-to-edge;
- remove keyboard callbacks.
However there was one problem - when we were disabling edge-to-edge we
saw a visual jump:
https://github.com/user-attachments/assets/f4880cce-14b7-495e-ac9f-25e39a80650a
That was caused by `@react-navigation/stack` +
`react-native-safe-area-context`. The `react-native-safe-area-context`
was emitting "wrong" events (we expected `0` insets):
<img width="161" height="28" alt="Image"
src="https://github.com/user-attachments/assets/7598f932-503e-4e89-ba24-b2c1458e821d"
/>
This is why I added a code with nulling insets. However it opens new
issues like
#1292
or
#1013
In this PR I'm revisiting the implementation and I do one small trick:
now we will not toggle `edge-to-edge` mode (in Android 16 it's enabled
by default anyway without ability to turn it off) - instead we'll apply
bottom padding/margin when keyboard appears (only when module turned off
and input mode=resize, since resize + edge-to-edge acts as a
adjustNothing). Yes, this is effectively a simulation of
pre-edge-to-edge behavior and this simulation may not work everywhere
perfectly (for example Android 16 would act differently before, since
edge-to-edge is not disableable and even if you turn off the mode the
keyboard wouldn't resize the window - with this solution it will, but at
the same it bring consistency and reduces API fragmentation which is
also good).
I don't think this is a breaking change, so it can be published as a
patch release 🤞
Closes
#1292
#1013
Possibly
#1179
#1192
## 📢 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
- removed `replaceStatusBarInsets`;
- created extension for `windowSoftInputMode`;
- use `windowSoftInputMode` extension in `KeyboardControllerModuleImpl`
file;
- don't `replaceStatusBarInsets` in global
`setOnApplyWindowInsetsListener(rootView)`;
- don't disable `edge-to-edge` mode;
- apply bottom padding if module disabled and `ADJUST_RESIZE` mode is
active and `preserveEdgeToEdge` is `false`;
## 🤔 How Has This Been Tested?
Tested manually on Pixel 7 Pro (API 36).
## 📸 Screenshots (if appropriate):
|Before|After|
|-------|-----|
|<img width="1080" height="2400" alt="image"
src="https://github.com/user-attachments/assets/e09b0d80-8eac-47e3-a36a-8cf92ac9bde1"
/>|<img width="1080" height="2400" alt="image"
src="https://github.com/user-attachments/assets/f1f2937f-bdec-4f74-86f1-b3f256a5655c"
/>|
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed1 parent 86d8e27 commit e979dbf
4 files changed
Lines changed: 32 additions & 73 deletions
File tree
- android/src/main/java/com/reactnativekeyboardcontroller
- extensions
- modules
- views
Lines changed: 10 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 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
Lines changed: 0 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
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 | | - | |
Lines changed: 3 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 116 | | |
125 | 117 | | |
126 | 118 | | |
| |||
Lines changed: 19 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
114 | | - | |
| 114 | + | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
| 118 | + | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
120 | | - | |
| 123 | + | |
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
124 | 127 | | |
125 | 128 | | |
126 | | - | |
127 | | - | |
| 129 | + | |
| 130 | + | |
128 | 131 | | |
129 | | - | |
| 132 | + | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
134 | | - | |
| 137 | + | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
153 | 148 | | |
| 149 | + | |
| 150 | + | |
154 | 151 | | |
155 | 152 | | |
156 | 153 | | |
| |||
0 commit comments