Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.auth0.android.sample.ui.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ButtonElevation
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.auth0.universalcomponents.theme.Auth0Theme

@Composable
fun SampleGradientButton(
modifier: Modifier = Modifier,
gradient: Brush = Brush.verticalGradient(
colors = listOf(
Color.White.copy(alpha = 0.15f),
Color.Transparent
)
),
buttonDefaultColor: ButtonColors? = null,
shape: RoundedCornerShape? = null,
elevation: ButtonElevation = ButtonDefaults.buttonElevation(
defaultElevation = 0.dp,
pressedElevation = 2.dp
),
isLoading: Boolean = false,
enabled: Boolean = true,
borderStroke: BorderStroke? = null,
onClick: () -> Unit,
content: @Composable () -> Unit,
) {
val colors = Auth0Theme.colors
val dimensions = Auth0Theme.dimensions
val resolvedShape = shape ?: Auth0Theme.shapes.large

val buttonColors = buttonDefaultColor ?: ButtonDefaults.buttonColors(
containerColor = colors.backgroundPrimary,
contentColor = colors.textOnPrimary,
disabledContainerColor = colors.backgroundPrimary.copy(alpha = 0.38f),
disabledContentColor = colors.textOnPrimary.copy(alpha = 0.38f)
)

Button(
modifier = modifier,
colors = buttonColors,
shape = resolvedShape,
contentPadding = PaddingValues(),
elevation = elevation,
enabled = enabled && !isLoading,
border = borderStroke,
onClick = { onClick() },
) {
Box(
modifier = Modifier
.background(gradient)
.then(modifier),
contentAlignment = Alignment.Center,
) {
Row(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
if (isLoading) {
CircularProgressIndicator(
modifier = Modifier.size(16.dp),
color = Color.White.copy(alpha = 0.75f),
strokeWidth = 2.dp
)
Spacer(modifier = Modifier.size(dimensions.spacingXs))
} else {
content()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.auth0.android.sample.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.auth0.universalcomponents.theme.Auth0Theme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SampleTopBar(
title: String,
modifier: Modifier = Modifier,
topBarColor: Color = Color.Unspecified,
showSeparator: Boolean = false,
showBackNavigation: Boolean = true,
trailingIcon: Painter? = null,
titleTextStyle: TextStyle? = null,
onBackClick: () -> Unit,
trailingIconClick: () -> Unit = {}
) {
val colors = Auth0Theme.colors
val typography = Auth0Theme.typography

val resolvedTopBarColor = if (topBarColor == Color.Unspecified) colors.backgroundLayerBase else topBarColor
val titleStyle = titleTextStyle ?: typography.title

Column {
CenterAlignedTopAppBar(
title = {
Text(
text = title,
style = titleStyle,
color = colors.textBold
)
},
navigationIcon = {
if (showBackNavigation) {
IconButton(onClick = onBackClick) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Navigate back",
tint = MaterialTheme.colorScheme.onSurface
)
}
}
},
actions = {
if (trailingIcon != null) {
IconButton(onClick = trailingIconClick) {
Icon(
painter = trailingIcon,
contentDescription = "Action",
tint = MaterialTheme.colorScheme.onSurface
)
}
}
},
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = resolvedTopBarColor,
),
modifier = modifier
)
if (showSeparator) {
HorizontalDivider(
modifier = Modifier.fillMaxWidth(),
thickness = 0.3.dp,
color = colors.borderDefault
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.auth0.android.sample.ui.viewmodels.AppearanceViewModel
import com.auth0.universalcomponents.presentation.ui.components.GradientButton
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleGradientButton
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.android.sample.ui.theme.isAuth0DarkTheme
import com.auth0.universalcomponents.theme.Auth0Theme

Expand Down Expand Up @@ -60,7 +60,7 @@ fun AppearanceScreen(

Scaffold(
topBar = {
TopBar(title = "", showBackNavigation = true, onBackClick = onBack)
SampleTopBar(title = "", showBackNavigation = true, onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down Expand Up @@ -137,7 +137,7 @@ fun AppearanceScreen(

Spacer(modifier = Modifier.height(dimensions.spacingLg))

GradientButton(
SampleGradientButton(
modifier = Modifier
.fillMaxWidth()
.height(sizes.buttonHeight),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.universalcomponents.theme.Auth0Theme

@Composable
Expand All @@ -19,7 +19,7 @@ fun DocsScreen(onBack: () -> Unit) {

Scaffold(
topBar = {
TopBar(title = "Docs", onBackClick = onBack)
SampleTopBar(title = "Docs", onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import com.auth0.android.sample.ui.components.Auth0LogoHeader
import com.auth0.android.sample.ui.components.OrDivider
import com.auth0.android.sample.ui.theme.auth0ScreenBackground
import com.auth0.android.sample.ui.theme.isAuth0DarkTheme
import com.auth0.universalcomponents.presentation.ui.components.GradientButton
import com.auth0.android.sample.ui.components.SampleGradientButton
import com.auth0.universalcomponents.theme.Auth0Theme

/**
Expand Down Expand Up @@ -222,7 +222,7 @@ fun EmbeddedLoginScreen(
Spacer(modifier = Modifier.height(dimensions.spacingLg))

// Continue button
GradientButton(
SampleGradientButton(
modifier = Modifier
.fillMaxWidth()
.height(sizes.buttonHeight),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.universalcomponents.theme.Auth0Theme

@Composable
Expand All @@ -19,7 +19,7 @@ fun FavoritesScreen(onBack: () -> Unit) {

Scaffold(
topBar = {
TopBar(title = "Favorites", onBackClick = onBack)
SampleTopBar(title = "Favorites", onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.universalcomponents.theme.Auth0Theme

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ fun ProfileScreen(

Scaffold(
topBar = {
TopBar(title = "", showBackNavigation = true, onBackClick = onBack)
SampleTopBar(title = "", showBackNavigation = true, onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.universalcomponents.theme.Auth0Theme

@Composable
Expand All @@ -19,7 +19,7 @@ fun SessionsScreen(onBack: () -> Unit) {

Scaffold(
topBar = {
TopBar(title = "Sessions", onBackClick = onBack)
SampleTopBar(title = "Sessions", onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.universalcomponents.theme.Auth0Theme

@Composable
Expand All @@ -19,7 +19,7 @@ fun TokensScreen(onBack: () -> Unit) {

Scaffold(
topBar = {
TopBar(title = "Tokens", onBackClick = onBack)
SampleTopBar(title = "Tokens", onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.auth0.universalcomponents.presentation.ui.components.GradientButton
import com.auth0.universalcomponents.presentation.ui.components.TopBar
import com.auth0.android.sample.ui.components.SampleGradientButton
import com.auth0.android.sample.ui.components.SampleTopBar
import com.auth0.universalcomponents.theme.Auth0Theme

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ fun UpdateFullNameScreen(

Scaffold(
topBar = {
TopBar(title = "", showBackNavigation = true, onBackClick = onBack)
SampleTopBar(title = "", showBackNavigation = true, onBackClick = onBack)
},
containerColor = colors.backgroundLayerBase
) { padding ->
Expand Down Expand Up @@ -114,7 +114,7 @@ fun UpdateFullNameScreen(

Spacer(modifier = Modifier.height(dimensions.spacingXl))

GradientButton(
SampleGradientButton(
modifier = Modifier
.fillMaxWidth()
.height(sizes.buttonHeight),
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ configure(project(':universal_components')) {
detekt {
buildUponDefaultConfig = true
parallel = true
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
source.setFrom(files('src/main/java', 'src/main/kotlin', 'src/test/java', 'src/test/kotlin'))
}

Expand Down
5 changes: 0 additions & 5 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ formatting:
active: true
NoWildcardImports:
active: true
# authenticator_methods package is public API; renaming would break consumers.
PackageName:
active: true
excludes: [ '**/mfa/authenticator_methods/**' ]

complexity:
active: true
Expand Down Expand Up @@ -69,11 +67,8 @@ naming:
TopLevelPropertyNaming:
active: true
constantPattern: '[A-Z][_A-Z0-9]*'
# The authenticator_methods package is part of the published public API.
# Renaming it to drop the underscore would be a breaking change for consumers.
PackageNaming:
active: true
excludes: [ '**/mfa/authenticator_methods/**' ]

style:
active: true
Expand Down
Loading
Loading