[iOS] voice dictation text does not register with text fields using TextFieldValue
Describe the bug
When using the iOS stock keyboard's voice dictation in a BasicTextField using TextFieldValue, the dictated text is cleared when voice dictation is disabled.
Affected platforms
- iOS
Versions
- Libraries:
- Compose Multiplatform version: 1.6.11
- Kotlin version: 2.0.0
- OS version(s) (required for Desktop and iOS issues): iOS 17.5.1
- OS architecture (x86 or arm64): N/A
- Device (model or simulator for iOS issues): iPhone SE 2020, but reported on newer models as well
- JDK (for desktop issues): N/A
To Reproduce Steps to reproduce the behavior:
- Create a
BasicTextFieldusingTextFieldValuee.g.
var textState by remember { mutableStateOf(TextFieldValue()) }
BasicTextField(
value = textState,
onValueChange = { textState = it },
)
- Click on the voice dictation button on the stock iOS keyboard
- Dictate
- Tap on the screen to end the dictation
- The text will disappear as soon as dictation ends
Repo that reproduces the issue on my device: https://github.com/garrison-henkle/composeMultiplatformVoiceDictationBug
Expected behavior The text does not disappear when dictation ends
Screenshots https://github.com/JetBrains/compose-multiplatform/assets/70973354/d4997920-0a77-479e-a5a9-26b7be7259a1
Additional context
I played around with the debugger / print statements for a bit this afternoon. To reproduce in the compose-multiplatform-core repo, I added the following to androidx.compose.mpp.demo.textfield.android.TextFieldValueDemo:
item {
TagLine("TextFieldValue overload")
var state by remember { mutableStateOf(TextFieldValue()) }
BasicTextField(
value = state,
onValueChange = { state = it },
textStyle = TextStyle(fontSize = fontSize8),
modifier = demoTextFieldModifiers
)
}
So far, the issue seems be somewhere afteronValueChangeOriginal is called in CoreTextField's onValueChange here. It is called with the correct TextFieldValue containing the dictated text, but the callback in the BasicTextField that I'm using receives what looks like a brand new empty TextFieldValue instance instead.
There is a currentRecomposeScope.invalidate() that is called immediately after the onValueChangeOriginal call, so I wonder if that is breaking something.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.