https://kotlinlang.org logo
d

Deepak Gahlot

02/26/2021, 3:00 PM
Copy code
@Preview
@Composable
fun AttachmentComponent() {

    var fileName = remember { mutableStateOf(ArrayList<String>()) }
    var array = arrayOf("application/pdf")
    var files = ArrayList<String>()
    var fileAttached = remember { mutableStateOf(false) }


    Column {

        val registerTakeFile = registerForActivityResult(
            ActivityResultContracts.OpenMultipleDocuments()
        ) {
            for (i in 0 until it.size) {
                var uri = it.get(i)
                files.add(uri.path!!)
            }
            fileName.value = files
        }

        Text(
            text = "Attachment",
            color = colorResource(id = R.color.gray1)
        )
        if (fileAttached.value) {
            FileAttached(item = fileName.value)
        }
        OutlinedButton(
            modifier = Modifier
                .fillMaxWidth()
                .padding(16.dp),
            colors = ButtonDefaults.outlinedButtonColors(
                contentColor = colorResource(id = R.color.blue1)
            ),
            onClick = {
                registerTakeFile.launch(array)
                fileAttached.value = true
            }
        ) {
            Icon(painterResource(id = R.drawable.ico_attach), contentDescription = "attach")
            Text(
                fontSize = 14.sp,
                text = "Add Files",
                )
        }
    }
}

@Composable
fun FileAttached(item: ArrayList<String>) {
    Column {
        item.forEach {
            Row {
                Text(
                    text = it,
                    color = colorResource(id = R.color.black)
                )
            }
        }
    }
}
i

Ian Lake

02/26/2021, 3:06 PM
Please file a bug with a sample project and we can take a look: https://issuetracker.google.com/issues/new?component=527362&amp;template=1189829
👍 1
d

Deepak Gahlot

02/26/2021, 3:07 PM
Sure will do that
@Ian Lake after updating to the new version i'm getting this exception
Can only use lower 16 bits for requestCode
, how do i set the requestCode
i

Ian Lake

03/15/2021, 1:30 PM
Upgrade to Fragment 1.3.0 - Compose doesn't do this for you anymore as per the release notes: https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0-beta02
🙏 1
4 Views