auto focus
This commit is contained in:
parent
b5610ae7b0
commit
59839fe8ca
1 changed files with 37 additions and 11 deletions
|
@ -29,15 +29,22 @@ import androidx.compose.material3.Text
|
|||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
@ -198,13 +205,19 @@ fun TransactionList(viewModel: WalletViewModel) {
|
|||
}
|
||||
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun TransactionDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (String, Int) -> Unit
|
||||
) {
|
||||
var label by rememberSaveable { mutableStateOf("") }
|
||||
var value by rememberSaveable { mutableStateOf("0") }
|
||||
var value by rememberSaveable { mutableStateOf("") }
|
||||
val (firstFocus, secondFocus) = remember { FocusRequester.createRefs() }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
firstFocus.requestFocus()
|
||||
}
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = {
|
||||
|
@ -225,8 +238,13 @@ fun TransactionDialog(
|
|||
onValueChange = { label = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
.weight(1f)
|
||||
.focusRequester(firstFocus)
|
||||
.focusProperties { next = secondFocus },
|
||||
supportingText = { Text("Label") },
|
||||
keyboardOptions = KeyboardOptions(
|
||||
imeAction = ImeAction.Next
|
||||
),
|
||||
singleLine = true
|
||||
)
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
|
@ -235,9 +253,13 @@ fun TransactionDialog(
|
|||
onValueChange = { value = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
.weight(1f)
|
||||
.focusRequester(secondFocus),
|
||||
supportingText = { Text("Value") },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Number,
|
||||
imeAction = ImeAction.Done
|
||||
),
|
||||
singleLine = true
|
||||
)
|
||||
}
|
||||
|
@ -245,15 +267,19 @@ fun TransactionDialog(
|
|||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
TextButton(onClick = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
label = ""
|
||||
onDismiss()
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
Text(text = "Cancel")
|
||||
}
|
||||
TextButton(onClick = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onConfirm(label, (value.toFloat() * 100).toInt())
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
Text("Create transaction")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue