Skip to content

Commit 177c3cf

Browse files
committed
LoginScreenのテキスト入力とボタンの状態変更を実装
1 parent 397828f commit 177c3cf

File tree

1 file changed

+15
-7
lines changed
  • app/login/src/main/java/jp/co/mixi/androidtraining/login

1 file changed

+15
-7
lines changed

app/login/src/main/java/jp/co/mixi/androidtraining/login/LoginScreen.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import androidx.compose.material3.MaterialTheme
1212
import androidx.compose.material3.Text
1313
import androidx.compose.material3.TextField
1414
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.getValue
16+
import androidx.compose.runtime.mutableStateOf
17+
import androidx.compose.runtime.remember
18+
import androidx.compose.runtime.setValue
1519
import androidx.compose.ui.Alignment
1620
import androidx.compose.ui.Modifier
1721
import androidx.compose.ui.res.stringResource
@@ -29,33 +33,37 @@ fun LoginScreen(modifier: Modifier = Modifier) {
2933
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
3034
horizontalAlignment = Alignment.CenterHorizontally,
3135
) {
36+
var userId by remember { mutableStateOf("") }
37+
var password by remember { mutableStateOf("") }
38+
var loginEnabled by remember { mutableStateOf(false) }
39+
3240
TextField(
33-
value = "", // TODO 入力した文字列が表示されるようにする
41+
value = userId,
3442
onValueChange = { value ->
35-
// TODO 状態を更新する
43+
userId = value
44+
loginEnabled = userId.length >= 4 && password.length >= 8
3645
},
3746
modifier = Modifier.fillMaxWidth(),
3847
label = { Text(text = stringResource(R.string.user_id)) },
3948
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Ascii),
40-
singleLine = true,
4149
)
4250

4351
TextField(
44-
value = "", // TODO 入力した文字列が表示されるようにする
52+
value = password,
4553
onValueChange = { value ->
46-
// TODO 状態を更新する
54+
password = value
55+
loginEnabled = userId.length >= 4 && password.length >= 8
4756
},
4857
modifier = Modifier.fillMaxWidth(),
4958
label = { Text(text = stringResource(R.string.password)) },
5059
visualTransformation = PasswordVisualTransformation(),
5160
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
52-
singleLine = true,
5361
)
5462

5563
Button(
5664
onClick = {},
5765
modifier = Modifier.fillMaxWidth(),
58-
enabled = true, // TODO ユーザーIDが4文字以上、かつパスワードが8文字以上入力されたら押せるようにする
66+
enabled = loginEnabled,
5967
) {
6068
Text(text = stringResource(R.string.login))
6169
}

0 commit comments

Comments
 (0)