Share
Embed
Introducing Jetpack Compose into your existing app
In this talk I am explaining how to introduce Jetpack Compose into your existing app by following those steps:
- Theme
- Components
- Interop (with the old UI Toolkit)
- Full Screens
- Navigation
Alexander Gherschon
July 18, 2022
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
155 slides
-
INTRODUCING JETPACK COMPOSE INTO YOUR EXISTING APP Alexander Gherschon
Android Tech Lead @ ONE ZERO Digital Bank -
THEME - DEFINING @Composable fun IntroducingComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - DEFINING @Composable fun IntroducingComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - DEFINING @Composable fun IntroducingComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - DEFINING @Composable fun IntroducingComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - DEFINING @Composable fun IntroducingComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - DEFINING @Composable fun IntroducingComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } @Composable fun GreetingScreen() { Surface( modi fi er = Modi fi er. fi llMaxSize(), color = MaterialTheme.colors.primary ) { Text(text = "Hello KotlinTLV!") } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } @Composable fun GreetingScreen() { Surface( modi fi er = Modi fi er. fi llMaxSize(), color = MaterialTheme.colors.primary ) { Text(text = "Hello KotlinTLV!") } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } @Composable fun GreetingScreen() { Surface( modi fi er = Modi fi er. fi llMaxSize(), color = MaterialTheme.colors.primary ) { Text(text = "Hello KotlinTLV!") } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } @Composable fun GreetingScreen() { Surface( modi fi er = Modi fi er. fi llMaxSize(), color = MaterialTheme.colors.primary ) { Text(text = "Hello KotlinTLV!") } } -
THEME - USAGE class MainActivity : ComponentActivity() { override fun
onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } @Composable fun GreetingScreen() { Surface( modi fi er = Modi fi er. fi llMaxSize(), color = MaterialTheme.colors.primary ) { Text(text = "Hello KotlinTLV!") } } -
THEME - HOW DOES THIS WORK? class MainActivity : ComponentActivity()
{ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { IntroducingComposeTheme { GreetingScreen() } } } } @Composable fun GreetingScreen() { Surface( modi fi er = Modi fi er. fi llMaxSize(), color = MaterialTheme.colors.primary ) { Text(text = "Hello KotlinTLV!") } } -
THEME - MATERIAL THEME @Composable fun IntroducingComposeTheme( darkTheme: Boolean =
isSystemInDarkTheme(), content: @Composable () -> Unit ) { val colors = if (darkTheme) DarkColorPalette else LightColorPalette MaterialTheme( colors = colors, typography = Typography, shapes = Shapes, content = content ) } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } internal val LocalColors = staticCompositionLocalOf { error("LocalColors was not provided") } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } internal val LocalColors = staticCompositionLocalOf { error("LocalColors was not provided") } -
THEME - MATERIAL THEME @Composable fun MaterialTheme( colors: Colors =
MaterialTheme.colors, typography: Typography = MaterialTheme.typography, shapes: Shapes = MaterialTheme.shapes, content: @Composable () -> Unit ) { CompositionLocalProvider( LocalColors provides colors, // more provided compositionLocals content = content ) } object MaterialTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current val typography: Typography // same val shapes: Shapes // same } internal val LocalColors = staticCompositionLocalOf { error("LocalColors was not provided") } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } object OZTheme { val isDarkMode: Boolean @Composable get() = LocalIsDarkMode.current val isGeneralMode: Boolean @Composable get() = LocalIsGeneralMode.current val colors: OZColors @Composable get() = LocalOZColors.current val generalColors: OZGeneralColors @Composable get() = LocalOZGeneralColors.current val typography: OZTypography @Composable get() = LocalOZTypography.current val shapes: OZShapes @Composable get() = LocalOZShapes.current } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } object OZTheme { val isDarkMode: Boolean @Composable get() = LocalIsDarkMode.current val isGeneralMode: Boolean @Composable get() = LocalIsGeneralMode.current val colors: OZColors @Composable get() = LocalOZColors.current val generalColors: OZGeneralColors @Composable get() = LocalOZGeneralColors.current val typography: OZTypography @Composable get() = LocalOZTypography.current val shapes: OZShapes @Composable get() = LocalOZShapes.current } -
THEME - FULLY-CUSTOM THEME @Composable fun OZTheme( isDarkMode: Boolean =
isSystemInDarkTheme(), isGeneralMode: Boolean = false, content: @Composable () -> Unit, ) { val colors = if (isDarkMode) ozDarkColors else ozLightColors val generalColors = ozGeneralColors val typography = OZTypography() val shapes = OZShapes() CompositionLocalProvider( LocalOZColors provides colors, LocalOZGeneralColors provides generalColors, LocalOZTypography provides typography, LocalOZShapes provides shapes, LocalIsDarkMode provides isDarkMode, LocalIsGeneralMode provides isGeneralMode, content = content ) } object OZTheme { val isDarkMode: Boolean @Composable get() = LocalIsDarkMode.current val isGeneralMode: Boolean @Composable get() = LocalIsGeneralMode.current val colors: OZColors @Composable get() = LocalOZColors.current val generalColors: OZGeneralColors @Composable get() = LocalOZGeneralColors.current val typography: OZTypography @Composable get() = LocalOZTypography.current val shapes: OZShapes @Composable get() = LocalOZShapes.current } -
THEME - CONCLUSION • Use Material Theme as your Design
System if it’s enough for you • Have your designers build your brand aka Design System • Translate Your Design System into your own Fully Custom Theme -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR enum class StepProgressBarVariant( val completedStepColor:
Color, val unCompletedStepColor: Color, ) { Regular( completedStepColor = OZTheme.colors.buttonsPrimaryRegular, unCompletedStepColor = OZTheme.colors.systemGrayGray5 ), } -
COMPONENTS - STEP PROGRESS BAR enum class StepProgressBarVariant( val completedStepColor:
Color, val unCompletedStepColor: Color, ) { Regular( completedStepColor = OZTheme.colors.buttonsPrimaryRegular, unCompletedStepColor = OZTheme.colors.systemGrayGray5 ), } Looks good? -
COMPONENTS - STEP PROGRESS BAR enum class StepProgressBarVariant( val completedStepColor:
Color, val unCompletedStepColor: Color, ) { Regular( completedStepColor = OZTheme.colors.buttonsPrimaryRegular, unCompletedStepColor = OZTheme.colors.systemGrayGray5 ), } Looks good, but doesn’t work -
COMPONENTS - STEP PROGRESS BAR enum class StepProgressBarVariant( val completedStepColor:
Color, val unCompletedStepColor: Color, ) { Regular( completedStepColor = OZTheme.colors.buttonsPrimaryRegular, unCompletedStepColor = OZTheme.colors.systemGrayGray5 ), } HOW DO WE FIX THIS? -
COMPONENTS - STEP PROGRESS BAR enum class StepProgressBarVariant( val completedStepColor:
@Composable () -> Color, val unCompletedStepColor: @Composable () -> Color, ) { Regular( completedStepColor = { OZTheme.colors.buttonsPrimaryRegular }, unCompletedStepColor = { OZTheme.colors.systemGrayGray5 } ), } -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR @Composable fun StepProgressBar( modi fi
er: Modi fi er = Modi fi er, variant: StepProgressBarVariant = StepProgressBarVariant.Regular, numberOfSteps: Int, currentStep: Int ) { // some code here } -
COMPONENTS - STEP PROGRESS BAR { Row( modi fi er
= modi fi er .width(230.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center, ) { // more code here } } -
COMPONENTS - STEP PROGRESS BAR { Row( modi fi er
= modi fi er .width(230.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center, ) { // more code here } } -
COMPONENTS - STEP PROGRESS BAR { Row( modi fi er
= modi fi er .width(230.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center, ) { // more code here } } -
COMPONENTS - STEP PROGRESS BAR for (step in 0 until
numberOfSteps) { Step( completed = step < currentStep, completedColor = variant.completedStepColor(), unCompletedColor = variant.unCompletedStepColor(), modi fi er = Modi fi er .weight(1F), ) if (step < numberOfSteps - 1) { Spacer(modi fi er = Modi fi er.width(5.dp)) } } -
COMPONENTS - STEP PROGRESS BAR for (step in 0 until
numberOfSteps) { Step( completed = step < currentStep, completedColor = variant.completedStepColor(), unCompletedColor = variant.unCompletedStepColor(), modi fi er = Modi fi er .weight(1F), ) if (step < numberOfSteps - 1) { Spacer(modi fi er = Modi fi er.width(5.dp)) } } -
COMPONENTS - STEP PROGRESS BAR for (step in 0 until
numberOfSteps) { Step( completed = step < currentStep, completedColor = variant.completedStepColor(), unCompletedColor = variant.unCompletedStepColor(), modi fi er = Modi fi er .weight(1F), ) if (step < numberOfSteps - 1) { Spacer(modi fi er = Modi fi er.width(5.dp)) } } -
COMPONENTS - STEP PROGRESS BAR for (step in 0 until
numberOfSteps) { Step( completed = step < currentStep, completedColor = variant.completedStepColor(), unCompletedColor = variant.unCompletedStepColor(), modi fi er = Modi fi er .weight(1F), ) if (step < numberOfSteps - 1) { Spacer(modi fi er = Modi fi er.width(5.dp)) } } -
COMPONENTS - STEP PROGRESS BAR for (step in 0 until
numberOfSteps) { Step( completed = step < currentStep, completedColor = variant.completedStepColor(), unCompletedColor = variant.unCompletedStepColor(), modi fi er = Modi fi er .weight(1F), ) if (step < numberOfSteps - 1) { Spacer(modi fi er = Modi fi er.width(5.dp)) } } -
COMPONENTS - STEP PROGRESS BAR for (step in 0 until
numberOfSteps) { Step( completed = step < currentStep, completedColor = variant.completedStepColor(), unCompletedColor = variant.unCompletedStepColor(), modi fi er = Modi fi er .weight(1F), ) if (step < numberOfSteps - 1) { Spacer(modi fi er = Modi fi er.width(5.dp)) } } -
COMPONENTS - STEP PROGRESS BAR @Composable fun Step( modi fi
er: Modi fi er = Modi fi er, completed: Boolean, completedColor: Color, unCompletedColor: Color ) { Divider( modi fi er = modi fi er .width(20.dp) .clip(OZTheme.shapes.cornerRadius50percent), color = if (completed) completedColor else unCompletedColor, thickness = 2.dp ) } -
COMPONENTS - STEP PROGRESS BAR @Composable fun Step( modi fi
er: Modi fi er = Modi fi er, completed: Boolean, completedColor: Color, unCompletedColor: Color ) { Divider( modi fi er = modi fi er .width(20.dp) .clip(OZTheme.shapes.cornerRadius50percent), color = if (completed) completedColor else unCompletedColor, thickness = 2.dp ) } -
COMPONENTS - STEP PROGRESS BAR @Composable fun Step( modi fi
er: Modi fi er = Modi fi er, completed: Boolean, completedColor: Color, unCompletedColor: Color ) { Divider( modi fi er = modi fi er .width(20.dp) .clip(OZTheme.shapes.cornerRadius50percent), color = if (completed) completedColor else unCompletedColor, thickness = 2.dp ) } -
COMPONENTS - STEP PROGRESS BAR @Composable fun Step( modi fi
er: Modi fi er = Modi fi er, completed: Boolean, completedColor: Color, unCompletedColor: Color ) { Divider( modi fi er = modi fi er .width(20.dp) .clip(OZTheme.shapes.cornerRadius50percent), color = if (completed) completedColor else unCompletedColor, thickness = 2.dp ) } -
COMPONENTS - STEP PROGRESS BAR @Composable fun Step( modi fi
er: Modi fi er = Modi fi er, completed: Boolean, completedColor: Color, unCompletedColor: Color ) { Divider( modi fi er = modi fi er .width(20.dp) .clip(OZTheme.shapes.cornerRadius50percent), color = if (completed) completedColor else unCompletedColor, thickness = 2.dp ) } -
COMPONENTS - STEP PROGRESS BAR @Composable fun Step( modi fi
er: Modi fi er = Modi fi er, completed: Boolean, completedColor: Color, unCompletedColor: Color ) { Divider( modi fi er = modi fi er .width(20.dp) .clip(OZTheme.shapes.cornerRadius50percent), color = if (completed) completedColor else unCompletedColor, thickness = 2.dp ) } -
COMPONENTS - STEP PROGRESS BAR @Preview(name = "Step Progress Bar
/ Light Mode", showBackground = true, uiMode = Con fi guration.UI_MODE_NIGHT_NO) @Preview(name = "Step Progress Bar / Dark Mode", showBackground = true, uiMode = Con fi guration.UI_MODE_NIGHT_YES) @Composable fun StepProgressBarPreview() { OZTheme { StepProgressBar(numberOfSteps = 10, currentStep = 2) } } @Preview(name = "Step Progress Bar / General Mode", showBackground = true, uiMode = Con fi guration.UI_MODE_NIGHT_YES) @Composable fun StepProgressBarGeneralPreview() { OZTheme(isGeneralMode = true) { StepProgressBar(numberOfSteps = 6, currentStep = 3) } } -
COMPONENTS - TESTING class StepProgressBarViewTest { @get:Rule val paparazzi =
Paparazzi( theme = "android:Theme.AppCompat", deviceCon fi g = DeviceCon fi g.NEXUS_5, ) // screenshot tests here } -
COMPONENTS - TESTING class StepProgressBarViewTest { @get:Rule val paparazzi =
Paparazzi( theme = "android:Theme.AppCompat", deviceCon fi g = DeviceCon fi g.NEXUS_5, ) // screenshot tests here } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - TESTING @Test fun sixStepsTwoCompleted() { paparazzi.snapshot { OZTheme
{ Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modi fi er = Modi fi er . fi llMaxSize() .background(backgroundColor), ) { StepProgressBar( modi fi er = Modi fi er.background(componentBackgroundColor), numberOfSteps = 6, currentStep = 2, ) } } } } -
COMPONENTS - CONCLUSION • Translate design needs into the right
parameters like a “Variant” • We can’t call something @Composable inside enums or classes but we can hold a Composable lambda • Use cashapp/paparazzi to screenshot-test your components -
INTEROP - USING COMPONENTS <?xml version="1.0" encoding="utf-8"?> <merge ...> <androidx.appcompat.widget.Toolbar
...> <androidx.compose.ui.platform.ComposeView android:id="@+id/step_progress_bar" android:layout_width="match_parent" android:layout_height="match_parent" /> </androidx.appcompat.widget.Toolbar> </merge> -
INTEROP - USING COMPONENTS <?xml version="1.0" encoding="utf-8"?> <merge ...> <androidx.appcompat.widget.Toolbar
...> <androidx.compose.ui.platform.ComposeView android:id="@+id/step_progress_bar" android:layout_width="match_parent" android:layout_height="match_parent" /> </androidx.appcompat.widget.Toolbar> </merge> -
INTEROP - USING COMPONENTS binding.stepProgressBar.setOZContent(forceLtr = false) { Column( verticalArrangement
= Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { StepProgressBar( numberOfSteps = numberOfSteps, currentStep = currentStep ) } } -
INTEROP - USING COMPONENTS binding.stepProgressBar.setOZContent(forceLtr = false) { Column( verticalArrangement
= Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { StepProgressBar( numberOfSteps = numberOfSteps, currentStep = currentStep ) } } -
INTEROP - USING COMPONENTS binding.stepProgressBar.setOZContent(forceLtr = false) { Column( verticalArrangement
= Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { StepProgressBar( numberOfSteps = numberOfSteps, currentStep = currentStep ) } } -
INTEROP - USING COMPONENTS binding.stepProgressBar.setOZContent(forceLtr = false) { Column( verticalArrangement
= Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { StepProgressBar( numberOfSteps = numberOfSteps, currentStep = currentStep ) } } -
INTEROP - USING COMPONENTS binding.stepProgressBar.setOZContent(forceLtr = false) { Column( verticalArrangement
= Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { StepProgressBar( numberOfSteps = numberOfSteps, currentStep = currentStep ) } } -
INTEROP - USING COMPONENTS binding.stepProgressBar.setOZContent(forceLtr = false) { Column( verticalArrangement
= Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { StepProgressBar( numberOfSteps = numberOfSteps, currentStep = currentStep ) } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - USING COMPONENTS fun ComposeView.setOZContent( forceLtr: Boolean = true,
content: @Composable () -> Unit, ) { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { OZTheme { val direction = if (forceLtr) LayoutDirection.Ltr else LocalLayoutDirection.current CompositionLocalProvider( LocalLayoutDirection provides direction, content = content ) } } } -
INTEROP - CONCLUSION • Build your helper functions to make
it easy to use • Do not forget setViewCompositionStrategy() -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - BASE FRAGMENTS abstract class ComposeFragment : Fragment()
{ protected open val isThemeInGeneralMode: Boolean = false override fun onCreateView(in fl ater: LayoutIn fl ater, c: ViewGroup?, sub: Bundle?): View? { return setOZContent(isThemeInGeneralMode) { ComposeContent() } } @Composable protected abstract fun ComposeContent() } -
FULL SCREENS - USING BASE FRAGMENT class SomeComposeFragment: ComposeFragment() {
@Composable override fun ComposeContent() { TestComposeScreen() } } -
FULL SCREENS - USING BASE FRAGMENT class SomeComposeFragment: ComposeFragment() {
@Composable override fun ComposeContent() { TestComposeScreen() } } -
FULL SCREENS - USING BASE FRAGMENT class SomeComposeFragment: ComposeFragment() {
@Composable override fun ComposeContent() { TestComposeScreen() } } -
FULL SCREENS - USING BASE FRAGMENT class SomeComposeFragment: ComposeFragment() {
@Composable override fun ComposeContent() { TestComposeScreen() } } -
FULL SCREENS - USING BASE FRAGMENT fun TestComposeScreen(testViewModel: TestMVIViewModel =
viewModel()) { val uiState by testViewModel.uiState.collectAsState() Column(modi fi er = Modi fi er. fi llMaxSize()) { when (uiState) { TestUiState.Initial -> Text("Initial State") TestUiState.SecondState -> Text("Second State") } } } -
FULL SCREENS - USING BASE FRAGMENT fun TestComposeScreen(testViewModel: TestMVIViewModel =
viewModel()) { val uiState by testViewModel.uiState.collectAsState() Column(modi fi er = Modi fi er. fi llMaxSize()) { when (uiState) { TestUiState.Initial -> Text("Initial State") TestUiState.SecondState -> Text("Second State") } } } -
FULL SCREENS - USING BASE FRAGMENT fun TestComposeScreen(testViewModel: TestMVIViewModel =
viewModel()) { val uiState by testViewModel.uiState.collectAsState() Column(modi fi er = Modi fi er. fi llMaxSize()) { when (uiState) { TestUiState.Initial -> Text("Initial State") TestUiState.SecondState -> Text("Second State") } } } -
FULL SCREENS - USING BASE FRAGMENT fun TestComposeScreen(testViewModel: TestMVIViewModel =
viewModel()) { val uiState by testViewModel.uiState.collectAsState() Column(modi fi er = Modi fi er. fi llMaxSize()) { when (uiState) { TestUiState.Initial -> Text("Initial State") TestUiState.SecondState -> Text("Second State") } } } -
FULL SCREENS - USING BASE FRAGMENT fun TestComposeScreen(testViewModel: TestMVIViewModel =
viewModel()) { val uiState by testViewModel.uiState.collectAsState() Column(modi fi er = Modi fi er. fi llMaxSize()) { when (uiState) { TestUiState.Initial -> Text("Initial State") TestUiState.SecondState -> Text("Second State") } } } -
FULL SCREENS - USING BASE FRAGMENT class SomeComposeFragment: ComposeFragment() {
@Composable override fun ComposeContent() { TestComposeScreen() } } -
NAVIGATION • Jetpack Navigation for Compose • Compose-destinations by Rafael
Costa (1.3k stars on Github) • Voyager by Adiel Café (659 stars on Github) -
THANK YOU! Alexander Gherschon Android Tech Lead @ ONE
ZERO Digital Bank Blog - https://galex.co.il/ Twitter - https://twitter.com/galex Github - https://github.com/galex Linkedin - https://www.linkedin.com/in/agherschon/