Austin Nelson
11/07/2021, 1:06 PM@Composable
fun TextField() {
var value by remember { mutableStateOf(TextFieldValue("")) }
val keyboardController = LocalSoftwareKeyboardController.current
BasicTextField(
value = value,
onValueChange = { value = it },
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Number
),
keyboardActions = KeyboardActions(
onDone = { keyboardController?.hide() }),
decorationBox = { innerTextField ->
Row(
Modifier
.background(Color.DarkGray, RoundedCornerShape(percent = 50))
.padding(12.dp)
) {
if (value.text.isEmpty()) {
Text("Manual IP Address")
}
innerTextField()
}
},
)
}
John Nichol
11/08/2021, 12:02 PMAustin Nelson
11/15/2021, 2:42 PMwear-input
and use a RemoteInputIntentHelper
to solve my use case. Implementation in case anyone is curious:
val launcher =
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it.data?.let { data ->
val results: Bundle = RemoteInput.getResultsFromIntent(data)
val ipAddress: CharSequence? = results.getCharSequence("ip_address")
Timber.i(ipAddress.toString())
}
}
...
Chip(
label = { Text("Search with specific IP") },
onClick = {
val remoteInputs: List<RemoteInput> = listOf(
RemoteInput.Builder("ip_address")
.setLabel("Manual IP Entry")
.wearableExtender {
setEmojisAllowed(false)
setInputActionType(EditorInfo.IME_ACTION_DONE)
}.build()
)
val intent: Intent = RemoteInputIntentHelper.createActionRemoteInputIntent()
RemoteInputIntentHelper.putRemoteInputsExtra(intent, remoteInputs)
launcher.launch(intent)
}
)