Skip to content

Commit

Permalink
fix PeekabooCameraState recreation when lambda onCapture does not mem…
Browse files Browse the repository at this point in the history
…oized
  • Loading branch information
SuLG-ik committed Mar 14, 2024
1 parent 5c2f5b4 commit 2a59de1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.compose.runtime.setValue
@Stable
actual class PeekabooCameraState(
cameraMode: CameraMode,
private val onCapture: (ByteArray?) -> Unit,
internal var onCapture: (ByteArray?) -> Unit,
) {
actual var isCameraReady: Boolean by mutableStateOf(false)

Expand Down Expand Up @@ -80,7 +80,8 @@ actual fun rememberPeekabooCameraState(
onCapture: (ByteArray?) -> Unit,
): PeekabooCameraState {
return rememberSaveable(
onCapture,
saver = PeekabooCameraState.saver(onCapture),
) { PeekabooCameraState(initialCameraMode, onCapture) }
) { PeekabooCameraState(initialCameraMode, onCapture) }.apply {
this.onCapture = onCapture
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.compose.runtime.setValue
@Stable
actual class PeekabooCameraState(
cameraMode: CameraMode,
private val onCapture: (ByteArray?) -> Unit,
internal var onCapture: (ByteArray?) -> Unit,
) {
actual var isCameraReady: Boolean by mutableStateOf(false)

Expand Down Expand Up @@ -80,7 +80,8 @@ actual fun rememberPeekabooCameraState(
onCapture: (ByteArray?) -> Unit,
): PeekabooCameraState {
return rememberSaveable(
onCapture,
saver = PeekabooCameraState.saver(onCapture),
) { PeekabooCameraState(initialCameraMode, onCapture) }
) { PeekabooCameraState(initialCameraMode, onCapture) }.apply {
this.onCapture = onCapture
}
}

0 comments on commit 2a59de1

Please sign in to comment.