-
-
Notifications
You must be signed in to change notification settings - Fork 600
fix(Android): fix formSheet not adjusting for keyboard when it contains input with autofocus #2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2dda31a to
b78afc5
Compare
kkafar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it improves the situation, however, I'm not convinced taht onPrepare is good palce to do so. My initial impression is that registering observer proxy in onAttachedToWindow would make more sense. Can you check, whether it's feasible timing-wise to do so?
android/src/main/java/com/swmansion/rnscreens/ScreenStackFragment.kt
Outdated
Show resolved
Hide resolved
kligarski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onAttachedToWindow works as well.
kkafar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answering your question here.
| // This code currently does not work (changing maxHeight requires relayout) | ||
| // but it creates visual glitch when closing formSheet with keyboard still open. | ||
| // Decided to temporarily comment it out. | ||
| // More details: https://github.com/software-mansion/react-native-screens/pull/2911 | ||
|
|
||
| // val newMaxHeight = | ||
| // if (behavior.maxHeight - keyboardState.height > 1) { | ||
| // behavior.maxHeight - keyboardState.height | ||
| // } else { | ||
| // behavior.maxHeight | ||
| // } | ||
|
|
||
| val newMaxHeight = behavior.maxHeight | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to comment out this part because it does not work currently (even before this PR, sheet would extend to previous maxHeight) but it causes visual glitch when closing the formSheet.
| Before | After |
|---|---|
with_newMaxHeight.mp4 |
without_newMaxHeight.mp4 |
kkafar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see one issue, however: you say that we can rely on WindowInsetsAnimationCallback. I say: it is supported since API level 30, while min sdk is lower than that. How does the current apporach look on e.g. SDK 29?
android/src/main/java/com/swmansion/rnscreens/bottomsheet/SheetDelegate.kt
Outdated
Show resolved
Hide resolved
As we're using static void setCallback(@NonNull View view, @Nullable Callback callback) {
if (Build.VERSION.SDK_INT >= 30) {
Impl30.setCallback(view, callback);
} else if (Build.VERSION.SDK_INT >= 21) {
Impl21.setCallback(view, callback);
}
// Do nothing pre 21
}But I now noticed that in the docs, there is a note about using API < 30:
I'll try to make sure that everything works on API < 30 as well, because we're sometimes overriding |
|
With api_29.mov |
kkafar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once #2925 (comment) this is answered we can proceed
kkafar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now!
Description
Sometimes, formSheet that contains input with autoFocus would not account for the keyboard and would remain behind it. This is because
SheetDelegateis set as aOnApplyWindowInsetsListenerwhen fragment is resumed - this happens after finishing formSheet entering animations (animators impact fragment lifecycle). Sometimes, IME insets were applied before this handler was set. Now, we can useWindowInsetsAnimationCallbackadded in this PR. ItsonPreparemethod is called beforeonApplyWindowInsetstherefore making it possible to setOnApplyWindowInsetsListenerin time.Changes
insetsObserverProxy'slistenerstoHashSet(we might try to add the same listener multiple times)onPreparemethod inWindowInsetsAnimationCallbackSheetDelegatetointernalTest code and steps to reproduce
Open
Test2895screen in the example app, open & close the formSheet (multiple times).Checklist