Skip to content

Switch focus to web view after opening camera preview - listeners problem #383

Description

@zangi-dev

Is your feature request related to a problem? Please describe.
I’m trying to take a picture using the volume buttons and I’m using the library @capacitor-community/volume-buttons@6.0.1 to capture the volume button events.

The issue is that the volume button listener doesn’t work immediately after opening the camera preview. It only starts working after I tap once on the screen. To work around this, I simulated a tap using the following code:

getBridge().getWebView().dispatchTouchEvent(
                                        MotionEvent.obtain(
                                          System.currentTimeMillis(),
                                          System.currentTimeMillis(),
                                          MotionEvent.ACTION_DOWN,
                                          0,
                                          0,
                                          0
                                        )
                                      );
getBridge().getWebView().dispatchTouchEvent(
                                        MotionEvent.obtain(
                                          System.currentTimeMillis(),
                                          System.currentTimeMillis(),
                                          MotionEvent.ACTION_UP,
                                          0,
                                          0,
                                          0
                                        )
                                      );

After this simulated tap, the volume listener works again.

Describe the solution you'd like
Ideally, the volume listener should work immediately after the camera preview is opened, without requiring a manual or simulated tap. I tried calling setFocus() and triggering clicks on UI elements, but those didn’t help — only an actual or simulated tap seems to restore the listener.

Do you know why this happens, or if there’s a way to ensure the WebView regains focus automatically?

Describe alternatives you've considered
Do you have suggestions about alternatives?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions