diff --git a/filekit-dialog-compose/build.gradle.kts b/filekit-dialog-compose/build.gradle.kts index 296170b..53dba53 100644 --- a/filekit-dialog-compose/build.gradle.kts +++ b/filekit-dialog-compose/build.gradle.kts @@ -53,6 +53,7 @@ kotlin { implementation(libs.kotlinx.coroutines.core) // FileKit Dialog + api(projects.filekitCore) api(projects.filekitDialog) } @@ -60,21 +61,22 @@ kotlin { dependsOn(commonMain.get()) } + val mobileMain by creating { + dependsOn(nonWebMain) + } + val nonAndroidMain by creating { dependsOn(commonMain.get()) } androidMain { dependsOn(nonWebMain) + dependsOn(mobileMain) dependencies { implementation(libs.androidx.activity.compose) } } - nativeMain { - dependsOn(nonWebMain) - dependsOn(nonAndroidMain) - } jvmMain { dependsOn(nonWebMain) dependsOn(nonAndroidMain) @@ -82,6 +84,13 @@ kotlin { implementation(compose.ui) } } + + nativeMain { + dependsOn(nonWebMain) + dependsOn(nonAndroidMain) + } + iosMain.get().dependsOn(mobileMain) + wasmJsMain.get().dependsOn(nonAndroidMain) jsMain.get().dependsOn(nonAndroidMain) } diff --git a/filekit-dialog-compose/src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitCompose.mobile.kt b/filekit-dialog-compose/src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitCompose.mobile.kt new file mode 100644 index 0000000..e5ce390 --- /dev/null +++ b/filekit-dialog-compose/src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitCompose.mobile.kt @@ -0,0 +1,40 @@ +package io.github.vinceglb.filekit.dialog.compose + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.rememberUpdatedState +import io.github.vinceglb.filekit.FileKit +import io.github.vinceglb.filekit.PlatformFile +import io.github.vinceglb.filekit.dialog.takePhoto +import kotlinx.coroutines.launch + +@Composable +public fun rememberTakePhotoLauncher( + onResult: (PlatformFile?) -> Unit, +): PhotoResultLauncher { + // Init FileKit + InitFileKit() + + // Coroutine + val coroutineScope = rememberCoroutineScope() + + // Updated state + val currentOnResult by rememberUpdatedState(onResult) + + // FileKit + val fileKit = remember { FileKit } + + // FileKit launcher + val returnedLauncher = remember { + PhotoResultLauncher { + coroutineScope.launch { + val result = fileKit.takePhoto() + currentOnResult(result) + } + } + } + + return returnedLauncher +} diff --git a/filekit-dialog-compose/src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitResultLauncher.mobile.kt b/filekit-dialog-compose/src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitResultLauncher.mobile.kt new file mode 100644 index 0000000..2ecead1 --- /dev/null +++ b/filekit-dialog-compose/src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitResultLauncher.mobile.kt @@ -0,0 +1,9 @@ +package io.github.vinceglb.filekit.dialog.compose + +public class PhotoResultLauncher( + private val onLaunch: () -> Unit, +) { + public fun launch() { + onLaunch() + } +} \ No newline at end of file