Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Fix UBE Text Selection Bug on Android (#34668)
* Load new custom JS file in UBE With this commit, a new JS file is loaded in 'GutenbergWebViewActivity.java'. This new file will have our custom JS, which will load when the UBE is open. * Detect when dropdown menus are active An event listener is added as part of this commit, which will listen for changes in focus in the UBE. In addition, an if statement that checks for the specific elements we're interested in (the toolbars dropdown menus) has been added. This if statement will be fleshed out in future commits. * Remove toolbar by resetting text selection The text selection is reset by utilising JavaScript's setBaseAndExtent' method. This has the effect of removing the text selection toolbar when a dropdown menu is pressed, while maintaining the original selection. See here for more details on setBaseAndExtent: https://developer.mozilla.org/en-US/docs/Web/API/Selection/setBaseAndExtent * Rename 'custom-js' file for clarity This PR renames the 'custom-js' file to 'editor-behavior-overrides.js' in an attempt to clarify its purpose. * Add clarifying comment to new JS file As this is a somewhat hacky and unintuitive fix, this commit adds a clarifying comment along with a link back to the PR for more details. * Improve if/else logic by adding 'selected' check The if/else statement was only checking whether specific buttons were active before resetting the text selection. With this commit, an extra check for whether text is actually selected has been added. The code for resetting the selection will therefore only be run when necessary (i.e. it's not necessary if there's no selection). * Access 'activeElement' via 'document' With this commit, changes are made to access the 'activeElement' via 'document', rather than 'window'. Accessing directly via 'window' was not working as expected. It was necessary to still reference 'window' to bypass lint errors. * Add back 'activeElement' selector This was accidentally removed with the last commit. * Update CHANGELOG * Notify Android code when certain menus are tapped Previously the selected text was reset on the JavaScript side of the codebase (using the 'setBaseAndExtent' method). This commit refactors the code so that the Android side of the codebase is notified instead, via the newly created 'hideTextSelectionContextMenu' method. The aim here is to make use of Android's built-in functions around ActionMode, in order to make the code and functionality more stable. * Update comment to clarify new code changes * Hide text selection toolbar when selecting certain items This commit taps into Android's ActionMode to hide the text selection toolbar whenever the 'hideTextSelectionContextMenu' function is called. More specficially, it uses the 'finish' method: https://developer.android.com/reference/android/view/ActionMode#finish() * Add missing variable I accidentally ommitted the 'mActionMode' variable from previous commits. * Add listener for hide text selection context menu event * Listen to click events instead of focus * Add click listeners for context menu visibility * Remove commented line Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
- Loading branch information