@@ -31,24 +31,20 @@ import androidx.compose.foundation.layout.wrapContentSize
31
31
import androidx.compose.foundation.lazy.LazyColumn
32
32
import androidx.compose.foundation.text.KeyboardActions
33
33
import androidx.compose.foundation.text.KeyboardOptions
34
- import androidx.compose.material.ContentAlpha
35
- import androidx.compose.material.Icon
36
- import androidx.compose.material.IconButton
37
- import androidx.compose.material.LocalContentAlpha
38
- import androidx.compose.material.LocalTextStyle
39
- import androidx.compose.material.MaterialTheme
40
- import androidx.compose.material.OutlinedButton
41
- import androidx.compose.material.OutlinedTextField
42
- import androidx.compose.material.Surface
43
- import androidx.compose.material.Text
44
- import androidx.compose.material.TextField
45
- import androidx.compose.material.TopAppBar
46
34
import androidx.compose.material.icons.Icons
47
35
import androidx.compose.material.icons.filled.ChevronLeft
48
36
import androidx.compose.material.icons.filled.Visibility
49
37
import androidx.compose.material.icons.filled.VisibilityOff
38
+ import androidx.compose.material3.CenterAlignedTopAppBar
39
+ import androidx.compose.material3.ExperimentalMaterial3Api
40
+ import androidx.compose.material3.Icon
41
+ import androidx.compose.material3.IconButton
42
+ import androidx.compose.material3.MaterialTheme
43
+ import androidx.compose.material3.OutlinedButton
44
+ import androidx.compose.material3.OutlinedTextField
45
+ import androidx.compose.material3.Surface
46
+ import androidx.compose.material3.Text
50
47
import androidx.compose.runtime.Composable
51
- import androidx.compose.runtime.CompositionLocalProvider
52
48
import androidx.compose.runtime.mutableStateOf
53
49
import androidx.compose.runtime.remember
54
50
import androidx.compose.runtime.saveable.rememberSaveable
@@ -60,17 +56,18 @@ import androidx.compose.ui.text.input.ImeAction
60
56
import androidx.compose.ui.text.input.KeyboardType
61
57
import androidx.compose.ui.text.input.PasswordVisualTransformation
62
58
import androidx.compose.ui.text.input.VisualTransformation
63
- import androidx.compose.ui.text.style.TextAlign
64
59
import androidx.compose.ui.tooling.preview.Preview
65
60
import androidx.compose.ui.unit.dp
66
61
import com.example.compose.jetsurvey.R
62
+ import com.example.compose.jetsurvey.theme.JetsurveyTheme
63
+ import com.example.compose.jetsurvey.theme.stronglyDeemphasizedAlpha
67
64
68
65
@Composable
69
66
fun SignInSignUpScreen (
70
67
onSignedInAsGuest : () -> Unit ,
71
68
modifier : Modifier = Modifier ,
72
69
contentPadding : PaddingValues = PaddingValues (),
73
- content : @Composable() () -> Unit
70
+ content : @Composable () -> Unit
74
71
) {
75
72
LazyColumn (
76
73
modifier = modifier,
@@ -96,13 +93,13 @@ fun SignInSignUpScreen(
96
93
}
97
94
}
98
95
96
+ @OptIn(ExperimentalMaterial3Api ::class ) // CenterAlignedTopAppBar is experimental in m3
99
97
@Composable
100
98
fun SignInSignUpTopAppBar (topAppBarText : String , onBackPressed : () -> Unit ) {
101
- TopAppBar (
99
+ CenterAlignedTopAppBar (
102
100
title = {
103
101
Text (
104
102
text = topAppBarText,
105
- textAlign = TextAlign .Center ,
106
103
modifier = Modifier
107
104
.fillMaxSize()
108
105
.wrapContentSize(Alignment .Center )
@@ -112,19 +109,19 @@ fun SignInSignUpTopAppBar(topAppBarText: String, onBackPressed: () -> Unit) {
112
109
IconButton (onClick = onBackPressed) {
113
110
Icon (
114
111
imageVector = Icons .Filled .ChevronLeft ,
115
- contentDescription = stringResource(id = R .string.back)
112
+ contentDescription = stringResource(id = R .string.back),
113
+ tint = MaterialTheme .colorScheme.primary
116
114
)
117
115
}
118
116
},
119
117
// We need to balance the navigation icon, so we add a spacer.
120
118
actions = {
121
119
Spacer (modifier = Modifier .width(68 .dp))
122
120
},
123
- backgroundColor = MaterialTheme .colors.surface,
124
- elevation = 0 .dp
125
121
)
126
122
}
127
123
124
+ @OptIn(ExperimentalMaterial3Api ::class ) // OutlinedTextField is experimental in m3
128
125
@Composable
129
126
fun Email (
130
127
emailState : TextFieldState = remember { EmailState () },
@@ -137,12 +134,10 @@ fun Email(
137
134
emailState.text = it
138
135
},
139
136
label = {
140
- CompositionLocalProvider (LocalContentAlpha provides ContentAlpha .medium) {
141
- Text (
142
- text = stringResource(id = R .string.email),
143
- style = MaterialTheme .typography.body2
144
- )
145
- }
137
+ Text (
138
+ text = stringResource(id = R .string.email),
139
+ style = MaterialTheme .typography.bodyMedium,
140
+ )
146
141
},
147
142
modifier = Modifier
148
143
.fillMaxWidth()
@@ -152,7 +147,7 @@ fun Email(
152
147
emailState.enableShowErrors()
153
148
}
154
149
},
155
- textStyle = MaterialTheme .typography.body2 ,
150
+ textStyle = MaterialTheme .typography.bodyMedium ,
156
151
isError = emailState.showErrors(),
157
152
keyboardOptions = KeyboardOptions .Default .copy(
158
153
imeAction = imeAction,
@@ -162,12 +157,13 @@ fun Email(
162
157
onDone = {
163
158
onImeAction()
164
159
}
165
- )
160
+ ),
166
161
)
167
162
168
163
emailState.getError()?.let { error -> TextFieldError (textError = error) }
169
164
}
170
165
166
+ @OptIn(ExperimentalMaterial3Api ::class ) // OutlinedTextField is experimental in m3
171
167
@Composable
172
168
fun Password (
173
169
label : String ,
@@ -191,14 +187,12 @@ fun Password(
191
187
passwordState.enableShowErrors()
192
188
}
193
189
},
194
- textStyle = MaterialTheme .typography.body2 ,
190
+ textStyle = MaterialTheme .typography.bodyMedium ,
195
191
label = {
196
- CompositionLocalProvider (LocalContentAlpha provides ContentAlpha .medium) {
197
- Text (
198
- text = label,
199
- style = MaterialTheme .typography.body2
200
- )
201
- }
192
+ Text (
193
+ text = label,
194
+ style = MaterialTheme .typography.bodyMedium,
195
+ )
202
196
},
203
197
trailingIcon = {
204
198
if (showPassword.value) {
@@ -231,7 +225,7 @@ fun Password(
231
225
onDone = {
232
226
onImeAction()
233
227
}
234
- )
228
+ ),
235
229
)
236
230
237
231
passwordState.getError()?.let { error -> TextFieldError (textError = error) }
@@ -247,7 +241,7 @@ fun TextFieldError(textError: String) {
247
241
Text (
248
242
text = textError,
249
243
modifier = Modifier .fillMaxWidth(),
250
- style = LocalTextStyle .current.copy( color = MaterialTheme .colors .error)
244
+ color = MaterialTheme .colorScheme .error
251
245
)
252
246
}
253
247
}
@@ -261,20 +255,17 @@ fun OrSignInAsGuest(
261
255
modifier = modifier,
262
256
horizontalAlignment = Alignment .CenterHorizontally
263
257
) {
264
- Surface {
265
- CompositionLocalProvider (LocalContentAlpha provides ContentAlpha .medium) {
266
- Text (
267
- text = stringResource(id = R .string.or ),
268
- style = MaterialTheme .typography.subtitle2,
269
- modifier = Modifier .paddingFromBaseline(top = 25 .dp)
270
- )
271
- }
272
- }
258
+ Text (
259
+ text = stringResource(id = R .string.or ),
260
+ style = MaterialTheme .typography.titleSmall,
261
+ color = MaterialTheme .colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha),
262
+ modifier = Modifier .paddingFromBaseline(top = 25 .dp)
263
+ )
273
264
OutlinedButton (
274
265
onClick = onSignedInAsGuest,
275
266
modifier = Modifier
276
267
.fillMaxWidth()
277
- .padding(top = 20 .dp, bottom = 24 .dp)
268
+ .padding(top = 20 .dp, bottom = 24 .dp),
278
269
) {
279
270
Text (text = stringResource(id = R .string.sign_in_guest))
280
271
}
@@ -284,8 +275,12 @@ fun OrSignInAsGuest(
284
275
@Preview
285
276
@Composable
286
277
fun SignInSignUpScreenPreview () {
287
- SignInSignUpScreen (
288
- onSignedInAsGuest = {},
289
- content = {}
290
- )
278
+ JetsurveyTheme {
279
+ Surface {
280
+ SignInSignUpScreen (
281
+ onSignedInAsGuest = {},
282
+ content = {}
283
+ )
284
+ }
285
+ }
291
286
}
0 commit comments