Open Theoistic opened 2 years ago
It works with Android 12/sdk 31+
It does not work even with Android 12/sdk 31+ when it is used inside navigation page. Is there a workaround
Has someone found a solution or workaround? It is still not working for me. Works fine when i set the MainPage. But if i use it with NavigationPage, i only see a black screen.
I dot the same problem using AppShell and tabbed pages. When tabbing to another page and going back, the camera disappears. The camera object is probably destroyed when changing to another tab, and not reinitialized when the page gets in focus.
Could be that the MainPage get initialized before it get focused, and when it get focused it is never properly initialized.
It was easy to reproduce in the BigIslandBarcode project
Replace
MainPage = new MainPage();
with
MainPage = new NavigationPage(new MainPage());
This is still an issue. The issue lies here:
When using a FlyoutPage (for example), Context.Context
is not a Lifecycle owner.
QuickWatch: ContentPage Snipping Tool: FlyoutPage
Hello,
I am try ZXing.Net.Maui on .NET 6 Framework and sometimes the camera just turns black. Is anyone know what is the fix for this issue?
I have also noticed an other preview version of ZXing.Net.Maui on NuGet supporting NET 7, do you know if the black screen issue will be addressed on that version ?
Thank you
When using a FlyoutPage (for example), Context.Context is not a Lifecycle owner.
If you understand the bug, don't you know how to fix it upstream? (i.e. propose a PR?)
Same issue here, with a NavigationPage the view is Black. .NET 6, Android 12
I found a workaround for this, you need to recreate and re-assign the camera view with something like the following:
Add to Page Init: Appearing += Page_Appearing;
private void Page_Appearing(object sender, EventArgs e)
{
RecreateCameraView();
}
private void RecreateCameraView()
{
// Create a new instance for CameraBarcodeReaderView
var newCameraView = new CameraBarcodeReaderView()
{
Options = new BarcodeReaderOptions
{
AutoRotate = true,
Multiple = false,
TryHarder = true,
TryInverted = true,
Formats = BarcodeFormat.QrCode
},
CameraLocation = CameraLocation.Rear
};
newCameraView.BarcodesDetected += cameraView_BarCodeDetected;
var index = CameraGrid.Children.IndexOf(CameraView);
CameraGrid.Children.Remove(CameraView);
`CameraGrid.Children.Insert(index,newCameraView);`
// Assign your new instance to CameraView.
CameraView = newCameraView;
}
Replace "CameraView" with the name of your CameraBarcodeReaderView, Replace "CameraGrid" with the name of the Parent container. Adjust the Options and listeners etc to whatever you are needing.
This is still an issue. The issue lies here:
When using a FlyoutPage (for example),
Context.Context
is not a Lifecycle owner.QuickWatch: ContentPage Snipping Tool: FlyoutPage
I found a workaround for this, you need to recreate and re-assign the camera view with something like the following:
Add to Page Init: Appearing += Page_Appearing; private void Page_Appearing(object sender, EventArgs e) { RecreateCameraView(); } private void RecreateCameraView() { // Create a new instance for CameraBarcodeReaderView var newCameraView = new CameraBarcodeReaderView() { Options = new BarcodeReaderOptions { AutoRotate = true, Multiple = false, TryHarder = true, TryInverted = true, Formats = BarcodeFormat.QrCode }, CameraLocation = CameraLocation.Rear }; newCameraView.BarcodesDetected += cameraView_BarCodeDetected; var index = CameraGrid.Children.IndexOf(CameraView); CameraGrid.Children.Remove(CameraView); `CameraGrid.Children.Insert(index,newCameraView);` // Assign your new instance to CameraView. CameraView = newCameraView; }
Replace "CameraView" with the name of your CameraBarcodeReaderView, Replace "CameraGrid" with the name of the Parent container. Adjust the Options and listeners etc to whatever you are needing.
Thank you for the workaround. It worked for me.
Solution it's working for me is open CameraBarcodeReaderView in Shell modal
await Shell.Current.Navigation.PushModalAsync(new CameraPage(), true);
<zxing:CameraBarcodeReaderView Options="{Binding BarcodeOptions}">
<zxing:CameraBarcodeReaderView.Behaviors>
<toolkit:EventToCommandBehavior
EventName="BarcodesDetected"
Command="{Binding BarcodeDetectedCommand}"
EventArgsConverter="{StaticResource BarcodeDetectedEventArgsConverter}"/>
</zxing:CameraBarcodeReaderView.Behaviors>
</zxing:CameraBarcodeReaderView>
note
: This is a solution for MVVM pattern.
Can someone propose a PR instead of posting workarounds? :)
Can someone propose a PR instead of posting workarounds? :)
I agree, I can take a look at this this weekend if you all want
Only way atm to use the components is by setting the MainPage manually, when pushing and poping using navigation it will cause the component not to initialize.