Skip to content
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 keyboard crashes in BrowserFragment #5033

Merged
merged 6 commits into from
Sep 19, 2024

Conversation

mikescamell
Copy link
Contributor

@mikescamell mikescamell commented Sep 18, 2024

Task/Issue URL: https://app.asana.com/0/414730916066338/1208339084893367/f

Description

We saw some keyboard crashes due to some recent refactoring of the Omnibar.

The Omnibar was previously solely bound in onActivityCreated.

It was never nulled out in onDestroyView so the Fragment held on to it, and when the delay concluded it would happily try to call show/hideKeyboard using the Omnibar without issue.

Now, we’re using the FragmentViewBindingDelegate for the Omnibar, which gets nulled out in onDestroy, so when the delay concluded we tried calling show/hideKeyboard on a null object.

To fix this we’re introducing new extension functions that follow the recommended way to show and hide the keyboard.

Steps to test this PR

Run the following tests locally they should all pass

  • whenProtectionsAreDisabledRequestAreNotBlocked
  • whenProtectionsAreDisabledSurrogatesAreNotLoaded
  • whenProtectionsAreEnabledHttpsUpgradedCorrectly
  • whenProtectionsAreEnabledRequestBlockedCorrectly
  • whenProtectionsAreEnabledSurrogatesAreLoaded
  • whenProtectionsAreFingerprintProtected

Omnibar Keyboard

  • Ensure keyboard shows when opening app with New Tab Page
  • Generally play around with the Omnibar EditText and ensure keyboard is shown and hidden where appropriate

UI changes

N/A

This is the new recommended way to show and hide the keyboard according to the documentation: https://developer.android.com/develop/ui/views/touch-and-input/keyboard-input/visibility#ShowReliably

Quote:

- (Recommended) Use WindowInsetsControllerCompat. This object displays the soft keyboard during Activity.onCreate() as shown in the following code snippet. The call is guaranteed to be scheduled after the window is focused.

We decided to enforce the view passed as an EditText as we couldn't imagine a reason for any other type as of now.
We're only changing the functions we saw break right now. We'll follow up with a task to look into other places where we show/hide the keyboard
We should discourage the use of the the extension functions that probably are not reliable in favour of our new extension functions
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @mikescamell and the rest of your teammates on Graphite Graphite

@mikescamell mikescamell marked this pull request as ready for review September 18, 2024 16:35
@joshliebe joshliebe self-assigned this Sep 18, 2024
Copy link
Contributor

@malmstein malmstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this it’s removing the outline of the Omnibar.

Copy link
Contributor

@malmstein malmstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I let you agree with @joshliebe in the outstanding question, but I don’t consider that a blocker.

Copy link
Contributor

@joshliebe joshliebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m gonna have to disagree with @malmstein on this one, blocking on: #5033 (comment)

Copy link
Contributor

@joshliebe joshliebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good but we still have failing tests:
Screenshot 2024-09-19 at 13 10 50

It’s hard for me to know if it’s related to this because I can’t check on develop, since these tests are failing with the lifecycle issue:
Screenshot 2024-09-19 at 13 09 29

Copy link
Contributor

@malmstein malmstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Copy link
Contributor

@joshliebe joshliebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current issues seem to be unrelated to this PR, thanks for fixing this 👍🙂

@mikescamell mikescamell merged commit 7acbc31 into develop Sep 19, 2024
14 checks passed
@mikescamell mikescamell deleted the fix/mike/browser-keyboard-crashes branch September 19, 2024 14:05
cmonfortep added a commit that referenced this pull request Sep 26, 2024
Task/Issue URL: https://app.asana.com/0/1202552961248957/1208407851630430/f

### Description
After we did #5033 the omnibar is taking focus more than usual, triggering onFocus changes in some unexpected scenarios (e.g: if we send the app to background, etc.)

After taking a look, the logic to show/hide keyboard was changed, and we now, for both methods, execute `editText.requestFocus()`. That seems correct for showing, but unsure for hiding. 

### Steps to test this PR

_Feature 1_
- just smoke test

### UI changes
| Before  | After |
| ------ | ----- |
!(Upload before screenshot)|(Upload after screenshot)|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants