https://kotlinlang.org logo
s

Slackbot

03/07/2021, 12:36 PM
This message was deleted.
d

Denis

03/07/2021, 12:38 PM
do you try to
remember
on the top level?
m

Mjahangiry75

03/07/2021, 12:39 PM
it bundled in
InputDialog
d

Denis

03/07/2021, 12:42 PM
I was talking about
val showRenameDocumentDialog = remember,
but I suppose it's not full code, though. Otherwise it shouldn't even compile, right? btw, could you put code in the thread? it takes a lot of space in the channel
m

Mjahangiry75

03/07/2021, 12:45 PM
no I don't get compile errors when the error occurs when I tap on the confirm button
Copy code
val showRenameDocumentDialog = remember { mutableStateOf<Document?>(null) }

showRenameDocumentDialog.value?.let { document ->
    InputDialog(
        inputLabel = stringResource(id = R.string.rename_document_dialog_placeholder),
        onConfirm = {
            documentsBaseViewModel.renameDocument(document.id, it)
            showRenameDocumentDialog.value = null
        },
        onDismissRequest = {
            showRenameDocumentDialog.value = null
        }
    )
}

@Composable
fun InputDialog(
    modifier: Modifier = Modifier,
    inputLabel: String,
    onConfirm: (String) -> Unit,
    onDismissRequest: () -> Unit = {}
) {

    val (input, setInput) = remember { mutableStateOf("") }

    Dialog(
        onDismissRequest = onDismissRequest,
        properties = DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true),
        content = {
            Column(
                modifier = modifier
                    .background(color = Color(0xFFFFFFFF), shape = alertDialogShape)
                    .padding(horizontal = 16.dp, vertical = 32.dp),
            ) {

                OutlinedTextField(
                    label = { Text(text = inputLabel) },
                    value = input,
                    onValueChange = setInput
                )

                Spacer(modifier = Modifier.height(16.dp))

                ActionButton(
                    modifier = Modifier.fillMaxWidth(),
                    onClick = {
                        onConfirm(input)
                        setInput("")
                    }
                ) {
                    Text(text = stringResource(id = R.string.confirm))
                }
            }
        }
    )
}