https://kotlinlang.org logo
#compose
Title
# compose
s

skwalking

11/21/2021, 7:05 AM
Copy code
@Composable
fun GetContentExample() {
    val context = LocalContext.current
    var directoryUri by remember { mutableStateOf<Uri?>(null) }
    //val imageUri = mutableListOf<Uri?>()
    //val cR = context.contentResolver

    val launcher =
        rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri: Uri? ->
            directoryUri = uri
        }
    Column(modifier = Modifier.fillMaxSize()) {

        Button(onClick = { launcher.launch(directoryUri) }) {
            Text(text = "Load Image")

        }

        val documentFile = directoryUri?.let { DocumentFile.fromTreeUri(context, it) }
        val files = documentFile?.listFiles()

        val pathList = mutableListOf<DocumentFile>()

        files?.forEach { file ->
            if (file.type == "image/jpeg") {
                pathList.add(file)
            }
        }

        LazyColumn(modifier = Modifier.fillMaxSize()) {
            items(items = pathList) { path ->
                Text(text = path.uri.toString())
                Image(
                    painter = rememberImagePainter(path.uri),
                    contentDescription = "My Image"
                )
                Spacer(modifier = Modifier.height(20.dp))
            }
        }
    }
}
Help Text appearing but not the images. Here I'm first taking access to pictures folder then wanna show it on LazyColumn... It'll be good if you provide source I can read to know how to display, copy images from one folder to another 🙂
🧵 4
c

Colin White

11/21/2021, 9:01 AM
This is a Coil issue with how it handles unbounded sizes: https://github.com/coil-kt/coil/issues/953. Setting
rememberImagePainter(path.uri) { size(OriginalSize) }
should work around the issue, but keep an eye on that Github thread as there’s better solution coming soon.
z

Zach Klippenstein (he/him) [MOD]

11/22/2021, 4:02 PM
Please keep code snippets and other large blocks in this channel to threads. https://kotlinlang.slack.com/archives/CJLTWPH7S/p1614355175421600
12 Views