-
Notifications
You must be signed in to change notification settings - Fork 3
fix: pinned tabs with viewpager and drop shadow #968
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
Open
jvsena42
wants to merge
20
commits into
master
Choose a base branch
from
fix/design-review-181
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f061c77
fix: add widgets icon
jvsena42 2ca84a7
fix: implement PinnedTabsScaffold with dropshadow effect
jvsena42 bfe3429
fix: implement viewpager
jvsena42 6fb99d4
fix: map top padding
jvsena42 8358f89
fix: implement viewpager
jvsena42 f37d9e6
fix: remove viewpager
jvsena42 3c24dbe
fix: apply blur bg to the tab
jvsena42 43b371b
fix: apply blur to AppTopBar
jvsena42 e93c06b
fix: apply default bg color
jvsena42 2b6f782
fix: bg transparency
jvsena42 f2462cf
fix: recompose on tab change
jvsena42 c89dd88
fix: scroll to top on tab change
jvsena42 5d338e3
fix: apply padding to empty state text
jvsena42 655c6c7
fix: modifier reuse
jvsena42 4956d22
fix: implement subcompose for measure calculation to avoid recomposition
jvsena42 57c57a3
refactor: move PinnedTabsScaffold.kt to scaffold directory
jvsena42 f726fc1
Merge branch 'master' into fix/design-review-181
jvsena42 36fd82f
fix: keep the parent HorizontalPager from intercept horizontal pan wh…
jvsena42 9c22f70
refactor: remove dead padding
jvsena42 f3781d9
fix: consume only top padding
jvsena42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
app/src/main/java/to/bitkit/ui/scaffold/PinnedTabsScaffold.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package to.bitkit.ui.scaffold | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.ColumnScope | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Brush | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.layout.SubcomposeLayout | ||
| import androidx.compose.ui.unit.Dp | ||
| import androidx.compose.ui.unit.dp | ||
| import dev.chrisbanes.haze.HazeStyle | ||
| import dev.chrisbanes.haze.HazeTint | ||
| import dev.chrisbanes.haze.hazeEffect | ||
| import dev.chrisbanes.haze.hazeSource | ||
| import dev.chrisbanes.haze.rememberHazeState | ||
| import to.bitkit.ui.theme.Colors | ||
|
|
||
| private val PinnedTabsShadowHeight = 32.dp | ||
| private val PinnedTabsBlurRadius = 24.dp | ||
|
|
||
| private enum class PinnedTabsSlot { Header, Content, Shadow } | ||
|
|
||
| @Composable | ||
| fun PinnedTabsScaffold( | ||
| header: @Composable ColumnScope.() -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| content: @Composable (topPadding: Dp) -> Unit, | ||
| ) { | ||
| val hazeState = rememberHazeState() | ||
| val shadowBrush = remember { | ||
| Brush.verticalGradient(colors = listOf(Colors.Black, Color.Transparent)) | ||
| } | ||
| val hazeStyle = remember { | ||
| HazeStyle( | ||
| backgroundColor = Colors.Black, | ||
| tint = HazeTint(Colors.Black70), | ||
| blurRadius = PinnedTabsBlurRadius, | ||
| ) | ||
| } | ||
|
|
||
| SubcomposeLayout(modifier = modifier.fillMaxSize()) { constraints -> | ||
| val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0) | ||
|
|
||
| val headerPlaceables = subcompose(PinnedTabsSlot.Header) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .hazeEffect(state = hazeState, style = hazeStyle), | ||
| content = { header() }, | ||
| ) | ||
| }.map { it.measure(looseConstraints) } | ||
|
|
||
| val headerHeightPx = headerPlaceables.maxOfOrNull { it.height } ?: 0 | ||
| val headerHeightDp = headerHeightPx.toDp() | ||
|
|
||
| val contentPlaceables = subcompose(PinnedTabsSlot.Content) { | ||
| Box( | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .hazeSource(hazeState) | ||
| ) { | ||
| content(headerHeightDp) | ||
| } | ||
| }.map { it.measure(constraints) } | ||
|
|
||
| val shadowPlaceables = subcompose(PinnedTabsSlot.Shadow) { | ||
| Box( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .height(PinnedTabsShadowHeight) | ||
| .background(shadowBrush) | ||
| ) | ||
| }.map { it.measure(looseConstraints) } | ||
|
|
||
| layout(constraints.maxWidth, constraints.maxHeight) { | ||
| contentPlaceables.forEach { it.placeRelative(0, 0) } | ||
| shadowPlaceables.forEach { it.placeRelative(0, headerHeightPx) } | ||
| headerPlaceables.forEach { it.placeRelative(0, 0) } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.