1
- package com.firebase.ui.auth.compose
1
+ package com.firebase.ui.auth.compose.ui.method_picker
2
2
3
3
import androidx.compose.foundation.Image
4
- import androidx.compose.foundation.background
5
- import androidx.compose.foundation.layout.Arrangement
6
4
import androidx.compose.foundation.layout.Box
7
5
import androidx.compose.foundation.layout.Column
8
- import androidx.compose.foundation.layout.PaddingValues
9
- import androidx.compose.foundation.layout.Spacer
10
- import androidx.compose.foundation.layout.fillMaxHeight
11
6
import androidx.compose.foundation.layout.fillMaxSize
12
- import androidx.compose.foundation.layout.height
13
7
import androidx.compose.foundation.layout.padding
14
- import androidx.compose.foundation.layout.safeContentPadding
15
8
import androidx.compose.foundation.layout.safeDrawingPadding
16
- import androidx.compose.foundation.layout.widthIn
17
9
import androidx.compose.foundation.lazy.LazyColumn
18
- import androidx.compose.material.icons.Icons
19
- import androidx.compose.material.icons.filled.Favorite
20
- import androidx.compose.material.icons.filled.Star
21
- import androidx.compose.material3.Icon
22
- import androidx.compose.material3.Scaffold
23
- import androidx.compose.material3.Text
24
10
import androidx.compose.runtime.Composable
25
11
import androidx.compose.ui.Alignment
26
12
import androidx.compose.ui.Modifier
27
- import androidx.compose.ui.graphics.Color
28
13
import androidx.compose.ui.platform.LocalContext
29
- import androidx.compose.ui.text.style.TextAlign
14
+ import androidx.compose.ui.platform.LocalInspectionMode
15
+ import androidx.compose.ui.platform.testTag
16
+ import androidx.compose.ui.res.stringResource
30
17
import androidx.compose.ui.tooling.preview.Preview
31
18
import androidx.compose.ui.unit.dp
32
19
import com.firebase.ui.auth.R
33
- import com.firebase.ui.auth.compose.AuthProviderButton
34
20
import com.firebase.ui.auth.compose.configuration.AuthProvider
35
- import com.firebase.ui.auth.compose.configuration.stringprovider .DefaultAuthUIStringProvider
21
+ import com.firebase.ui.auth.compose.configuration.string_provider .DefaultAuthUIStringProvider
36
22
import com.firebase.ui.auth.compose.configuration.theme.AuthUIAsset
37
-
38
- // AuthMethodPicker(
39
- // providers = listOf(GoogleAuthProvider(), EmailAuthProvider()),
40
- // onProviderSelected = { provider -> /* ... */ }
41
- // )
23
+ import com.firebase.ui.auth.compose.ui.components.AuthProviderButton
42
24
43
25
/* *
44
26
* Renders the provider selection screen.
@@ -59,6 +41,8 @@ import com.firebase.ui.auth.compose.configuration.theme.AuthUIAsset
59
41
* @param logo An optional logo to display.
60
42
* @param onProviderSelected A callback when a provider is selected.
61
43
* @param customLayout An optional custom layout composable for the provider buttons.
44
+ * @param termsOfServiceUrl The URL for the Terms of Service.
45
+ * @param privacyPolicyUrl The URL for the Privacy Policy.
62
46
*
63
47
* @since 10.0.0
64
48
*/
@@ -69,8 +53,11 @@ fun AuthMethodPicker(
69
53
logo : AuthUIAsset ? = null,
70
54
onProviderSelected : (AuthProvider ) -> Unit ,
71
55
customLayout : @Composable ((List <AuthProvider >, (AuthProvider ) -> Unit ) -> Unit )? = null,
56
+ termsOfServiceUrl : String? = null,
57
+ privacyPolicyUrl : String? = null,
72
58
) {
73
59
val context = LocalContext .current
60
+ val inPreview = LocalInspectionMode .current
74
61
75
62
Column (
76
63
modifier = modifier
@@ -83,7 +70,8 @@ fun AuthMethodPicker(
83
70
modifier = Modifier
84
71
.weight(0.4f ),
85
72
painter = it.painter,
86
- contentDescription = " AuthMethodPicker logo" ,
73
+ contentDescription = if (inPreview) " "
74
+ else stringResource(R .string.fui_auth_method_picker_logo)
87
75
)
88
76
}
89
77
if (customLayout != null ) {
@@ -92,9 +80,9 @@ fun AuthMethodPicker(
92
80
LazyColumn (
93
81
modifier = Modifier
94
82
.fillMaxSize()
95
- .weight(1f ),
83
+ .weight(1f )
84
+ .testTag(" AuthMethodPicker LazyColumn" ),
96
85
horizontalAlignment = Alignment .CenterHorizontally ,
97
- contentPadding = PaddingValues (bottom = 64 .dp) // Space for text
98
86
) {
99
87
items(providers.size) { index ->
100
88
val provider = providers[index]
@@ -112,14 +100,18 @@ fun AuthMethodPicker(
112
100
}
113
101
}
114
102
}
115
- Text (
116
- " By continuing, you are indicating that you accept our " +
117
- " Terms of Service and Privacy Policy." ,
118
- textAlign = TextAlign .Center ,
119
- modifier = Modifier
120
- .padding(horizontal = 16 .dp, vertical = 16 .dp)
121
- )
122
103
}
104
+ AnnotatedStringResource (
105
+ context = context,
106
+ inPreview = inPreview,
107
+ previewText = " By continuing, you accept our Terms of Service and Privacy Policy." ,
108
+ modifier = Modifier .padding(vertical = 16 .dp),
109
+ id = R .string.fui_tos_and_pp,
110
+ links = arrayOf(
111
+ " Terms of Service" to (termsOfServiceUrl ? : " " ),
112
+ " Privacy Policy" to (privacyPolicyUrl ? : " " )
113
+ )
114
+ )
123
115
}
124
116
}
125
117
@@ -160,19 +152,12 @@ fun PreviewAuthMethodPicker() {
160
152
customParameters = emptyMap()
161
153
),
162
154
AuthProvider .Anonymous ,
163
- AuthProvider .GenericOAuth (
164
- providerId = " google.com" ,
165
- scopes = emptyList(),
166
- customParameters = emptyMap(),
167
- buttonLabel = " Generic Provider" ,
168
- buttonIcon = AuthUIAsset .Vector (Icons .Default .Star ),
169
- buttonColor = Color .Gray ,
170
- contentColor = Color .White
171
- )
172
155
),
173
156
logo = AuthUIAsset .Resource (R .drawable.fui_ic_check_circle_black_128dp),
174
157
onProviderSelected = { provider ->
175
158
176
159
},
160
+ termsOfServiceUrl = " https://example.com/terms" ,
161
+ privacyPolicyUrl = " https://example.com/privacy"
177
162
)
178
163
}
0 commit comments