New API for focused TextInputs #222
Closed
kirillzyusko
started this conversation in
Ideas
Replies: 1 comment
-
Closed as #257 was merged |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem?
Right now you can access
target
property and detect layout of focused input usingmeasure
function from Reanimated.However this approach has several downsides:
ShadowNode
and it adds more complexity to the code (and you need to usefindNodeHandle
which is deprecated in StrictMode);useKeyboardHandler
is not reporting such cases (and obviously it shouldn't);measure
on Fabric works differently and you need to take into consideration other UI elements (header height, etc.)Describe the solution you'd like
I'd like to have two hooks:
They will return a value with next shape:
These hooks should update its value before any keyboard lifecycle (
onStart
/onEnd
), and should update when:TextInput
to another;Describe alternatives you've considered
There is no known alternatives at the moment. You can use
TextInputState
andcurrentlyFocusedInput
- but it's available only in JS (not reanimated), it's not reactive (i. e. you can not detect a moment when layout was changed, etc.) - so overall it's not an alternative 🙂But everything above it's just rough idea. During the implementation it could be polish and adopted to real use cases.
Additional context
I think theoretically it shouldn't be too difficult to add such API. We can use the same approach as we used for
onKeyboardMoveStart
/onKeyboardMoveEnd
etc.But it would be good to move native implementation in separate files and don't mix it with current implementation.
Also we'll need to understand how to track layout changes on iOS. It seems like you can add KVO - but a lot of people don't recommend do that. Alternatively we can use the approach as used in IQKeyboardManager - we'll add a callback like
KeyboardController.onFocusedInputLayout(e)
and use this function inonLayout
of TextInputs <- but it'll require additional setup. Also if we decide to release this functionality using KVO - maybe worth to consider to release it under feature flags (because Interactive keyboard brought a lot of issues 😅).Overall I think suggested functionality can significantly enhance library capability and open new horizons 🚀
Beta Was this translation helpful? Give feedback.
All reactions