@@ -38,7 +38,9 @@ import io.element.android.libraries.architecture.AsyncData
38
38
import io.element.android.libraries.designsystem.atomic.atoms.ElementLogoAtom
39
39
import io.element.android.libraries.designsystem.atomic.atoms.ElementLogoAtomSize
40
40
import io.element.android.libraries.designsystem.atomic.molecules.ButtonColumnMolecule
41
+ import io.element.android.libraries.designsystem.atomic.pages.FlowStepPage
41
42
import io.element.android.libraries.designsystem.atomic.pages.OnBoardingPage
43
+ import io.element.android.libraries.designsystem.components.BigIcon
42
44
import io.element.android.libraries.designsystem.preview.ElementPreview
43
45
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
44
46
import io.element.android.libraries.designsystem.theme.components.Button
@@ -58,6 +60,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
58
60
@Composable
59
61
fun OnBoardingView (
60
62
state : OnBoardingState ,
63
+ onBackPressed : () -> Unit ,
61
64
onSignInWithQrCode : () -> Unit ,
62
65
onSignIn : (mustChooseAccountProvider: Boolean ) -> Unit ,
63
66
onCreateAccount : () -> Unit ,
@@ -67,6 +70,52 @@ fun OnBoardingView(
67
70
onCreateAccountContinue : (url: String ) -> Unit ,
68
71
onReportProblem : () -> Unit ,
69
72
modifier : Modifier = Modifier ,
73
+ ) {
74
+ val loginView = @Composable {
75
+ LoginModeView (
76
+ loginMode = state.loginMode,
77
+ onClearError = {
78
+ state.eventSink(OnBoardingEvents .ClearError )
79
+ },
80
+ onLearnMoreClick = onLearnMoreClick,
81
+ onOidcDetails = onOidcDetails,
82
+ onNeedLoginPassword = onNeedLoginPassword,
83
+ onCreateAccountContinue = onCreateAccountContinue,
84
+ )
85
+ }
86
+ val buttons = @Composable {
87
+ OnBoardingButtons (
88
+ state = state,
89
+ onSignInWithQrCode = onSignInWithQrCode,
90
+ onSignIn = onSignIn,
91
+ onCreateAccount = onCreateAccount,
92
+ onReportProblem = onReportProblem,
93
+ )
94
+ }
95
+
96
+ if (state.isAddingAccount) {
97
+ AddOtherAccountScaffold (
98
+ modifier = modifier,
99
+ loginView = loginView,
100
+ buttons = buttons,
101
+ onBackPressed = onBackPressed,
102
+ )
103
+ } else {
104
+ AddFirstAccountScaffold (
105
+ modifier = modifier,
106
+ state = state,
107
+ loginView = loginView,
108
+ buttons = buttons,
109
+ )
110
+ }
111
+ }
112
+
113
+ @Composable
114
+ private fun AddFirstAccountScaffold (
115
+ state : OnBoardingState ,
116
+ loginView : @Composable () -> Unit ,
117
+ buttons : @Composable () -> Unit ,
118
+ modifier : Modifier = Modifier ,
70
119
) {
71
120
OnBoardingPage (
72
121
modifier = modifier,
@@ -79,29 +128,32 @@ fun OnBoardingView(
79
128
} else {
80
129
OnBoardingContent (state = state)
81
130
}
82
- LoginModeView (
83
- loginMode = state.loginMode,
84
- onClearError = {
85
- state.eventSink(OnBoardingEvents .ClearError )
86
- },
87
- onLearnMoreClick = onLearnMoreClick,
88
- onOidcDetails = onOidcDetails,
89
- onNeedLoginPassword = onNeedLoginPassword,
90
- onCreateAccountContinue = onCreateAccountContinue,
91
- )
131
+ loginView()
92
132
},
93
133
footer = {
94
- OnBoardingButtons (
95
- state = state,
96
- onSignInWithQrCode = onSignInWithQrCode,
97
- onSignIn = onSignIn,
98
- onCreateAccount = onCreateAccount,
99
- onReportProblem = onReportProblem,
100
- )
134
+ buttons()
101
135
}
102
136
)
103
137
}
104
138
139
+ @Composable
140
+ private fun AddOtherAccountScaffold (
141
+ loginView : @Composable () -> Unit ,
142
+ buttons : @Composable () -> Unit ,
143
+ onBackPressed : () -> Unit ,
144
+ modifier : Modifier = Modifier ,
145
+ ) {
146
+ FlowStepPage (
147
+ modifier = modifier,
148
+ // TODO i18n
149
+ title = " Add account" ,
150
+ iconStyle = BigIcon .Style .Default (CompoundIcons .HomeSolid ()),
151
+ buttons = { buttons() },
152
+ content = loginView,
153
+ onBackClick = onBackPressed,
154
+ )
155
+ }
156
+
105
157
@Composable
106
158
private fun OnBoardingContent (state : OnBoardingState ) {
107
159
Box (
@@ -226,27 +278,29 @@ private fun OnBoardingButtons(
226
278
.fillMaxWidth()
227
279
)
228
280
}
229
- if (state.canReportBug) {
230
- // Add a report problem text button. Use a Text since we need a special theme here.
231
- Text (
232
- modifier = Modifier
233
- .clickable(onClick = onReportProblem)
234
- .padding(16 .dp),
235
- text = stringResource(id = CommonStrings .common_report_a_problem),
236
- style = ElementTheme .typography.fontBodySmRegular,
237
- color = ElementTheme .colors.textSecondary,
238
- )
239
- } else {
240
- Text (
241
- modifier = Modifier
242
- .clickable {
243
- state.eventSink(OnBoardingEvents .OnVersionClick )
244
- }
245
- .padding(16 .dp),
246
- text = stringResource(id = R .string.screen_onboarding_app_version, state.version),
247
- style = ElementTheme .typography.fontBodySmRegular,
248
- color = ElementTheme .colors.textSecondary,
249
- )
281
+ if (state.isAddingAccount.not ()) {
282
+ if (state.canReportBug) {
283
+ // Add a report problem text button. Use a Text since we need a special theme here.
284
+ Text (
285
+ modifier = Modifier
286
+ .clickable(onClick = onReportProblem)
287
+ .padding(16 .dp),
288
+ text = stringResource(id = CommonStrings .common_report_a_problem),
289
+ style = ElementTheme .typography.fontBodySmRegular,
290
+ color = ElementTheme .colors.textSecondary,
291
+ )
292
+ } else {
293
+ Text (
294
+ modifier = Modifier
295
+ .clickable {
296
+ state.eventSink(OnBoardingEvents .OnVersionClick )
297
+ }
298
+ .padding(16 .dp),
299
+ text = stringResource(id = R .string.screen_onboarding_app_version, state.version),
300
+ style = ElementTheme .typography.fontBodySmRegular,
301
+ color = ElementTheme .colors.textSecondary,
302
+ )
303
+ }
250
304
}
251
305
}
252
306
}
@@ -258,6 +312,7 @@ internal fun OnBoardingViewPreview(
258
312
) = ElementPreview {
259
313
OnBoardingView (
260
314
state = state,
315
+ onBackPressed = {},
261
316
onSignInWithQrCode = {},
262
317
onSignIn = {},
263
318
onCreateAccount = {},
0 commit comments