onseok / peekaboo

🌄 Kotlin Multiplatform library for Compose Multiplatform, designed for seamless integration of an image picker feature in iOS and Android applications.
Apache License 2.0
241 stars 20 forks source link

Camera state based control #67

Closed SuLG-ik closed 8 months ago

SuLG-ik commented 8 months ago

Add PeekabooCameraState and PeekabooCamera that matches state flow.

Reason: old api with inner overlay has no abilities for advanced usage of camera. For example, if i need to handle progress state outside of PeekabooCamera, i add external boolean state of is in progress and add disposable effect inside progressIndicator to change this state and handle it outside PeekabooCamera, for example, to change captureIcon.

var isCapturing by remember { mutableStateOf(false) }
PeekabooCamera(
    modifier = Modifier.fillMaxSize().padding(it),
    cameraMode = CameraMode.Back,
    progressIndicator = {
        DisposableEffect(Unit) {
            isCapturing = true
            onDispose { isCapturing = false }
        }
    },
   / * ... */
)

Benefits: camera overlay become more flexible and in future PeekabooCameraState will be able to have advanced features of camera control.

Note: camera underhood is not changes, only provide actions to new state api. Old api saved for compatibility, but underhood rebased on state

SuLG-ik commented 8 months ago

Fix for pass spotless check

onseok commented 8 months ago

Thanks for your PR! LGTM 👍