@@ -12,6 +12,10 @@ import androidx.compose.material3.MaterialTheme
12
12
import androidx.compose.material3.Text
13
13
import androidx.compose.material3.TextField
14
14
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
15
19
import androidx.compose.ui.Alignment
16
20
import androidx.compose.ui.Modifier
17
21
import androidx.compose.ui.res.stringResource
@@ -29,33 +33,37 @@ fun LoginScreen(modifier: Modifier = Modifier) {
29
33
verticalArrangement = Arrangement .spacedBy(8 .dp, Alignment .CenterVertically ),
30
34
horizontalAlignment = Alignment .CenterHorizontally ,
31
35
) {
36
+ var userId by remember { mutableStateOf(" " ) }
37
+ var password by remember { mutableStateOf(" " ) }
38
+ var loginEnabled by remember { mutableStateOf(false ) }
39
+
32
40
TextField (
33
- value = " " , // TODO 入力した文字列が表示されるようにする
41
+ value = userId,
34
42
onValueChange = { value ->
35
- // TODO 状態を更新する
43
+ userId = value
44
+ loginEnabled = userId.length >= 4 && password.length >= 8
36
45
},
37
46
modifier = Modifier .fillMaxWidth(),
38
47
label = { Text (text = stringResource(R .string.user_id)) },
39
48
keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .Ascii ),
40
- singleLine = true ,
41
49
)
42
50
43
51
TextField (
44
- value = " " , // TODO 入力した文字列が表示されるようにする
52
+ value = password,
45
53
onValueChange = { value ->
46
- // TODO 状態を更新する
54
+ password = value
55
+ loginEnabled = userId.length >= 4 && password.length >= 8
47
56
},
48
57
modifier = Modifier .fillMaxWidth(),
49
58
label = { Text (text = stringResource(R .string.password)) },
50
59
visualTransformation = PasswordVisualTransformation (),
51
60
keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .Password ),
52
- singleLine = true ,
53
61
)
54
62
55
63
Button (
56
64
onClick = {},
57
65
modifier = Modifier .fillMaxWidth(),
58
- enabled = true , // TODO ユーザーIDが4文字以上、かつパスワードが8文字以上入力されたら押せるようにする
66
+ enabled = loginEnabled,
59
67
) {
60
68
Text (text = stringResource(R .string.login))
61
69
}
0 commit comments