You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 9, 2026. It is now read-only.
Implement InputTextState-like focus sync mechanism for RCTAztecView #273
Unfortunately, InputTextState only knows about InputText and does not know about Aztec. As focus can only be held by one component at a time, we would (ideally) actually need to make TextInputState aware that Aztec is also something to take care of, so focus can be handled correctly (or build our own state-keeping for Aztec)
This cannot be done directly, as TextInputState only cares for RN's AndroidTextInput component in Android (iOS should apparently “just work” as it only keeps the node ID for it, without making a distinction of which class it is - we should verify nevertheless). For example, see focusTextInput() and blurTextInput() there in that class. This (only in part) explains why focus handling on iOS with the Aztec wrapper doesn't seem to be a problem.
Description of plan
The best way to go is to have something else that cares for both types of component (InputText and AztecText).
We also need Aztec to provide React Native with all methods for it to control its focus (work for this partially started in wordpress-mobile/react-native-aztec#75, replicating the API from RN InputText)
So current plan is: have a similarly built AztecState, and internally cascades back to TextInputState by usingTextInputState.currentlyFocusedField() and if there’s no “native” TextInput focused atm, looks into AztecState’s own state (otherwise, continue to run with the TextInputState implementation).
This way, ReactNative can keep working with focus for TextInput, and we would manage our own focus for AztecText components (and leave it up to the platform when we don’t have any focused items to take care of).
Keyboard show/hide works the same way: we should have a Keyboard.dismiss() of our own that does this check first, and be careful to always call our own method in our business logic (otherwise AztecText instances would not receive the signal to hide the keyboard). See related PR in #241, we should adapt these calls to use the new Gutenberg-focus manager that handles both state machines.
ToDo:
build InputTextState for Aztec
register components as they are added to the UI
build mechanism to first check focus on InputText, then fallback to Aztec
add needed methods in Aztec wrapper (RCTAztecView) to keep the same API
implement keyboard hide/show sync for all (cascade Aztec arrays first, and then run through InputTextState's implementation.
I don't fully understand the problem we're trying to solve or all the scenarios described, but I was looking at that code earlier this week for dismissing the keyboard, and I'm not sure all the assumptions are correct.
TextInputState is only aware of AndroidTextInput, but to the extent of knowing what commands to send to focus/blur. We just need to make sure that RCTAztecView is capable of taking the same commands.
Since I'm not clear about all the pieces, I couldn't test this properly (and I haven't tested on iOS), but with a couple simple changes, Aztec seems to be behaving as TextInput in terms of TextInputState focus/blur:
Since I'm not clear about all the pieces, I couldn't test this properly (and I haven't tested on iOS), but with a couple simple changes, Aztec seems to be behaving as TextInput in terms of TextInputState focus/blur:
I had made some changes to React Native Aztec yesterday (more or less your changes above, with few other additions). We need to update the ref in master. Doing it now, so we can all start from the same place.
with a couple simple changes, Aztec seems to be behaving as TextInput in terms of TextInputState focus/blur
I'd say "with a couple simple changes, Aztec seems to be behaving as TextInput in terms of TextInputState focus/blur" :D - the changes made there (what @daniloercoli mentioned in the comment above) are a step in that direction only, as what you're currently seeing is only adding the local behavior to show the keyboard when the Aztec instance gets the focus, as expressed in the approval note to that PR . There's no coordination between Aztec to other Aztec instances, and of course no Aztec-TextInput coordination.
TextInputState is only aware of AndroidTextInput, but to the extent of knowing what commands to send to focus/blur. We just need to make sure that RCTAztecView is capable of taking the same commands.
First sentence is correct, second one is not 😄 . Basically the first use case that this is needed for, is to be able to make the Keyboard.dismiss() for Aztec-based blocks. But, just adding the commands for blur and focus to Aztec RN wrapper does not ensure these will be called. The only place where these are called in RN's code is exactly in TextInputState, and only for "AndroidTextInput" components, so there's no way TextInputState would magically call our own Aztec's blur/focus methods whatsoever even if we call them the same and all. The point I'm trying to make is, that having the same API / action names will not bring us any magic. It needs to be wired.
Now, in order to wire it, we need to know which editable component has the focus currently. Which is essentially a thing that InputTextState takes care of :).
Hence, the trick they're using here (and which I think makes sense to replicate): is to keep a registry of all Aztec blocks and send them this signal if the keyboard needs be dismissed. The logic in Gutenberg (for the toolbar) will have to call either both implementations (RN's InputText's and ours) or we make one class that takes care for both, just for ease of use.
Hope it's clearer now, and thanks for asking! feel free to ask more questions as it enriches the ticket a lot
Side note as well: whether this is all considered an enhancement rather than something to fix for Alpha is not something I put in consideration. In terms of UX it's definitely a must have, but not up to me to decide if this is a minor issue we can live with for a first version.
Activity
koke commentedon Nov 23, 2018
I don't fully understand the problem we're trying to solve or all the scenarios described, but I was looking at that code earlier this week for dismissing the keyboard, and I'm not sure all the assumptions are correct.
TextInputStateis only aware ofAndroidTextInput, but to the extent of knowing what commands to send to focus/blur. We just need to make sure thatRCTAztecViewis capable of taking the same commands.Since I'm not clear about all the pieces, I couldn't test this properly (and I haven't tested on iOS), but with a couple simple changes, Aztec seems to be behaving as TextInput in terms of TextInputState focus/blur:
https://gist.github.com/koke/730187b6a89aefd814bda9eea61da523
Again, I don't fully understand what I'm doing here, but I'm hoping it's helpful.
daniloercoli commentedon Nov 23, 2018
I had made some changes to React Native Aztec yesterday (more or less your changes above, with few other additions). We need to update the ref in master. Doing it now, so we can all start from the same place.
mzorz commentedon Nov 23, 2018
I'd say "with a couple simple changes, Aztec seems to be behaving as TextInput in terms of
TextInputStatefocus/blur" :D - the changes made there (what @daniloercoli mentioned in the comment above) are a step in that direction only, as what you're currently seeing is only adding the local behavior to show the keyboard when the Aztec instance gets the focus, as expressed in the approval note to that PR . There's no coordination between Aztec to other Aztec instances, and of course no Aztec-TextInput coordination.First sentence is correct, second one is not 😄 . Basically the first use case that this is needed for, is to be able to make the
Keyboard.dismiss()for Aztec-based blocks. But, just adding the commands forblurandfocusto Aztec RN wrapper does not ensure these will be called. The only place where these are called in RN's code is exactly in TextInputState, and only for "AndroidTextInput" components, so there's no way TextInputState would magically call our own Aztec's blur/focus methods whatsoever even if we call them the same and all. The point I'm trying to make is, that having the same API / action names will not bring us any magic. It needs to be wired.Now, in order to wire it, we need to know which editable component has the focus currently. Which is essentially a thing that
InputTextStatetakes care of :).Hence, the trick they're using here (and which I think makes sense to replicate): is to keep a registry of all Aztec blocks and send them this signal if the keyboard needs be dismissed. The logic in Gutenberg (for the toolbar) will have to call either both implementations (RN's InputText's and ours) or we make one class that takes care for both, just for ease of use.
Hope it's clearer now, and thanks for asking! feel free to ask more questions as it enriches the ticket a lot
Side note as well: whether this is all considered an enhancement rather than something to fix for Alpha is not something I put in consideration. In terms of UX it's definitely a must have, but not up to me to decide if this is a minor issue we can live with for a first version.
mzorz commentedon Nov 28, 2018
Closing for now, as #282 brings in the minimum updates necessary by using
TextInputState'sfocusandbluron Aztec wrapper nodes as well