@@ -2,7 +2,6 @@ package com.flexa.identity.create_id
22
33import android.content.res.Configuration
44import androidx.compose.animation.AnimatedContent
5- import androidx.compose.animation.ExperimentalAnimationApi
65import androidx.compose.animation.SizeTransform
76import androidx.compose.animation.expandVertically
87import androidx.compose.animation.fadeIn
@@ -12,7 +11,7 @@ import androidx.compose.animation.slideInHorizontally
1211import androidx.compose.animation.slideInVertically
1312import androidx.compose.animation.slideOutHorizontally
1413import androidx.compose.animation.slideOutVertically
15- import androidx.compose.animation.with
14+ import androidx.compose.animation.togetherWith
1615import androidx.compose.foundation.background
1716import androidx.compose.foundation.clickable
1817import androidx.compose.foundation.focusable
@@ -109,7 +108,7 @@ import java.util.Date
109108
110109
111110@OptIn(
112- ExperimentalComposeUiApi ::class , ExperimentalAnimationApi :: class ,
111+ ExperimentalComposeUiApi ::class ,
113112 ExperimentalMaterial3Api ::class
114113)
115114@Composable
@@ -118,6 +117,7 @@ internal fun CreateId(
118117 viewModel : CreateIdViewModel ,
119118 userVM : UserViewModel ,
120119 toBack : () -> Unit = {},
120+ toPrivacy : () -> Unit = {},
121121 toTermsOfUse : () -> Unit = {},
122122 toCoppa : () -> Unit = {},
123123 toContinue : () -> Unit = {},
@@ -159,6 +159,7 @@ internal fun CreateId(
159159 toContinue()
160160 viewModel.state.value = CreateIdViewModel .State .General
161161 }
162+
162163 else -> {}
163164 }
164165 }
@@ -201,7 +202,8 @@ internal fun CreateId(
201202 ) {
202203 TextButton (
203204 modifier = Modifier .padding(start = 0 .dp),
204- onClick = { viewModel.state.value = CreateIdViewModel .State .FlexaPrivacy }) {
205+ onClick = toPrivacy
206+ ) {
205207 Text (text = stringResource(id = R .string.about_flexa_and_privacy))
206208 }
207209 val progress by viewModel.progress.collectAsStateWithLifecycle()
@@ -231,11 +233,11 @@ internal fun CreateId(
231233 transitionSpec = {
232234 if (targetState) {
233235 slideInHorizontally { width -> width } +
234- fadeIn() with slideOutHorizontally()
236+ fadeIn() togetherWith slideOutHorizontally()
235237 { width -> - width } + fadeOut()
236238 } else {
237239 slideInHorizontally { width -> - width } +
238- fadeIn() with slideOutHorizontally()
240+ fadeIn() togetherWith slideOutHorizontally()
239241 { width -> width } + fadeOut()
240242 }.using(SizeTransform (clip = false ))
241243 }, label = stringResource(R .string.get_started)
@@ -280,7 +282,14 @@ internal fun CreateId(
280282 }
281283 val keyboardController = LocalSoftwareKeyboardController .current
282284 KeyboardHandler ()
283- val firstNameTextValue = remember { mutableStateOf(TextFieldValue (firstName)) }
285+ val firstNameTextValue = remember {
286+ mutableStateOf(
287+ TextFieldValue (
288+ text = firstName,
289+ selection = TextRange (firstName.length)
290+ )
291+ )
292+ }
284293 TextField (
285294 modifier = Modifier
286295 .fillMaxWidth()
@@ -314,18 +323,15 @@ internal fun CreateId(
314323 transitionSpec = {
315324 if (targetState.length > initialState.length) {
316325 slideInVertically { width -> width } +
317- fadeIn() with slideOutVertically()
326+ fadeIn() togetherWith slideOutVertically()
318327 { width -> - width } + fadeOut()
319328 } else {
320329 slideInVertically { width -> - width } +
321- fadeIn() with slideOutVertically()
330+ fadeIn() togetherWith slideOutVertically()
322331 { width -> width } + fadeOut()
323332 }.using(SizeTransform (clip = false ))
324333 }, label = " Text"
325- ) { state ->
326- state
327- Text (text = text)
328- }
334+ ) { state -> Text (text = state) }
329335 },
330336 value = if (nameExpanded) firstNameTextValue.value
331337 else {
@@ -337,12 +343,20 @@ internal fun CreateId(
337343 )
338344 },
339345 onValueChange = {
340- if (firstNameBlocked) {
341- firstNameBlocked = false
342- } else {
343- firstNameTextValue.value = it
344- firstNameError = it.text.isEmpty()
345- userVM.userData.value = userVM.userData.value.copy(firstName = it.text)
346+ when {
347+ firstNameTextValue.value.text.isEmpty() -> {
348+ firstNameBlocked = false
349+ firstNameTextValue.value = it
350+ firstNameError = it.text.isEmpty()
351+ userVM.userData.value = userVM.userData.value.copy(firstName = it.text)
352+ }
353+
354+ firstNameBlocked -> firstNameBlocked = false
355+ else -> {
356+ firstNameTextValue.value = it
357+ firstNameError = it.text.isEmpty()
358+ userVM.userData.value = userVM.userData.value.copy(firstName = it.text)
359+ }
346360 }
347361 },
348362 leadingIcon = {
@@ -366,7 +380,14 @@ internal fun CreateId(
366380 enter = expandVertically(),
367381 exit = shrinkVertically()
368382 ) {
369- val lastNameTextValue = remember { mutableStateOf(TextFieldValue (lastName)) }
383+ val lastNameTextValue = remember {
384+ mutableStateOf(
385+ TextFieldValue (
386+ text = lastName,
387+ selection = TextRange (lastName.length)
388+ )
389+ )
390+ }
370391 TextField (
371392 modifier = Modifier
372393 .focusRequester(lastNameFocus)
@@ -390,10 +411,7 @@ internal fun CreateId(
390411 style = TextStyle (color = MaterialTheme .colorScheme.error)
391412 )
392413 },
393- value = TextFieldValue (
394- text = lastName,
395- selection = TextRange (lastName.length)
396- ),
414+ value = lastNameTextValue.value,
397415 maxLines = 1 ,
398416 label = { Text (text = stringResource(id = R .string.last_name)) },
399417 onValueChange = {
0 commit comments