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

Fix flash overlay animation not appearing fully over SurfaceView by using a dedicated overlay View

Open bolaware opened this issue 9 months ago • 0 comments

The foreground drawable was not rendering fully over the entire screen due to the use of SurfaceView by PreviewView when ImplementationMode.PERFORMANCE is used (which is the default)(Source). SurfaceView draws in a separate window layer, which causes it to clip or obscure any views (like overlays or foregrounds) placed above it in the view hierarchy.

Instead of switching to TextureView via ImplementationMode.COMPATIBLE (which is less performant [source]), this fix introduces a dedicated full-screen overlay View positioned above the camera preview. The flash animation is now handled by toggling the visibility and animating the alpha of this overlay view, ensuring consistent visual feedback without compromising performance.

Additionally, this approach eliminates the need for API-level checks (previously required for Android 23 and below), making the flash animation available across all supported versions.

Description Link
Before https://github.com/user-attachments/assets/4b14eec4-4dc9-4a20-923e-c338df137f5a
After https://github.com/user-attachments/assets/5368dca5-a35b-454e-a4b1-7c504eb1401b

bolaware avatar May 22 '25 16:05 bolaware