camera-preview icon indicating copy to clipboard operation
camera-preview copied to clipboard

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

Open zangi-dev opened this issue 5 months ago • 0 comments

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/[email protected] 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?

zangi-dev avatar May 19 '25 16:05 zangi-dev