Skip to content

Commit

Permalink
Merge pull request #148 from janmarektelc/bugfix-118-release-camera-r…
Browse files Browse the repository at this point in the history
…esources

Camera resources relese
  • Loading branch information
Redth authored Sep 12, 2024
2 parents 631825a + 19af047 commit 57eef38
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
12 changes: 10 additions & 2 deletions ZXing.Net.MAUI.Controls/Controls/CameraBarcodeReaderView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public partial class CameraBarcodeReaderView : View, ICameraBarcodeReaderView
public event EventHandler<BarcodeDetectionEventArgs> BarcodesDetected;
public event EventHandler<CameraFrameBufferEventArgs> FrameReady;

void ICameraBarcodeReaderView.BarcodesDetected(BarcodeDetectionEventArgs e) => BarcodesDetected?.Invoke(this, e);
public CameraBarcodeReaderView()
{
Unloaded += (s, e) => Cleanup();
}

void ICameraBarcodeReaderView.BarcodesDetected(BarcodeDetectionEventArgs e) => BarcodesDetected?.Invoke(this, e);
void ICameraFrameAnalyzer.FrameReady(ZXing.Net.Maui.CameraFrameBufferEventArgs e) => FrameReady?.Invoke(this, e);

public static readonly BindableProperty OptionsProperty =
Expand Down Expand Up @@ -65,5 +70,8 @@ public void Focus(Point point)

CameraBarcodeReaderViewHandler StrongHandler
=> Handler as CameraBarcodeReaderViewHandler;
}

private void Cleanup()
=> Handler?.DisconnectHandler();
}
}
12 changes: 10 additions & 2 deletions ZXing.Net.MAUI.Controls/Controls/CameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ public partial class CameraView : View, ICameraView
{
public event EventHandler<CameraFrameBufferEventArgs> FrameReady;

void ICameraFrameAnalyzer.FrameReady(CameraFrameBufferEventArgs e)
public CameraView()
{
Unloaded += (s, e) => Cleanup();
}

void ICameraFrameAnalyzer.FrameReady(CameraFrameBufferEventArgs e)
=> FrameReady?.Invoke(this, e);

public static readonly BindableProperty IsTorchOnProperty =
Expand Down Expand Up @@ -38,5 +43,8 @@ public void Focus(Point point)

CameraViewHandler StrongHandler
=> Handler as CameraViewHandler;
}

private void Cleanup()
=> Handler?.DisconnectHandler();
}
}
1 change: 1 addition & 0 deletions ZXing.Net.MAUI/CameraBarcodeReaderViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected override void DisconnectHandler(NativePlatformCameraPreviewView native
cameraManager.FrameReady -= CameraManager_FrameReady;

cameraManager.Disconnect();
cameraManager.Dispose();
}

base.DisconnectHandler(nativeView);
Expand Down
3 changes: 2 additions & 1 deletion ZXing.Net.MAUI/CameraViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ protected override void DisconnectHandler(NativePlatformCameraPreviewView native
{
cameraManager.FrameReady -= CameraManager_FrameReady;

cameraManager.Disconnect();
cameraManager.Disconnect();
cameraManager.Dispose();
}

base.DisconnectHandler(nativeView);
Expand Down
2 changes: 2 additions & 0 deletions ZXing.Net.MAUI/Platforms/Android/CameraManager.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public void AutoFocus()

public void Dispose()
{
cameraProvider?.Shutdown();

cameraExecutor?.Shutdown();
cameraExecutor?.Dispose();
}
Expand Down

0 comments on commit 57eef38

Please sign in to comment.