Hi everyone! Has anyone encountered an issue with ...
# compose
g
Hi everyone! Has anyone encountered an issue with BTF2 where the field loses focus and the keyboard closes in some cases after recomposing? I currently have such problem, maybe there is some workaround or existing issue. I've managed to create a minimal reproducer, video and code in thread
Copy code
@Composable
fun NewPhoneField(
    modifier: Modifier = Modifier,
    textStyle: TextStyle = MaterialTheme.typography.titleSmall,
) {
    var errorText by remember { mutableStateOf<Int?>(null) }
    val fieldState = rememberTextFieldState()

    LaunchedEffect(Unit) {
        delay(5000)
        errorText = android.R.string.cancel
    }

    LaunchedEffect(Unit) {
        snapshotFlow { fieldState.text.toString() }.collect {
            errorText = null
        }
    }

    errorText?.let { stringResource(it) }

    BasicTextField(
        state = fieldState,
        textStyle = textStyle,
        modifier = modifier
            .safeContentPadding()
            .background(Color.LightGray),
    )
}
h
Is there something missing in the code? What are you doing with errorText? Or are you using just to trigger a recomposition in NewPhoneField?
g
In real code I display this error as Text (that's why recomposition happens here), removed Text and just left recomposition trigger for simplicity