Created
March 16, 2021 18:53
-
-
Save pauloaapereira/3786906a77acd4f75b8b3b1aed391d8a to your computer and use it in GitHub Desktop.
Android Dev Challenge - Week 3 - Bloom - A Full Development Overview - 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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