fix: react-native-navigation integration #149
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📜 Description
Fixed an integration with
react-native-navigation
without hacks.💡 Motivation and Context
To overcome the initial problem I've decided to re-create callback between
onAttachedToWindow
/onDetachFromWindow
lifecycles. It improves the situation, but at some point of time you still may inconsistent values returned by hook and actual keyboard position.For me it seems like if the
WindowInsetsAnimationCompat.Callback
is attached to any parent view of the current screen (i. e.decorView
,rootView
, etc.), then it can be broken after some navigation cycles.This solution was inspired by Omelyan/RNNKeyboardController-Test@d5ee7ea. If we send events through overlay, then it's never broken. I had a look on a view hierarchy and realised, that overlays are not attached to parent views or to navigation tree:
I got an inspiration from this idea and decided to replicate this mechanism in native code. I've decided to attach a view as a child to
@id/action_bar_root
and setup callback on this view. In this case this view will not be a parent of navigation tree and will not be inside of navigation tree:However such approach didn't work out - it seems like if current view has
onAttachedToWindow
/onDetachedFromWindow
calls, then Keyboard insets detection in the end will be broken on API < 30.I've tried to remove this
eventView
inonDetachedFromWindow
and re-create it again inonAttachedToWindow
- and such combination worked out.Fixes #130
📢 Changelog
Android
onAttachedToWindow
;eventView
as a child of@id/action_bar_root
view (inonAttachedToWindow
);eventView
rather thanEdgeToEdgeReactViewGroup
(but still send events throughEdgeToEdgeReactViewGroup
id)removeSelf
toViewGroup
extensions;eventView
inonDetachedFromWindow
;inputMode
only if new mode is not equal to current one;Docs
README.md
;🤔 How Has This Been Tested?
Tested on Pixel 6 Pro (API 28), emulator.
📸 Screenshots (if appropriate):
Screen.Recording.2023-05-13.at.12.41.39.mov
📝 Checklist