[#65] Add background gradient

This commit is contained in:
Carter Jernigan 2021-12-09 15:18:18 -05:00 committed by GitHub
parent ca457b1116
commit 84795ad213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 131 additions and 85 deletions

View File

@ -9,14 +9,18 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import cash.z.ecc.sdk.model.PersistableWallet import cash.z.ecc.sdk.model.PersistableWallet
import cash.z.ecc.ui.screen.backup.view.BackupWallet import cash.z.ecc.ui.screen.backup.view.BackupWallet
import cash.z.ecc.ui.screen.backup.viewmodel.BackupViewModel import cash.z.ecc.ui.screen.backup.viewmodel.BackupViewModel
import cash.z.ecc.ui.screen.common.GradientSurface
import cash.z.ecc.ui.screen.home.view.Home import cash.z.ecc.ui.screen.home.view.Home
import cash.z.ecc.ui.screen.home.viewmodel.WalletState import cash.z.ecc.ui.screen.home.viewmodel.WalletState
import cash.z.ecc.ui.screen.home.viewmodel.WalletViewModel import cash.z.ecc.ui.screen.home.viewmodel.WalletViewModel
@ -56,42 +60,48 @@ class MainActivity : ComponentActivity() {
} }
private fun setupSplashScreen() { private fun setupSplashScreen() {
installSplashScreen().also { val splashScreen = installSplashScreen()
val start = SystemClock.elapsedRealtime().milliseconds val start = SystemClock.elapsedRealtime().milliseconds
it.setKeepVisibleCondition {
if (SPLASH_SCREEN_DELAY > Duration.ZERO) {
val now = SystemClock.elapsedRealtime().milliseconds
// This delay is for debug purposes only; do not enable for production usage. splashScreen.setKeepVisibleCondition {
if (now - start < SPLASH_SCREEN_DELAY) { if (SPLASH_SCREEN_DELAY > Duration.ZERO) {
return@setKeepVisibleCondition true val now = SystemClock.elapsedRealtime().milliseconds
}
// This delay is for debug purposes only; do not enable for production usage.
if (now - start < SPLASH_SCREEN_DELAY) {
return@setKeepVisibleCondition true
} }
WalletState.Loading == walletViewModel.state.value
} }
WalletState.Loading == walletViewModel.state.value
} }
} }
private fun setupUiContent() { private fun setupUiContent() {
setContent { setContent {
ZcashTheme { ZcashTheme {
val walletState = walletViewModel.state.collectAsState().value GradientSurface(
Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
val walletState = walletViewModel.state.collectAsState().value
when (walletState) { when (walletState) {
WalletState.Loading -> { WalletState.Loading -> {
// For now, keep displaying splash screen using condition above. // For now, keep displaying splash screen using condition above.
// In the future, we might consider displaying something different here. // In the future, we might consider displaying something different here.
}
WalletState.NoWallet -> {
WrapOnboarding()
}
is WalletState.NeedsBackup -> WrapBackup(walletState.persistableWallet)
is WalletState.Ready -> WrapHome(walletState.persistableWallet)
} }
WalletState.NoWallet -> {
WrapOnboarding()
}
is WalletState.NeedsBackup -> WrapBackup(walletState.persistableWallet)
is WalletState.Ready -> WrapHome(walletState.persistableWallet)
}
if (walletState != WalletState.Loading) { if (walletState != WalletState.Loading) {
reportFullyDrawn() reportFullyDrawn()
}
} }
} }
} }

View File

@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Card import androidx.compose.material.Card
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -26,6 +25,7 @@ import cash.z.ecc.ui.screen.common.Body
import cash.z.ecc.ui.screen.common.CHIP_GRID_ROW_SIZE import cash.z.ecc.ui.screen.common.CHIP_GRID_ROW_SIZE
import cash.z.ecc.ui.screen.common.Chip import cash.z.ecc.ui.screen.common.Chip
import cash.z.ecc.ui.screen.common.ChipGrid import cash.z.ecc.ui.screen.common.ChipGrid
import cash.z.ecc.ui.screen.common.GradientSurface
import cash.z.ecc.ui.screen.common.Header import cash.z.ecc.ui.screen.common.Header
import cash.z.ecc.ui.screen.common.NavigationButton import cash.z.ecc.ui.screen.common.NavigationButton
import cash.z.ecc.ui.screen.common.PrimaryButton import cash.z.ecc.ui.screen.common.PrimaryButton
@ -37,14 +37,16 @@ import cash.z.ecc.ui.theme.ZcashTheme
@Preview(device = Devices.PIXEL_4) @Preview(device = Devices.PIXEL_4)
@Composable @Composable
fun ComposablePreview() { fun ComposablePreview() {
ZcashTheme(darkTheme = true) { ZcashTheme(darkTheme = false) {
BackupWallet( GradientSurface {
PersistableWalletFixture.new(), BackupWallet(
BackupState(BackupStage.Test), PersistableWalletFixture.new(),
TestChoices(), BackupState(BackupStage.EducationOverview),
onCopyToClipboard = {}, TestChoices(),
onComplete = {} onCopyToClipboard = {},
) onComplete = {}
)
}
} }
} }
@ -59,27 +61,25 @@ fun BackupWallet(
onCopyToClipboard: () -> Unit, onCopyToClipboard: () -> Unit,
onComplete: () -> Unit, onComplete: () -> Unit,
) { ) {
Surface { Column {
Column { when (backupState.current.collectAsState().value) {
when (backupState.current.collectAsState().value) { BackupStage.EducationOverview -> EducationOverview(onNext = backupState::goNext)
BackupStage.EducationOverview -> EducationOverview(onNext = backupState::goNext) BackupStage.EducationRecoveryPhrase -> EducationRecoveryPhrase(onNext = backupState::goNext)
BackupStage.EducationRecoveryPhrase -> EducationRecoveryPhrase(onNext = backupState::goNext) BackupStage.Seed -> SeedPhrase(
BackupStage.Seed -> SeedPhrase( wallet,
wallet, onNext = backupState::goNext,
onNext = backupState::goNext, onCopyToClipboard = onCopyToClipboard
onCopyToClipboard = onCopyToClipboard )
) BackupStage.Test -> Test(
BackupStage.Test -> Test( wallet,
wallet, selectedTestChoices,
selectedTestChoices, onBack = backupState::goPrevious,
onBack = backupState::goPrevious, onNext = backupState::goNext
onNext = backupState::goNext )
) BackupStage.Complete -> Complete(
BackupStage.Complete -> Complete( onComplete = onComplete,
onComplete = onComplete, onBackToSeedPhrase = backupState::goToSeed
onBackToSeedPhrase = backupState::goToSeed )
)
}
} }
} }
} }

View File

@ -0,0 +1,20 @@
package cash.z.ecc.ui.screen.common
import androidx.compose.foundation.background
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import cash.z.ecc.ui.theme.ZcashTheme
@Composable
fun GradientSurface(modifier: Modifier = Modifier, content: @Composable () -> Unit) {
Surface(
color = Color.Transparent,
modifier = modifier
.background(ZcashTheme.colors.surfaceGradient()),
shape = RectangleShape,
content = content
)
}

View File

@ -2,7 +2,6 @@ package cash.z.ecc.ui.screen.debug.view
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Surface
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.List import androidx.compose.material.icons.filled.List
import androidx.compose.material.icons.filled.Person import androidx.compose.material.icons.filled.Person
@ -12,6 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import cash.z.ecc.ui.screen.common.Body import cash.z.ecc.ui.screen.common.Body
import cash.z.ecc.ui.screen.common.Chip import cash.z.ecc.ui.screen.common.Chip
import cash.z.ecc.ui.screen.common.GradientSurface
import cash.z.ecc.ui.screen.common.Header import cash.z.ecc.ui.screen.common.Header
import cash.z.ecc.ui.screen.common.NavigationButton import cash.z.ecc.ui.screen.common.NavigationButton
import cash.z.ecc.ui.screen.common.PinkProgress import cash.z.ecc.ui.screen.common.PinkProgress
@ -35,7 +35,7 @@ fun ComposablePreview() {
// Allowing magic numbers since this is debug-only // Allowing magic numbers since this is debug-only
@Suppress("MagicNumber") @Suppress("MagicNumber")
fun DesignGuide() { fun DesignGuide() {
Surface { GradientSurface {
Column { Column {
Header(text = "H1") Header(text = "H1")
Body(text = "body") Body(text = "body")

View File

@ -1,28 +1,28 @@
package cash.z.ecc.ui.screen.home.view package cash.z.ecc.ui.screen.home.view
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.material.Surface
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import cash.z.ecc.sdk.fixture.PersistableWalletFixture import cash.z.ecc.sdk.fixture.PersistableWalletFixture
import cash.z.ecc.sdk.model.PersistableWallet import cash.z.ecc.sdk.model.PersistableWallet
import cash.z.ecc.ui.screen.common.GradientSurface
import cash.z.ecc.ui.theme.ZcashTheme import cash.z.ecc.ui.theme.ZcashTheme
@Preview @Preview
@Composable @Composable
fun ComposablePreview() { fun ComposablePreview() {
ZcashTheme(darkTheme = true) { ZcashTheme(darkTheme = true) {
Home(PersistableWalletFixture.new()) GradientSurface {
Home(PersistableWalletFixture.new())
}
} }
} }
@Composable @Composable
fun Home(@Suppress("UNUSED_PARAMETER") persistableWallet: PersistableWallet) { fun Home(@Suppress("UNUSED_PARAMETER") persistableWallet: PersistableWallet) {
Surface { Column {
Column { // Placeholder
// Placeholder Text("Welcome to your wallet")
Text("Welcome to your wallet")
}
} }
} }

View File

@ -7,10 +7,10 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -22,6 +22,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import cash.z.ecc.ui.R import cash.z.ecc.ui.R
import cash.z.ecc.ui.screen.common.Body import cash.z.ecc.ui.screen.common.Body
import cash.z.ecc.ui.screen.common.GradientSurface
import cash.z.ecc.ui.screen.common.Header import cash.z.ecc.ui.screen.common.Header
import cash.z.ecc.ui.screen.common.NavigationButton import cash.z.ecc.ui.screen.common.NavigationButton
import cash.z.ecc.ui.screen.common.PinkProgress import cash.z.ecc.ui.screen.common.PinkProgress
@ -38,11 +39,13 @@ import cash.z.ecc.ui.theme.ZcashTheme
@Composable @Composable
fun ComposablePreview() { fun ComposablePreview() {
ZcashTheme(darkTheme = true) { ZcashTheme(darkTheme = true) {
Onboarding( GradientSurface {
OnboardingState(OnboardingStage.UnifiedAddresses), Onboarding(
onImportWallet = {}, OnboardingState(OnboardingStage.UnifiedAddresses),
onCreateWallet = {} onImportWallet = {},
) onCreateWallet = {}
)
}
} }
} }
@ -56,24 +59,22 @@ fun Onboarding(
onImportWallet: () -> Unit, onImportWallet: () -> Unit,
onCreateWallet: () -> Unit onCreateWallet: () -> Unit
) { ) {
Surface { Column {
Column { TopNavButtons(onboardingState)
TopNavButtons(onboardingState)
val onboardingStage = onboardingState.current.collectAsState().value val onboardingStage = onboardingState.current.collectAsState().value
when (onboardingStage) { when (onboardingStage) {
OnboardingStage.ShieldedByDefault -> ShieldedByDefault() OnboardingStage.ShieldedByDefault -> ShieldedByDefault()
OnboardingStage.UnifiedAddresses -> UnifiedAddresses() OnboardingStage.UnifiedAddresses -> UnifiedAddresses()
OnboardingStage.More -> More() OnboardingStage.More -> More()
OnboardingStage.Wallet -> Wallet( OnboardingStage.Wallet -> Wallet(
onCreateWallet = onCreateWallet, onCreateWallet = onCreateWallet,
onImportWallet = onImportWallet onImportWallet = onImportWallet
) )
}
BottomNav(onboardingStage.getProgress(), onboardingState::goNext)
} }
BottomNav(onboardingStage.getProgress(), onboardingState::goNext)
} }
} }
@ -100,6 +101,8 @@ private fun TopNavButtons(onboardingState: OnboardingState) {
private fun BottomNav(progress: Progress, onNext: () -> Unit) { private fun BottomNav(progress: Progress, onNext: () -> Unit) {
if (progress.current != progress.last) { if (progress.current != progress.last) {
Column { Column {
Spacer(modifier = Modifier.fillMaxHeight().weight(MINIMAL_WEIGHT, true))
SecondaryButton(onNext, stringResource(R.string.onboarding_next), Modifier.fillMaxWidth()) SecondaryButton(onNext, stringResource(R.string.onboarding_next), Modifier.fillMaxWidth())
// Converts from index to human numbering // Converts from index to human numbering

View File

@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
private val DarkColorPalette = darkColors( private val DarkColorPalette = darkColors(
@ -34,6 +35,7 @@ private val LightColorPalette = lightColors(
@Immutable @Immutable
data class ExtendedColors( data class ExtendedColors(
val surfaceEnd: Color,
val onBackgroundHeader: Color, val onBackgroundHeader: Color,
val tertiary: Color, val tertiary: Color,
val onTertiary: Color, val onTertiary: Color,
@ -43,9 +45,18 @@ data class ExtendedColors(
val progressEnd: Color, val progressEnd: Color,
val progressBackground: Color, val progressBackground: Color,
val chipIndex: Color val chipIndex: Color
) ) {
@Composable
fun surfaceGradient() = Brush.verticalGradient(
colors = listOf(
MaterialTheme.colors.surface,
ZcashTheme.colors.surfaceEnd
)
)
}
val DarkExtendedColorPalette = ExtendedColors( val DarkExtendedColorPalette = ExtendedColors(
surfaceEnd = Dark.backgroundEnd,
onBackgroundHeader = Dark.textHeaderOnBackground, onBackgroundHeader = Dark.textHeaderOnBackground,
tertiary = Dark.tertiaryButton, tertiary = Dark.tertiaryButton,
onTertiary = Dark.textTertiaryButton, onTertiary = Dark.textTertiaryButton,
@ -58,6 +69,7 @@ val DarkExtendedColorPalette = ExtendedColors(
) )
val LightExtendedColorPalette = ExtendedColors( val LightExtendedColorPalette = ExtendedColors(
surfaceEnd = Light.backgroundEnd,
onBackgroundHeader = Light.textHeaderOnBackground, onBackgroundHeader = Light.textHeaderOnBackground,
tertiary = Light.tertiaryButton, tertiary = Light.tertiaryButton,
onTertiary = Light.textTertiaryButton, onTertiary = Light.textTertiaryButton,
@ -71,6 +83,7 @@ val LightExtendedColorPalette = ExtendedColors(
val LocalExtendedColors = staticCompositionLocalOf { val LocalExtendedColors = staticCompositionLocalOf {
ExtendedColors( ExtendedColors(
surfaceEnd = Color.Unspecified,
onBackgroundHeader = Color.Unspecified, onBackgroundHeader = Color.Unspecified,
tertiary = Color.Unspecified, tertiary = Color.Unspecified,
onTertiary = Color.Unspecified, onTertiary = Color.Unspecified,