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

Unfocus fixed except for scroll containers #12290

Closed
taz4270 opened this issue Dec 23, 2022 · 1 comment
Closed

Unfocus fixed except for scroll containers #12290

taz4270 opened this issue Dec 23, 2022 · 1 comment
Labels
platform/android 🤖 t/bug Something isn't working

Comments

@taz4270
Copy link

taz4270 commented Dec 23, 2022

Description

Right now if you create an entry and try to unfocus by clicking somewhere else it will not work and the same entry will be focused, even if you hide the keyboard...
I found the problem and fixed bug with some bugs.
All I did was add a focus observer and touch observer on the MainActivity simple as that

protected override void OnCreate(Bundle savedInstanceState)
        {            
            base.OnCreate(savedInstanceState);

            Window.DecorView.ViewTreeObserver.GlobalFocusChange += FocusChanged;
        }

private void FocusChanged(object sender, ViewTreeObserver.GlobalFocusChangeEventArgs e)
        {

            if (e.NewFocus is null && e.OldFocus is not null)
            {
                InputMethodManager imm = InputMethodManager.FromContext(this);

                IBinder wt = e.OldFocus.WindowToken;

                if (imm is null || wt is null)
                    return;

                imm.HideSoftInputFromWindow(wt, HideSoftInputFlags.None);
            }
        }

public override bool OnTouchEvent(MotionEvent e)
        {
            if (CurrentFocus is not null)
                CurrentFocus.ClearFocus();

            return base.OnTouchEvent(e);
        }

but even so some views refuse to talk to OnTouchEvent, such as ScrollView or CollectionView somewhere on the code they are consuming the touch event and wont let it get to the unfocus happen
Also, this focus will remove the keyboard if has no more focus

Steps to Reproduce

  1. Create a list of views/entries/any focusable views and put it on the scrollView
  2. focus one
  3. try to unfocus without focusing on others focusables 🐞

Expected: Fire the OnTouchEvent in the MainActivity so could use the logic above
Outcome: Doesnt Fire the OnTouchEvent, not even on the ScrollView

Link to public reproduction project repository

https://github.com/taz4270/ScrollNFocus-Example

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

No response

Relevant log output

No response

@taz4270 taz4270 added the t/bug Something isn't working label Dec 23, 2022
@PureWeen
Copy link
Member

Duplicate of ##12002

@PureWeen PureWeen closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants