@@ -32,6 +32,7 @@ import androidx.compose.material3.TextField
3232import androidx.compose.material3.TopAppBarDefaults
3333import androidx.compose.runtime.Composable
3434import androidx.compose.runtime.LaunchedEffect
35+ import androidx.compose.runtime.State
3536import androidx.compose.runtime.getValue
3637import androidx.compose.runtime.remember
3738import androidx.compose.runtime.rememberCoroutineScope
@@ -68,38 +69,16 @@ import kotlinx.coroutines.flow.onEach
6869import kotlinx.coroutines.launch
6970import kotlinx.coroutines.withContext
7071
71- @OptIn(ExperimentalMaterial3Api :: class , ExperimentalLifecycleComposeApi ::class )
72+ @OptIn(ExperimentalLifecycleComposeApi ::class )
7273@Composable
7374internal fun AddNewUserRoute (
7475 configAppBar : ConfigAppBar ,
7576 onBackClick : () -> Unit ,
7677 modifier : Modifier = Modifier ,
7778 viewModel : AddVM = hiltViewModel(),
7879) {
79- val currentOnBackClick by rememberUpdatedState(onBackClick)
80-
81- val title = stringResource(id = R .string.add_new_user)
82- val colors = TopAppBarDefaults .centerAlignedTopAppBarColors()
83- val appBarState = remember(colors) {
84- AppBarState (
85- title = title,
86- actions = {},
87- navigationIcon = {
88- IconButton (onClick = { currentOnBackClick() }) {
89- Icon (
90- imageVector = Icons .Filled .ArrowBack ,
91- contentDescription = " Back"
92- )
93- }
94- },
95- colors = colors
96- )
97- }
98- OnLifecycleEvent (configAppBar, appBarState) { _, event ->
99- if (event == Lifecycle .Event .ON_START ) {
100- configAppBar(appBarState)
101- }
102- }
80+ val currentOnBackClickState = rememberUpdatedState(onBackClick)
81+ ConfigAppBar (currentOnBackClickState, configAppBar)
10382
10483 val intentChannel = remember { Channel <ViewIntent >(Channel .UNLIMITED ) }
10584 LaunchedEffect (Unit ) {
@@ -133,7 +112,7 @@ internal fun AddNewUserRoute(
133112 }
134113 scope.launch {
135114 delay(200 )
136- currentOnBackClick ()
115+ currentOnBackClickState.value ()
137116 }
138117 }
139118 }
@@ -156,6 +135,36 @@ internal fun AddNewUserRoute(
156135 )
157136}
158137
138+ @Composable
139+ @OptIn(ExperimentalMaterial3Api ::class )
140+ private fun ConfigAppBar (
141+ currentOnBackClickState : State <() -> Unit >,
142+ configAppBar : ConfigAppBar
143+ ) {
144+ val title = stringResource(id = R .string.add_new_user)
145+ val colors = TopAppBarDefaults .centerAlignedTopAppBarColors()
146+ val appBarState = remember(colors) {
147+ AppBarState (
148+ title = title,
149+ actions = {},
150+ navigationIcon = {
151+ IconButton (onClick = { currentOnBackClickState.value() }) {
152+ Icon (
153+ imageVector = Icons .Filled .ArrowBack ,
154+ contentDescription = " Back"
155+ )
156+ }
157+ },
158+ colors = colors
159+ )
160+ }
161+ OnLifecycleEvent (configAppBar, appBarState) { _, event ->
162+ if (event == Lifecycle .Event .ON_START ) {
163+ configAppBar(appBarState)
164+ }
165+ }
166+ }
167+
159168@Composable
160169private fun AddNewUserContent (
161170 viewState : ViewState ,
0 commit comments