-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../src/mobileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitCompose.mobile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
9 changes: 9 additions & 0 deletions
9
...bileMain/kotlin/io/github/vinceglb/filekit/dialog/compose/FileKitResultLauncher.mobile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.github.vinceglb.filekit.dialog.compose | ||
|
||
public class PhotoResultLauncher( | ||
private val onLaunch: () -> Unit, | ||
) { | ||
public fun launch() { | ||
onLaunch() | ||
} | ||
} |