Skip to content

Instantly share code, notes, and snippets.

@pauloaapereira
Created March 16, 2021 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauloaapereira/3786906a77acd4f75b8b3b1aed391d8a to your computer and use it in GitHub Desktop.
Save pauloaapereira/3786906a77acd4f75b8b3b1aed391d8a to your computer and use it in GitHub Desktop.
Android Dev Challenge - Week 3 - Bloom - A Full Development Overview - 5
@ExperimentalComposeUiApi
@Composable
fun BloomTextInput(
modifier: Modifier = Modifier,
label: String,
value: String = "",
@DrawableRes leadingIcon: Int? = null,
keyboardType: KeyboardType = KeyboardType.Text,
onValueChanged: (String) -> Unit = {}
) {
val softwareKeyboardController = LocalSoftwareKeyboardController.current
val view = LocalView.current
OutlinedTextField(
modifier = modifier.fillMaxWidth(.9f),
value = value,
onValueChange = onValueChanged,
label = { Text(text = label) },
leadingIcon = leadingIcon?.let {
{
Icon(
painter = painterResource(id = leadingIcon),
contentDescription = label
)
}
},
textStyle = MaterialTheme.typography.body1,
singleLine = true,
keyboardActions = KeyboardActions(
onDone = {
softwareKeyboardController?.hideSoftwareKeyboard()
view.clearFocus()
}
),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, keyboardType = keyboardType),
colors = TextFieldDefaults.outlinedTextFieldColors(
textColor = MaterialTheme.colors.onBackground,
focusedBorderColor = MaterialTheme.colors.onSurface,
focusedLabelColor = MaterialTheme.colors.onBackground,
unfocusedLabelColor = MaterialTheme.colors.onBackground,
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment