Skip to content

Commit af74717

Browse files
committed
♻️ Refactor: camera unbinding 메서드를 동기 방식으로 수정
1 parent 6f6c4b5 commit af74717

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

feature/task-certification/src/main/java/com/twix/task_certification/TaskCertificationScreen.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ fun TaskCertificationRoute(
8383
}
8484

8585
onDispose {
86-
coroutineScope.launch {
87-
camera.unbind()
88-
}
86+
camera.unbind()
8987
}
9088
}
9189

feature/task-certification/src/main/java/com/twix/task_certification/camera/Camera.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface Camera {
1515
lens: CameraSelector,
1616
)
1717

18-
suspend fun unbind()
18+
fun unbind()
1919

2020
suspend fun takePicture(): Result<Uri>
2121

feature/task-certification/src/main/java/com/twix/task_certification/camera/CaptureCamera.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class CaptureCamera(
2929
) : Camera {
3030
private var cameraControl: CameraControl? = null
3131
private var cameraInfo: CameraInfo? = null
32+
private var cameraProvider: ProcessCameraProvider? = null
3233

3334
private val _surfaceRequests = MutableStateFlow<CameraPreview?>(null)
3435
override val surfaceRequests: StateFlow<CameraPreview?> = _surfaceRequests.asStateFlow()
@@ -54,6 +55,8 @@ class CaptureCamera(
5455
lens: CameraSelector,
5556
) {
5657
val provider = ProcessCameraProvider.awaitInstance(context)
58+
cameraProvider = provider
59+
5760
provider.unbindAll()
5861

5962
val camera =
@@ -118,8 +121,8 @@ class CaptureCamera(
118121
}
119122
}
120123

121-
override suspend fun unbind() {
122-
ProcessCameraProvider.awaitInstance(context).unbindAll()
124+
override fun unbind() {
125+
cameraProvider?.unbindAll()
123126
}
124127

125128
override fun toggleTorch(torch: TorchStatus) {

0 commit comments

Comments
 (0)