@@ -6,11 +6,15 @@ import androidx.compose.foundation.layout.padding
66import androidx.compose.foundation.lazy.LazyColumn
77import androidx.compose.foundation.lazy.items
88import androidx.compose.material3.Button
9+ import androidx.compose.material3.ExperimentalMaterial3Api
10+ import androidx.compose.material3.ModalBottomSheet
911import androidx.compose.material3.Scaffold
1012import androidx.compose.material3.SnackbarDuration
1113import androidx.compose.material3.SnackbarHost
1214import androidx.compose.material3.SnackbarHostState
1315import androidx.compose.material3.Text
16+ import androidx.compose.material3.rememberBottomSheetScaffoldState
17+ import androidx.compose.material3.rememberModalBottomSheetState
1418import androidx.compose.runtime.Composable
1519import androidx.compose.runtime.LaunchedEffect
1620import androidx.compose.runtime.getValue
@@ -29,64 +33,87 @@ import io.github.kalinjul.easydocumentscan.KmpImage
2933import io.github.kalinjul.easydocumentscan.rememberDocumentScanner
3034import kotlinx.coroutines.launch
3135
36+ @OptIn(ExperimentalMaterial3Api ::class )
3237@Composable
3338fun 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