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

Camera work but overlay is hidden

Open marwenhinnaoui opened this issue 2 years ago • 16 comments

getCamera(){ const cameraPreviewOptions: CameraPreviewOptions = { className:'CameraPreview', position: 'rear', x:0, y:0, toBack:false, }; CameraPreview.start(cameraPreviewOptions); this.cameraActive=true; }

My scss: ion-content { --background: transparent !important; .CameraPreview{ width: 100%; height: 10%; ion-button{ position: absolute; z-index: 20; bottom: 0; } } ion-button{ position: absolute; z-index: 20; } }

marwenhinnaoui avatar Feb 07 '22 16:02 marwenhinnaoui

you need toBack:true

nseb avatar Feb 08 '22 14:02 nseb

i tried toBack:true but same issue the overlay is displayed and the camera work but i got white screen

marwenhinnaoui avatar Feb 08 '22 20:02 marwenhinnaoui

Hi @marwenhinnaoui and welcome to camera-preview!

With toBack: true set you will need to play with background transparency in your Ionic app. Please see the block of code and paragraph of text just above https://github.com/capacitor-community/camera-preview#stop for some details.

I find it easiest to give every element in my app - <ion-page> <ion-content> and so on - a different background colour so I can see which is stopping me from viewing the camera.

Good luck!

pbowyer avatar Feb 09 '22 09:02 pbowyer

Hello, I am having this same problem. I set toBack: true, ion-content {--background: transparent!important}, as well as setting the <div> that hosts the camera to background: transparent. I also cloned the demo repo to see how it ran on my Galaxy S9, and it doesn't display the camera. I know the camera is running because I hear the shutter and can still take pictures, but I just can't see what the camera is looking at.

holcomc avatar Mar 18 '22 19:03 holcomc

Hello! check the variables.scss and remove https://github.com/media (prefers-color-scheme: dark) content, then add to your CameraPreviewOptions this block of code: /* x:0, y:0, width: window.screen.width, height: window.screen.height, parent:'cameraPreview', className:'cameraPreview', position: 'rear', toBack:true / then check than in your html page that the parent is only the simple div like this and don't add background: transparent: /

*/

hope this help this

marwenhinnaoui avatar Mar 19 '22 19:03 marwenhinnaoui

There's a problem with the plugins implementation for Android. It launches a fragment that can either be above or behind the app. This eliminates all use cases for elements presented within a second view above the main app view. e.g Showing within a modal.

xsh2047 avatar Mar 23 '22 01:03 xsh2047

@xsh2047 Is there an alternative way it can be implemented on Android?

pbowyer avatar Mar 23 '22 08:03 pbowyer

I was looking into Ionic Portals. Not sure if this is a valid use case.

There's also the Web Media Capture API's but that wouldn't be a native solution.

xsh2047 avatar Mar 25 '22 01:03 xsh2047

Was anyone able to handle this issue on Ionic Angular App?

mwanginjamb avatar May 23 '22 12:05 mwanginjamb

No update on that ?

evanlegamer avatar Jun 25 '22 02:06 evanlegamer

I'm having the same issue, but only when the app runs in dark mode. If I change the device theme to light - the camera preview shows. However, it won't let me change it to light anymore - always runs on dark. I also have:

ion-content {
  --background: transparent !important;
}

And when I change it in the inspector to red - the black cover does change its color to red, which tells me that the cover is coming from a lower level (OS?) for the dark theme, and not controllable in the app.

As a workaround, I'm OK with forcing a light theme in the app:

document.body.setAttribute('data-theme', 'light');
document.body.classList.toggle('dark', false);

But it doesn't seem to work. App is now running in Dark mode regardless of theme settings or the above settings. I am experiencing this with two devices:

Xiaomi Rednote 8. Samsung Galaxy A32.

Is there a way anybody can think of for me to force the light theme on all devices (android and iOS)? This is an Angular 13 Ionic 6 app.

morsagmon avatar Jul 11 '22 20:07 morsagmon

I was experiencing the white screen with toBack: true.

I am using Vue 3 with Ionic 6.1 Here is what I did to solve it:

<style>
  body { background: transparent; }
  ion-content { --background: transparent; }
</style>

*Notice <style> is not scoped

MaxWeisen avatar Jul 14 '22 22:07 MaxWeisen

toBack: true is good solution. thanks.

hokimtam avatar Jan 31 '23 16:01 hokimtam

There's a problem with the plugins implementation for Android. It launches a fragment that can either be above or behind the app. This eliminates all use cases for elements presented within a second view above the main app view. e.g Showing within a modal.

Same issue as @xsh2047 descibes it here. On Android, I can either use toBack: true to display the camera stream behind the WebView or toBack: false to display it on top of the WebView. It doesn't seem to adhere to the position of the parent component. In Desktop browsers I can use position: absolute; and z-index to display elements above the stream (e.g. a frame that helps the user to find the right camera position). This is not possible at all on Android.

Using toBack: true and then "cut out" the image from the whole app is not feasible as I'm using Vuetify as component framework and want to display the camera preview stream in an dialog overlay.

Is there any way to fix this broken behavior?

frederikheld avatar Nov 20 '23 16:11 frederikheld

Just had this issue myself on Android - if you are in same situation I was (Camera starts, CameraPreview.capture() works correctly but the preview cant be seen / is a solid colour even when toBack: false) the solution is it double check your android/app/src/main/res/values/styles.xml - within AppTheme.NoActionBar make sure you don't have a background colour, this can be done with <item name="android:background">@null</item>.

If you have a background colour set within here the preview that shows the camera will be that solid colour rather than the camera feed. Hope this helps others!

haydncomley avatar Nov 23 '23 01:11 haydncomley

Thanks for the hint, but it didn't fix the issue. The value is already set like you suggested. I also think that this doesn't exactly relate to my problem.

I'm using toBack: false, which - on desktop - puts the camera image in front of the app but still allows me to stack elements on top of it. I think that - on desktop - toBack is relative to the parent element that is defined in the CameraPreviewOptions.

On Android those stacked elements are rendered behind the preview, which leads me to believe, that toBack is relative to the whole app / WebView.

The Android behavior would be more in line with the documentation, but the desktop behavior is way more useful...

Other users commented that iOS behaves like desktop but I wasn't able to verify that yet.

frederikheld avatar Nov 23 '23 11:11 frederikheld