Skip to content

Commit 6a3a69e

Browse files
authored
Merge branch 'main' into main
2 parents 2129bf8 + ce9d6f2 commit 6a3a69e

5 files changed

Lines changed: 77 additions & 51 deletions

File tree

build-logic/convention/src/main/kotlin/io/github/kalinjul/convention/config/Multiplatform.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
44

55
fun KotlinMultiplatformExtension.configureIosTargets(baseName: String? = null) {
66
listOf(
7-
iosX64(),
87
iosArm64(),
98
iosSimulatorArm64()
109
).forEach {

documentscanner-compose/src/iosMain/kotlin/io/github/kalinjul/easydocumentscan/DocumentScanner.ios.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.runtime.getValue
55
import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.remember
77
import androidx.compose.runtime.setValue
8+
import androidx.compose.ui.uikit.LocalUIView
89
import androidx.compose.ui.uikit.LocalUIViewController
910
import platform.AVFoundation.AVErrorApplicationIsNotAuthorizedToUseDevice
1011
import platform.UIKit.UIButton
@@ -19,7 +20,7 @@ actual fun rememberDocumentScanner(
1920
options: DocumentScannerOptions
2021
): DocumentScanner {
2122

22-
val localViewController = LocalUIViewController.current
23+
val localUiView = LocalUIView.current
2324

2425
var delegate by remember() { mutableStateOf<DocumentScannerDelegate?>(null) }
2526

@@ -29,19 +30,19 @@ actual fun rememberDocumentScanner(
2930
controller.setDelegate(
3031
DocumentScannerDelegate(
3132
onError = {
32-
controller.dismissViewControllerAnimated(true) {}
33+
controller.dismissViewControllerAnimated(false) {}
3334
val exception = when(it.code) {
3435
AVErrorApplicationIsNotAuthorizedToUseDevice -> DocumentScannerException.NotAuthorized(it.localizedDescription)
3536
else -> DocumentScannerException.Unknown(it.localizedDescription)
3637
}
3738
onResult(Result.failure(exception))
3839
},
3940
onCancel = {
40-
controller.dismissViewControllerAnimated(true) {}
41+
controller.dismissViewControllerAnimated(false) {}
4142
onResult(Result.failure(DocumentScannerException.Canceled(message = null)))
4243
},
4344
onResult = { result ->
44-
controller.dismissViewControllerAnimated(true) {}
45+
controller.dismissViewControllerAnimated(false) {}
4546

4647
val documents = (0..< result.pageCount.toInt()).map {
4748
val image = result.imageOfPageAtIndex(it.toULong())
@@ -54,7 +55,8 @@ actual fun rememberDocumentScanner(
5455
delegate = it // need to remember delegate else it is dereferenced
5556
}
5657
)
57-
localViewController.presentViewController(controller, animated = true) {
58+
val viewController = localUiView.window?.rootViewController
59+
viewController?.presentViewController(controller, animated = true) {
5860
if (options.ios.captureMode == DocumentCaptureMode.MANUAL) {
5961
controller.setManualMode()
6062
}

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ kotlin.code.style=official
88
#MPP
99
kotlin.mpp.stability.nowarn=true
1010
kotlin.mpp.enableCInteropCommonization=true
11-
kotlin.mpp.androidSourceSetLayoutVersion=2
1211

1312
#Compose
1413
org.jetbrains.compose.experimental.uikit.enabled=true

sample-app/shared/gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ android.useAndroidX=true
77
#MPP
88
kotlin.mpp.stability.nowarn=true
99
#kotlin.mpp.enableCInteropCommonization=true
10-
kotlin.mpp.androidSourceSetLayoutVersion=2
1110

1211
#Compose
1312
org.jetbrains.compose.experimental.uikit.enabled=true

sample-app/shared/src/commonMain/kotlin/MainView.kt

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import androidx.compose.foundation.layout.padding
66
import androidx.compose.foundation.lazy.LazyColumn
77
import androidx.compose.foundation.lazy.items
88
import androidx.compose.material3.Button
9+
import androidx.compose.material3.ExperimentalMaterial3Api
10+
import androidx.compose.material3.ModalBottomSheet
911
import androidx.compose.material3.Scaffold
1012
import androidx.compose.material3.SnackbarDuration
1113
import androidx.compose.material3.SnackbarHost
1214
import androidx.compose.material3.SnackbarHostState
1315
import androidx.compose.material3.Text
16+
import androidx.compose.material3.rememberBottomSheetScaffoldState
17+
import androidx.compose.material3.rememberModalBottomSheetState
1418
import androidx.compose.runtime.Composable
1519
import androidx.compose.runtime.LaunchedEffect
1620
import androidx.compose.runtime.getValue
@@ -29,64 +33,87 @@ import io.github.kalinjul.easydocumentscan.KmpImage
2933
import io.github.kalinjul.easydocumentscan.rememberDocumentScanner
3034
import kotlinx.coroutines.launch
3135

36+
@OptIn(ExperimentalMaterial3Api::class)
3237
@Composable
3338
fun MainView() {
3439
val snackbarHostState = remember() { SnackbarHostState() }
40+
41+
var showBottomSheet by remember { mutableStateOf(false) }
42+
if (showBottomSheet) {
43+
44+
ModalBottomSheet(
45+
onDismissRequest = { showBottomSheet = false }
46+
) {
47+
var images by remember { mutableStateOf<List<KmpImage>>(listOf()) }
48+
var bitmapImages by remember { mutableStateOf<List<ImageBitmap>>(listOf()) }
49+
50+
LaunchedEffect(images) {
51+
images.map { it.loadImage() }.also { bitmapImages = it }
52+
}
53+
54+
Column(modifier = Modifier) {
55+
Text("Scanner Bottom sheet")
56+
val scope = rememberCoroutineScope()
57+
val scanner = rememberDocumentScanner(
58+
onResult = {
59+
if (it.isSuccess) {
60+
images = it.getOrThrow()
61+
scope.launch {
62+
snackbarHostState.showSnackbar(
63+
"${images.size} documents scanned",
64+
duration = SnackbarDuration.Short
65+
)
66+
}
67+
} else {
68+
println(it.exceptionOrNull())
69+
}
70+
},
71+
options = DocumentScannerOptions(
72+
DocumentScannerOptionsAndroid(
73+
pageLimit = 3,
74+
allowGalleryImport = true,
75+
scannerMode = DocumentScannerModeAndroid.BASE
76+
),
77+
DocumentScannerOptionsIos(
78+
captureMode = DocumentCaptureMode.MANUAL
79+
)
80+
)
81+
)
82+
Button(onClick = {
83+
scanner.scan()
84+
}) {
85+
Text("Scan")
86+
}
87+
88+
LazyColumn {
89+
items(bitmapImages) {
90+
Image(
91+
bitmap = it,
92+
contentDescription = null
93+
)
94+
}
95+
}
96+
}
97+
}
98+
}
99+
35100
Scaffold(
36101
snackbarHost = {
37102
SnackbarHost(
38103
hostState = snackbarHostState
39104
)
40-
}
105+
},
41106
) {
42-
var images by remember { mutableStateOf<List<KmpImage>>(listOf()) }
43-
var bitmapImages by remember { mutableStateOf<List<ImageBitmap>>(listOf()) }
44-
45-
LaunchedEffect(images) {
46-
images.map { it.loadImage() }.also { bitmapImages = it }
47-
}
48-
49107
Column(modifier = Modifier.padding(it)) {
50108
Text("Document Scanner demo")
51109
val scope = rememberCoroutineScope()
52-
val scanner = rememberDocumentScanner(
53-
onResult = {
54-
if (it.isSuccess) {
55-
images = it.getOrThrow()
56-
scope.launch {
57-
snackbarHostState.showSnackbar(
58-
"${images.size} documents scanned",
59-
duration = SnackbarDuration.Short
60-
)
61-
}
62-
} else {
63-
println(it.exceptionOrNull())
64-
}
65-
},
66-
options = DocumentScannerOptions(
67-
DocumentScannerOptionsAndroid(
68-
pageLimit = 3,
69-
allowGalleryImport = true,
70-
scannerMode = DocumentScannerModeAndroid.BASE
71-
),
72-
DocumentScannerOptionsIos(
73-
captureMode = DocumentCaptureMode.MANUAL
74-
)
75-
)
76-
)
77110
Button(onClick = {
78-
scanner.scan()
79-
}) {
80-
Text("Scan")
81-
}
111+
scope.launch {
112+
showBottomSheet = !showBottomSheet
82113

83-
LazyColumn {
84-
items(bitmapImages) {
85-
Image(
86-
bitmap = it,
87-
contentDescription = null
88-
)
89114
}
115+
}) {
116+
Text("Show Bottom sheet")
90117
}
91118
}
92119
}

0 commit comments

Comments
 (0)