-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ShowkaseBrowser codebase and update navigation stack #390
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
// Showkase | ||
implementation project(':showkase') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here |
||
|
||
// Compose | ||
implementation deps.compose.activityCompose | ||
|
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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
) | ||
|
@@ -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, | ||
|
@@ -63,30 +67,35 @@ 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 | ||
// This is added to make sure that the navigation of the ShowkaseBrowser does not break | ||
// when one of the previews has a back press handler in the implementation of the component. | ||
val backPressedDispatcherOwner = rememberOnBackPressedDispatcherOwner() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing this at the top level (which was previously the case) was causing the navigation to not work at all. Instead, I moved this down to specifically happen for the Composables that are responsible for rendering the component previews as that's where we want to override/intercept any back handling that the previews might be doing themselves. Doing so fixed the issue but I'm not 100% on why doing this at the top level didn't work okay. |
||
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) | ||
) {} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space was lost here :)?