capacitor-community / capacitor-community/camera-preview
Switch focus to web view after opening camera preview - listeners problem
- Dominant language
- Java
- Stars
- 227
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Description
**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:
```java
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?
Contributor guide
Assessment
This issue has not been assessed yet.