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