-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathCustomSlotsThemingDemoActivity.kt
More file actions
1105 lines (1009 loc) · 36.1 KB
/
CustomSlotsThemingDemoActivity.kt
File metadata and controls
1105 lines (1009 loc) · 36.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.firebaseui.android.demo
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.firebase.ui.auth.AuthException
import com.firebase.ui.auth.FirebaseAuthUI
import com.firebase.ui.auth.configuration.AuthUIConfiguration
import com.firebase.ui.auth.configuration.PasswordRule
import com.firebase.ui.auth.configuration.authUIConfiguration
import com.firebase.ui.auth.configuration.auth_provider.AuthProvider
import com.firebase.ui.auth.configuration.string_provider.LocalAuthUIStringProvider
import com.firebase.ui.auth.configuration.theme.AuthUITheme
import com.firebase.ui.auth.configuration.theme.ProviderStyleDefaults
import com.firebase.ui.auth.configuration.string_provider.DefaultAuthUIStringProvider
import com.firebase.ui.auth.ui.components.AuthProviderButton
import com.firebase.ui.auth.ui.screens.email.EmailAuthContentState
import com.firebase.ui.auth.ui.screens.email.EmailAuthMode
import com.firebase.ui.auth.ui.screens.email.EmailAuthScreen
import com.firebase.ui.auth.ui.screens.phone.PhoneAuthContentState
import com.firebase.ui.auth.ui.screens.phone.PhoneAuthScreen
import com.firebase.ui.auth.ui.screens.phone.PhoneAuthStep
import com.google.firebase.auth.AuthResult
/**
* Demo activity showcasing custom slots and theming capabilities:
* - EmailAuthScreen with custom slot UI
* - PhoneAuthScreen with custom slot UI
* - Provider button shape customization with global and per-provider overrides
* - AuthUITheme.fromMaterialTheme() with custom ProviderStyle overrides
*/
class CustomSlotsThemingDemoActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val authUI = FirebaseAuthUI.getInstance()
val appContext = applicationContext
// Configuration for email authentication
val emailConfiguration = authUIConfiguration {
context = appContext
providers {
provider(
AuthProvider.Email(
isDisplayNameRequired = true,
isNewAccountsAllowed = true,
isEmailLinkSignInEnabled = false,
emailLinkActionCodeSettings = null,
isEmailLinkForceSameDeviceEnabled = false,
minimumPasswordLength = 8,
passwordValidationRules = listOf(
PasswordRule.MinimumLength(8),
PasswordRule.RequireLowercase,
PasswordRule.RequireUppercase,
PasswordRule.RequireDigit
)
)
)
}
tosUrl = "https://policies.google.com/terms"
privacyPolicyUrl = "https://policies.google.com/privacy"
}
// Configuration for phone authentication
val phoneConfiguration = authUIConfiguration {
context = appContext
providers {
provider(
AuthProvider.Phone(
defaultNumber = null,
defaultCountryCode = "US",
allowedCountries = emptyList(),
smsCodeLength = 6,
timeout = 60L,
isInstantVerificationEnabled = true
)
)
}
}
setContent {
// Custom theme using fromMaterialTheme() with custom provider styles
CustomAuthUITheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
var selectedDemo by remember { mutableStateOf(DemoType.Email) }
Column(
modifier = Modifier
.fillMaxSize()
.systemBarsPadding()
) {
// Demo selector tabs
DemoSelector(
selectedDemo = selectedDemo,
onDemoSelected = { selectedDemo = it }
)
// Show selected demo
when (selectedDemo) {
DemoType.Email -> EmailAuthDemo(
authUI = authUI,
configuration = emailConfiguration,
context = appContext
)
DemoType.Phone -> PhoneAuthDemo(
authUI = authUI,
configuration = phoneConfiguration,
context = appContext
)
DemoType.ShapeCustomization -> ShapeCustomizationDemo()
}
}
}
}
}
}
}
enum class DemoType {
Email,
Phone,
ShapeCustomization
}
@Composable
fun CustomAuthUITheme(content: @Composable () -> Unit) {
// Use Material Theme colors
MaterialTheme {
// UPDATED: Now uses ProviderStyleDefaults and the new providerButtonShape API
// Apply custom theme using fromMaterialTheme with global button shape
val authTheme = AuthUITheme.fromMaterialTheme(
providerButtonShape = RoundedCornerShape(12.dp) // Global shape for all buttons
)
AuthUITheme(theme = authTheme) {
content()
}
}
}
@Composable
fun DemoSelector(
selectedDemo: DemoType,
onDemoSelected: (DemoType) -> Unit
) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primaryContainer
)
) {
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
text = "Custom Slots & Theming Demo",
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onPrimaryContainer
)
Text(
text = "Select a demo to see custom UI implementations using slot APIs",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onPrimaryContainer
)
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
FilterChip(
selected = selectedDemo == DemoType.Email,
onClick = { onDemoSelected(DemoType.Email) },
label = { Text("Email Auth") },
modifier = Modifier.weight(1f)
)
FilterChip(
selected = selectedDemo == DemoType.Phone,
onClick = { onDemoSelected(DemoType.Phone) },
label = { Text("Phone Auth") },
modifier = Modifier.weight(1f)
)
}
FilterChip(
selected = selectedDemo == DemoType.ShapeCustomization,
onClick = { onDemoSelected(DemoType.ShapeCustomization) },
label = { Text("Shape Customization") },
modifier = Modifier.fillMaxWidth()
)
}
}
}
}
@Composable
fun EmailAuthDemo(
authUI: FirebaseAuthUI,
configuration: AuthUIConfiguration,
context: android.content.Context
) {
var currentUser by remember { mutableStateOf(authUI.getCurrentUser()) }
// Monitor auth state changes
LaunchedEffect(Unit) {
authUI.authStateFlow().collect { _ ->
currentUser = authUI.getCurrentUser()
}
}
if (currentUser != null) {
// Show success screen
val successScrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(successScrollState)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = "✓",
style = MaterialTheme.typography.displayLarge,
color = MaterialTheme.colorScheme.primary
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Successfully Authenticated!",
style = MaterialTheme.typography.headlineSmall,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = currentUser?.email ?: "Signed in",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Spacer(modifier = Modifier.height(32.dp))
Button(onClick = {
authUI.auth.signOut()
}) {
Text("Sign Out")
}
}
} else {
// Show custom email auth UI using slot API
// Provide the string provider required by EmailAuthScreen
CompositionLocalProvider(LocalAuthUIStringProvider provides configuration.stringProvider) {
EmailAuthScreen(
context = context,
configuration = configuration,
authUI = authUI,
onSuccess = { result: AuthResult ->
Log.d("CustomSlotsDemo", "Email auth success: ${result.user?.uid}")
},
onError = { exception: AuthException ->
Log.e("CustomSlotsDemo", "Email auth error", exception)
},
onCancel = {
Log.d("CustomSlotsDemo", "Email auth cancelled")
}
) { state: EmailAuthContentState ->
// Custom UI using the slot API
CustomEmailAuthUI(state)
}
}
}
}
@Composable
fun CustomEmailAuthUI(state: EmailAuthContentState) {
val scrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Spacer(modifier = Modifier.height(16.dp))
// Title based on mode
Text(
text = when (state.mode) {
EmailAuthMode.SignIn, EmailAuthMode.EmailLinkSignIn -> "📧 Welcome Back"
EmailAuthMode.SignUp -> "📧 Create Account"
EmailAuthMode.ResetPassword -> "📧 Reset Password"
},
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onSurface
)
Spacer(modifier = Modifier.height(8.dp))
// Error display
state.error?.let { errorMessage ->
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.errorContainer
),
modifier = Modifier.fillMaxWidth()
) {
Text(
text = errorMessage,
modifier = Modifier.padding(12.dp),
color = MaterialTheme.colorScheme.onErrorContainer,
style = MaterialTheme.typography.bodySmall
)
}
}
// Render UI based on mode
when (state.mode) {
EmailAuthMode.SignIn, EmailAuthMode.EmailLinkSignIn -> SignInUI(state)
EmailAuthMode.SignUp -> SignUpUI(state)
EmailAuthMode.ResetPassword -> ResetPasswordUI(state)
}
}
}
@Composable
fun SignInUI(state: EmailAuthContentState) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
OutlinedTextField(
value = state.email,
onValueChange = state.onEmailChange,
label = { Text("Email") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
OutlinedTextField(
value = state.password,
onValueChange = state.onPasswordChange,
label = { Text("Password") },
visualTransformation = PasswordVisualTransformation(),
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
if (state.emailSignInLinkSent) {
Text(
text = "✓ Sign-in link sent! Check your email.",
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth()
)
}
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = state.onSignInClick,
modifier = Modifier.fillMaxWidth(),
enabled = !state.isLoading
) {
if (state.isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = MaterialTheme.colorScheme.onPrimary
)
} else {
Text("Sign In")
}
}
TextButton(
onClick = state.onGoToResetPassword,
modifier = Modifier.align(Alignment.CenterHorizontally)
) {
Text("Forgot Password?")
}
HorizontalDivider()
TextButton(
onClick = state.onGoToSignUp,
modifier = Modifier.fillMaxWidth()
) {
Text("Don't have an account? Sign Up")
}
}
}
@Composable
fun SignUpUI(state: EmailAuthContentState) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
OutlinedTextField(
value = state.displayName,
onValueChange = state.onDisplayNameChange,
label = { Text("Display Name") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
OutlinedTextField(
value = state.email,
onValueChange = state.onEmailChange,
label = { Text("Email") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
OutlinedTextField(
value = state.password,
onValueChange = state.onPasswordChange,
label = { Text("Password") },
visualTransformation = PasswordVisualTransformation(),
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
OutlinedTextField(
value = state.confirmPassword,
onValueChange = state.onConfirmPasswordChange,
label = { Text("Confirm Password") },
visualTransformation = PasswordVisualTransformation(),
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = state.onSignUpClick,
modifier = Modifier.fillMaxWidth(),
enabled = !state.isLoading
) {
if (state.isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = MaterialTheme.colorScheme.onPrimary
)
} else {
Text("Create Account")
}
}
HorizontalDivider()
TextButton(
onClick = state.onGoToSignIn,
modifier = Modifier.fillMaxWidth()
) {
Text("Already have an account? Sign In")
}
}
}
@Composable
fun ResetPasswordUI(state: EmailAuthContentState) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
text = "Enter your email address and we'll send you a link to reset your password.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Spacer(modifier = Modifier.height(8.dp))
OutlinedTextField(
value = state.email,
onValueChange = state.onEmailChange,
label = { Text("Email") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
if (state.resetLinkSent) {
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primaryContainer
),
modifier = Modifier.fillMaxWidth()
) {
Text(
text = "✓ Password reset link sent! Check your email.",
modifier = Modifier.padding(12.dp),
color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.bodyMedium
)
}
}
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = state.onSendResetLinkClick,
modifier = Modifier.fillMaxWidth(),
enabled = !state.isLoading && !state.resetLinkSent
) {
if (state.isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = MaterialTheme.colorScheme.onPrimary
)
} else {
Text("Send Reset Link")
}
}
HorizontalDivider()
TextButton(
onClick = state.onGoToSignIn,
modifier = Modifier.fillMaxWidth()
) {
Text("Back to Sign In")
}
}
}
@Composable
fun PhoneAuthDemo(
authUI: FirebaseAuthUI,
configuration: AuthUIConfiguration,
context: android.content.Context
) {
var currentUser by remember { mutableStateOf(authUI.getCurrentUser()) }
// Monitor auth state changes
LaunchedEffect(Unit) {
authUI.authStateFlow().collect { _ ->
currentUser = authUI.getCurrentUser()
}
}
if (currentUser != null) {
// Show success screen
val successScrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(successScrollState)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = "📱",
style = MaterialTheme.typography.displayLarge,
color = MaterialTheme.colorScheme.primary
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Phone Verified!",
style = MaterialTheme.typography.headlineSmall,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = currentUser?.phoneNumber ?: "Signed in",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Spacer(modifier = Modifier.height(32.dp))
Button(onClick = {
authUI.auth.signOut()
}) {
Text("Sign Out")
}
}
} else {
// Show custom phone auth UI using slot API
// Provide the string provider required by PhoneAuthScreen
CompositionLocalProvider(LocalAuthUIStringProvider provides configuration.stringProvider) {
PhoneAuthScreen(
context = context,
configuration = configuration,
authUI = authUI,
onSuccess = { result: AuthResult ->
Log.d("CustomSlotsDemo", "Phone auth success: ${result.user?.uid}")
},
onError = { exception: AuthException ->
Log.e("CustomSlotsDemo", "Phone auth error", exception)
},
onCancel = {
Log.d("CustomSlotsDemo", "Phone auth cancelled")
}
) { state: PhoneAuthContentState ->
// Custom UI using the slot API
CustomPhoneAuthUI(state)
}
}
}
}
@Composable
fun CustomPhoneAuthUI(state: PhoneAuthContentState) {
val scrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Spacer(modifier = Modifier.height(16.dp))
// Title based on step
Text(
text = when (state.step) {
PhoneAuthStep.EnterPhoneNumber -> "📱 Phone Verification"
PhoneAuthStep.EnterVerificationCode -> "📱 Enter Code"
},
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onSurface
)
Spacer(modifier = Modifier.height(8.dp))
// Error display
state.error?.let { errorMessage ->
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.errorContainer
),
modifier = Modifier.fillMaxWidth()
) {
Text(
text = errorMessage,
modifier = Modifier.padding(12.dp),
color = MaterialTheme.colorScheme.onErrorContainer,
style = MaterialTheme.typography.bodySmall
)
}
}
// Render UI based on step
when (state.step) {
PhoneAuthStep.EnterPhoneNumber -> EnterPhoneNumberUI(state)
PhoneAuthStep.EnterVerificationCode -> EnterVerificationCodeUI(state)
}
}
}
@Composable
fun EnterPhoneNumberUI(state: PhoneAuthContentState) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
text = "Enter your phone number to receive a verification code",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(8.dp))
// Country selector (simplified for demo)
OutlinedCard(
onClick = { /* In real app, open country selector */ },
modifier = Modifier.fillMaxWidth()
) {
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${state.selectedCountry.flagEmoji} ${state.selectedCountry.dialCode}",
style = MaterialTheme.typography.bodyLarge
)
Spacer(modifier = Modifier.weight(1f))
Text(
text = state.selectedCountry.name,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
OutlinedTextField(
value = state.phoneNumber,
onValueChange = state.onPhoneNumberChange,
label = { Text("Phone Number") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = state.onSendCodeClick,
modifier = Modifier.fillMaxWidth(),
enabled = !state.isLoading && state.phoneNumber.isNotBlank()
) {
if (state.isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = MaterialTheme.colorScheme.onPrimary
)
} else {
Text("Send Code")
}
}
}
}
@Composable
fun EnterVerificationCodeUI(state: PhoneAuthContentState) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
text = "We sent a verification code to:",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center
)
Text(
text = state.fullPhoneNumber,
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.primary,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(8.dp))
OutlinedTextField(
value = state.verificationCode,
onValueChange = state.onVerificationCodeChange,
label = { Text("6-Digit Code") },
modifier = Modifier.fillMaxWidth(),
singleLine = true,
enabled = !state.isLoading
)
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = state.onVerifyCodeClick,
modifier = Modifier.fillMaxWidth(),
enabled = !state.isLoading && state.verificationCode.length == 6
) {
if (state.isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = MaterialTheme.colorScheme.onPrimary
)
} else {
Text("Verify Code")
}
}
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
TextButton(onClick = state.onChangeNumberClick) {
Text("Change Number")
}
TextButton(
onClick = state.onResendCodeClick,
enabled = state.resendTimer == 0
) {
Text(
if (state.resendTimer > 0)
"Resend (${state.resendTimer}s)"
else
"Resend Code"
)
}
}
}
}
/**
* Demo showcasing provider button shape customization capabilities.
* Demonstrates:
* - Global shape configuration for all buttons
* - Per-provider shape overrides
* - Using ProviderStyleDefaults with .copy()
*/
@Composable
fun ShapeCustomizationDemo() {
val context = androidx.compose.ui.platform.LocalContext.current
val stringProvider = DefaultAuthUIStringProvider(context)
var selectedPreset by remember { mutableStateOf(ShapePreset.DEFAULT) }
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
// Title and description
Text(
text = "Provider Button Shape Customization",
style = MaterialTheme.typography.headlineSmall,
color = MaterialTheme.colorScheme.primary
)
Text(
text = "This demo showcases the new shape customization API for provider buttons. " +
"You can set a global shape for all buttons or customize individual providers.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
HorizontalDivider()
// Preset selector
Text(
text = "Select Shape Preset:",
style = MaterialTheme.typography.titleMedium
)
ShapePreset.entries.forEach { preset ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = selectedPreset == preset,
onClick = { selectedPreset = preset }
)
Spacer(modifier = Modifier.width(8.dp))
Column {
Text(
text = preset.displayName,
style = MaterialTheme.typography.bodyLarge
)
Text(
text = preset.description,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
}
HorizontalDivider()
// Preview section
Text(
text = "Preview:",
style = MaterialTheme.typography.titleMedium
)
// Render buttons with the selected preset
when (selectedPreset) {
ShapePreset.DEFAULT -> DefaultShapeButtons(stringProvider)
ShapePreset.DEFAULT_COPY -> DefaultCopyShapeButtons(stringProvider)
ShapePreset.DARK_COPY -> DarkCopyShapeButtons(stringProvider)
ShapePreset.FROM_MATERIAL -> FromMaterialThemeButtons(stringProvider)
ShapePreset.PILL -> PillShapeButtons(stringProvider)
ShapePreset.MIXED -> MixedShapeButtons(stringProvider)
}
// Code example
HorizontalDivider()
Text(
text = "Code Example:",
style = MaterialTheme.typography.titleMedium
)
Surface(
modifier = Modifier.fillMaxWidth(),
color = MaterialTheme.colorScheme.surfaceVariant,
shape = RoundedCornerShape(8.dp)
) {
Text(
text = selectedPreset.codeExample,
style = MaterialTheme.typography.bodySmall.copy(
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace
),
modifier = Modifier.padding(12.dp)
)
}
}
}
enum class ShapePreset(
val displayName: String,
val description: String,
val codeExample: String
) {
DEFAULT(
"Default Shapes",
"Uses the standard 4dp rounded corners",
"""
// No customization needed
val theme = AuthUITheme.Default
""".trimIndent()
),
DEFAULT_COPY(
"Default.copy()",
"Customize default light theme with .copy()",
"""
val theme = AuthUITheme.Default.copy(
providerButtonShape = RoundedCornerShape(12.dp)
)
""".trimIndent()
),
DARK_COPY(
"DefaultDark.copy()",
"Customize default dark theme with .copy()",
"""
val theme = AuthUITheme.DefaultDark.copy(
providerButtonShape = RoundedCornerShape(16.dp)
)
""".trimIndent()
),
FROM_MATERIAL(
"fromMaterialTheme()",
"Inherit from Material Theme",
"""
val theme = AuthUITheme.fromMaterialTheme(
providerButtonShape = RoundedCornerShape(12.dp)
)
""".trimIndent()
),
PILL(
"Pill Shape",
"Creates pill-shaped buttons (Default.copy)",
"""
val theme = AuthUITheme.Default.copy(
providerButtonShape = RoundedCornerShape(28.dp)
)
""".trimIndent()
),
MIXED(
"Mixed Shapes",
"Different shapes per provider (Default.copy)",
"""
val customStyles = mapOf(
"google.com" to ProviderStyleDefaults.Google.copy(
shape = RoundedCornerShape(24.dp)
),
"facebook.com" to ProviderStyleDefaults.Facebook.copy(
shape = RoundedCornerShape(8.dp)
)
)
val theme = AuthUITheme.Default.copy(
providerButtonShape = RoundedCornerShape(12.dp),
providerStyles = customStyles
)
""".trimIndent()
)
}
@Composable