Deepak Gahlot

    Deepak Gahlot

    1 year ago
    @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

    1 year ago
    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
    Deepak Gahlot

    Deepak Gahlot

    1 year ago
    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

    1 year ago
    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