-
Notifications
You must be signed in to change notification settings - Fork 58
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
Fix List block handling on Android #928
Conversation
The Enter event (ReactAztecEnterEvent) will have the text that the RN side needs to process through the format-lib and hopefully match Aztec's processing.
@hypest I did a smoke test in iOS and the lists still working well there. |
I tested the cases in this comment: #898 (comment) and observed that this PR fixes the described issue. One caveat is that, while testing "Test B", the text remains after pressing [Enter] on step 4., but the bullet goes away (i.e. it does not create a new bullet). Screencast: |
start + before)); | ||
// if the "Enter" handling is underway, don't sent text change events. The ReactAztecEnterEvent will have | ||
// the text (minus the Enter char itself). | ||
if (mEditText.getText().getSpans(0, 0, EnterPressedUnderway.class).length == 0) { |
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.
Nitpick: What do you think about moving mEditText.getText().getSpans(0, 0, EnterPressedUnderway.class).length == 0
to a util method in EnterPressedUnderway
or AztecText
?
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.
Sounds good, will do 👍
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.
Done with 0417343.
Took me a while reviewing and checking the code on 3 repos, nice work here 🎉 I've followed the tests plan, and did other testing too, by using 3 different keyboards
I bet we should merged this ASAP, and let all the other people test the app since there are lot of changes in critical part of RichText+Aztec. |
I noticed a bug on develop where creating a new line in the middle of a list will not update the cursor position if there is styling lower down on the list (i.e. the cursor would remain at the end of the line before the newly-created line). On this PR branch though, it looks like the issue is fixed! 🎉 Develop (42d8443)PR (57c8de0) |
Thanks for reporting @mkevins , I've replicated that on my Pixel 2 XL. Will dig into it. |
Found a new issue: Tapping "Enter" from the virtual keyboard in an empty paragraph block creates a new block (OK) but leaves the originating block with an empty line in it. Will work on this. |
Fixed the garbage "Enter" key left in an empty paragraph with this commit: 897d272. |
Noticed that currently (04610cc), trying to use this PR with WPAndroid fails because the compiler complains that react-native-aztec has Java8 bytecode, instructing us to add:
to the build.gradle file. Doing that inside |
Looks like it's The magic of a fresh pair of eyes. 😄 |
Great eye @mchowning , thanks for looking into and spotting this! And of course, now I regret following AndroidStudio's hint to replace the interface implementation with the lambda 🤦♂️. |
I've tested cases A through E on APIs 27 and 24 (emulated Pixel 2 and Nexus 5, respectively) and everything is working as expected for those cases. I tested these cases with both the host keyboard and the emulated screen keyboard and observed the same behavior for each. A separate issue I observed while testing case C is that after splitting the list block with enter, and then pressing the undo button, the new paragraph block and second list block both disappear, and the caret moves back to the block preceding the first list block. The behavior I expected was that the list would return to its pre-split state. |
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.
Tested cases A through E on APIs 29 and 26.
Also run cut&paste and other writing flow tests on API29, everything worked as expected, and small issues or rendering glitches I found are also present on develop
.
Merging as chatted over Slack. |
Fixes #898 , #899 , #929
Companion PRs
Gutenberg: WordPress/gutenberg#15168
Aztec-Android: wordpress-mobile/AztecEditor-Android#812
This PR updates the way the "Enter" key is processed along with the general way changes from Aztec (Android) are updating the RN state without forcing them back to Aztec again.
Background
An Aztec-Android, the virtual keyboard has different behavior than external/hardware keyboards and the program flows through different code paths depending on whether it's the virtual keyboard or not. The key press from hardware keyboards is detected/intercepted before it changes the editor's text, the opposite happens on the virtual one. On the hardware keyboard, the event can be intercepted (and swallowed) upon detection, while on the virtual one the event will cause text change in Aztec. Then, virtual keyboards have a generally weird way to update the text, especially when auto-suggestions are enabled: a single key press may produce multiple "text-changed" events, each one with an intermediate state of the text change.
Changes
comesFromAztec
: A flag that signals whether a change initiated in Aztec, versus initiated by the RN app.firedAfterTextChanged
: A signal from Aztec to show when was the "Enter" key fired from the system. "Before text change" means it was fired from the hardware key listener, while "after" means it was from the virtual keyboard. If "before", Aztec will not process the "Enter" event so, no list processing will happen at that level. The format-lib will handle the list processing and so, RN needs to force the processed text into Aztec. On the contrary, If the event happened "after" the text change, the RN side just needs to update its internal model, without forcing anything to Aztec since Aztec will also process the event.ReactTextChangedEvent
andReactTextInputEvent
when the "Enter" key detection process is in progress in Aztec. We'll rely on theReactAztecEnterEvent
that will be sent and will have all the info we need, regarding text and caret. Introduced theEnterPressedUnderway
span class to mark text as still being processed for the "Enter" key detection.EnterPressedWatcher
TextWatcher (moved it here from the Aztec project) so we can specify that we need the watcher to remove theEnter
key when in an empty paragraph block. We don't specify that for the list block case because Aztec's list handling will remove theEnter
on the list end anyway.Test case A
Test case B
Test case C
Test case D
Test case E