Skip to content

Commit

Permalink
Improve ShowkaseBrowser codebase and update navigation stack
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaygaba committed Jun 5, 2024
1 parent b487e64 commit 5723051
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 190 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
'composeCompiler' : '1.5.13',
'composeActivity' : '1.9.0',
'composeConstraintLayout': '1.0.1',
'composeNavigation' : '2.5.1',
'composeNavigation' : '2.7.7',
'detekt' : '1.7.4',
'espresso' : '3.2.0',
'gradle' : '8.1.1',
Expand All @@ -22,10 +22,10 @@ buildscript {
'kotlinXMetadata' : '0.6.0',
'ksp' : "$KSP_VERSION",
'ktx' : '1.1.0',
'lifecycle' : '2.2.0',
'lifecycle' : '2.6.2',
'paparazzi' : '1.2.0',
'picasso' : '2.8',
'appcompat' : '1.4.0',
'appcompat' : '1.6.1',
'testRunner' : '1.4.0',
'testParameterInjector' : '1.8',
'googleTruth' : '1.1.3',
Expand Down Expand Up @@ -66,7 +66,8 @@ buildscript {
'support' : [
'appCompat' : "androidx.appcompat:appcompat:${versions.appcompat}",
'ktx' : "androidx.core:core-ktx:${versions.corektx}",
'lifecycleExtensions': "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}"
'lifecycleComposeViewModel' : "androidx.lifecycle:lifecycle-viewmodel-compose:${versions.lifecycle}",
'lifecycleComposeRuntime' : "androidx.lifecycle:lifecycle-runtime-compose:${versions.lifecycle}",
],
'test' : [
'androidXTestCore' : "androidx.test:core:${versions.androidXTestCore}",
Expand Down
3 changes: 2 additions & 1 deletion sample-submodule-2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ dependencies {
// Support Libraries
implementation deps.support.appCompat
implementation deps.support.ktx
implementation deps.support.lifecycleExtensions
implementation deps.support.lifecycleComposeViewModel
implementation deps.support.lifecycleComposeRuntime

// Showkase
implementation project(':showkase')
Expand Down
3 changes: 2 additions & 1 deletion sample-submodule/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ dependencies {
// Support Libraries
implementation deps.support.appCompat
implementation deps.support.ktx
implementation deps.support.lifecycleExtensions
implementation deps.support.lifecycleComposeViewModel
implementation deps.support.lifecycleComposeRuntime

// Showkase
implementation project(':showkase')
Expand Down
3 changes: 2 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ dependencies {
// Support Libraries
implementation deps.support.appCompat
implementation deps.support.ktx
implementation deps.support.lifecycleExtensions
implementation deps.support.lifecycleComposeViewModel
implementation deps.support.lifecycleComposeRuntime

// Compose
implementation deps.compose.activityCompose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,3 @@ internal fun ShowkaseBrowserScreenMetadata.clearActiveSearch() = copy(
isSearchActive = false,
searchQuery = null
)

internal fun <T> MutableState<T>.update(block: T.() -> T) {
value = this.component1().run(block)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.airbnb.android.showkase.ui

import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.compose.material.Text
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand All @@ -12,6 +13,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -32,10 +34,10 @@ fun SimpleTextCard(
onClick = onClick
) {
Text(
text = text,
text = text,
modifier = Modifier.padding(padding4x),
style = TextStyle(
fontSize = 20.sp,
fontSize = 20.sp,
fontFamily = FontFamily.Serif,
fontWeight = FontWeight.Bold
)
Expand All @@ -47,8 +49,10 @@ fun SimpleTextCard(
internal fun ComponentCardTitle(componentName: String) {
Text(
text = componentName,
modifier = Modifier.padding(start = padding4x, end = padding4x, top = padding8x,
bottom = padding1x),
modifier = Modifier.padding(
start = padding4x, end = padding4x, top = padding8x,
bottom = padding1x
),
style = TextStyle(
fontSize = 16.sp,
fontFamily = FontFamily.Serif,
Expand All @@ -63,30 +67,33 @@ internal fun ComponentCard(
onClick: (() -> Unit)? = null,
darkMode: Boolean = false,
) {
val composableModifier = Modifier.generateComposableModifier(metadata)
val composableContainerModifier = Modifier.generateContainerModifier(onClick)
MaterialTheme(
colors = if (darkMode) darkColors() else lightColors()
) {
Card(
shape = MaterialTheme.shapes.large
val backPressedDispatcherOwner = rememberOnBackPressedDispatcherOwner()
CompositionLocalProvider(LocalOnBackPressedDispatcherOwner provides backPressedDispatcherOwner) {
val composableModifier = Modifier.generateComposableModifier(metadata)
val composableContainerModifier = Modifier.generateContainerModifier(onClick)
MaterialTheme(
colors = if (darkMode) darkColors() else lightColors()
) {
Box {
Column(modifier = composableModifier) {
metadata.component()
Card(
shape = MaterialTheme.shapes.large
) {
Box {
Column(modifier = composableModifier) {
metadata.component()
}
// Need to add this as part of the stack so that we can intercept the touch of the
// component when we are on the "Group components" screen. If
// composableContainerModifier does not have any clickable modifiers, this column has no
// impact and the touches go through to the component(this happens in the "Component
// Detail" screen.
Column(
modifier = Modifier
.matchParentSize()
.then(composableContainerModifier)
) {}
}
// Need to add this as part of the stack so that we can intercept the touch of the
// component when we are on the "Group components" screen. If
// composableContainerModifier does not have any clickable modifiers, this column has no
// impact and the touches go through to the component(this happens in the "Component
// Detail" screen.
Column(
modifier = Modifier
.matchParentSize()
.then(composableContainerModifier)
) {}
}

}
}
}
}
Expand Down
Loading

0 comments on commit 5723051

Please sign in to comment.