Skip to content

Commit

Permalink
Merge pull request #78 from EssentialNRG/hotfix/null-ref-barcodeview
Browse files Browse the repository at this point in the history
Update LayoutSubviews BarcodeView to prevent NullReferenceException
  • Loading branch information
afriscic authored Jul 8, 2024
2 parents e0b980f + af5c1e0 commit d7c4ad7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ public override void LayoutSubviews()
{
base.LayoutSubviews();

var layer = this.Layer;
var window = this.Window;
if (window is null || layer is null) {
return;
}

if (_previewLayer is not null)
_previewLayer.Frame = this.Layer.Bounds;
_previewLayer.Frame = layer.Bounds;
if (_shapeLayer is not null)
_shapeLayer.Position = new CGPoint(this.Layer.Bounds.Width / 2, this.Layer.Bounds.Height / 2);
_shapeLayer.Position = new CGPoint(layer.Bounds.Width / 2, layer.Bounds.Height / 2);

if (_previewLayer?.Connection is not null && _previewLayer.Connection.SupportsVideoOrientation)
_previewLayer.Connection.VideoOrientation = this.Window.WindowScene?.InterfaceOrientation switch
var previewLayerConnection = _previewLayer?.Connection;
if (previewLayerConnection is not null && previewLayerConnection.SupportsVideoOrientation)
previewLayerConnection.VideoOrientation = window.WindowScene?.InterfaceOrientation switch
{
UIInterfaceOrientation.LandscapeLeft => AVCaptureVideoOrientation.LandscapeLeft,
UIInterfaceOrientation.LandscapeRight => AVCaptureVideoOrientation.LandscapeRight,
Expand Down

0 comments on commit d7c4ad7

Please sign in to comment.