-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/mobile elevation #762
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9e79362
feat(theme): add mobile elevation tokens
comfrt1k 76d547b
feat(theme): add elevation modifier
comfrt1k 78ee31f
chore(theme): mark legacy elevation tokens
comfrt1k bd832e4
fix(theme): use native elevation shadows
comfrt1k cf7def2
fix(theme): render inner elevation shadows
comfrt1k c6af972
fix(theme): align subtle action colors
comfrt1k ac3fb7f
fix(theme): add focused elevation shadows
comfrt1k f631880
refactor(theme): extract elevation tokens
comfrt1k 17a6d9b
fix(theme): remove invalid elevation immutability
comfrt1k 48e8ff0
feat(theme): elevation story
comfrt1k e81f508
fix(theme): remove focused elevation state
comfrt1k 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
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
50 changes: 50 additions & 0 deletions
50
mobile/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/primitives/Elevation.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,50 @@ | ||
| package com.atls.hyperion.ui.primitives | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.dropShadow | ||
| import androidx.compose.ui.draw.innerShadow | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.graphics.RectangleShape | ||
| import androidx.compose.ui.graphics.Shape | ||
| import androidx.compose.ui.graphics.shadow.Shadow | ||
| import androidx.compose.ui.unit.DpOffset | ||
| import com.atls.hyperion.ui.theme.tokens.elevation.Elevation | ||
| import com.atls.hyperion.ui.theme.tokens.elevation.ShadowType | ||
|
|
||
| fun Modifier.elevation( | ||
| elevation: Elevation, | ||
| backgroundColor: Color, | ||
| shape: Shape = RectangleShape | ||
| ): Modifier { | ||
| val withDropShadows = elevation.shadows.fold(this) { modifier, shadow -> | ||
| if (shadow.type == ShadowType.Drop) { | ||
| modifier.dropShadow( | ||
| shape = shape, | ||
| shadow = shadow.toComposeShadow() | ||
| ) | ||
| } else { | ||
| modifier | ||
| } | ||
| } | ||
|
|
||
| val withBackground = withDropShadows.background(backgroundColor, shape) | ||
|
|
||
| return elevation.shadows.fold(withBackground) { modifier, shadow -> | ||
| if (shadow.type == ShadowType.Inner) { | ||
| modifier.innerShadow( | ||
| shape = shape, | ||
| shadow = shadow.toComposeShadow() | ||
| ) | ||
| } else { | ||
| modifier | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun com.atls.hyperion.ui.theme.tokens.elevation.Shadow.toComposeShadow() = Shadow( | ||
| radius = blur, | ||
| spread = spread, | ||
| offset = DpOffset(offsetX, offsetY), | ||
| color = color | ||
| ) | ||
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
17 changes: 17 additions & 0 deletions
17
mobile/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/theme/tokens/elevation/Blurs.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,17 @@ | ||
| package com.atls.hyperion.ui.theme.tokens.elevation | ||
|
|
||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| object ShadowBlur { | ||
| val xs5 = 1.dp | ||
| val xs4 = 2.dp | ||
| val xs3 = 3.dp | ||
| val xs2 = 4.dp | ||
| val xs = 5.dp | ||
| val sm = 6.dp | ||
| val md = 8.dp | ||
| val lg = 12.dp | ||
| val xl = 14.dp | ||
| val xl2 = 16.dp | ||
| val xl3 = 20.dp | ||
| } |
136 changes: 136 additions & 0 deletions
136
...le/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/theme/tokens/elevation/Elevations.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,136 @@ | ||
| package com.atls.hyperion.ui.theme.tokens.elevation | ||
|
|
||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.unit.Dp | ||
| import com.atls.hyperion.ui.theme.tokens.colors.Colors | ||
|
|
||
| class Elevations(colors: Colors) { | ||
| val xs: PressableElevationStates = Xs(colors.elevation.xs) | ||
| val sm: PressableElevationStates = Sm(colors.elevation.sm) | ||
| val md: PressableElevationStates = Md(colors.elevation.md) | ||
| val lg: PressableElevationStates = Lg(colors.elevation.lg) | ||
| val modal: ElevationStates = Modal(colors.elevation.md) | ||
|
|
||
| private class Xs(color: Color) : PressableElevationStates { | ||
| override val default = elevation( | ||
| drop(color, offsetY = ShadowOffset.xs, blur = ShadowBlur.xs4) | ||
| ) | ||
| override val pressed = elevation( | ||
| inner(color, offsetY = ShadowOffset.xs, blur = ShadowBlur.xs5), | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.xs, | ||
| blur = ShadowBlur.xs5, | ||
| spread = ShadowSpread.negativeXs | ||
| ) | ||
| ) | ||
| override val disabled = elevation( | ||
| drop(color, offsetY = ShadowOffset.xs, blur = ShadowBlur.xs5) | ||
| ) | ||
| } | ||
|
|
||
| private class Sm(color: Color) : PressableElevationStates { | ||
| override val default = elevation( | ||
| drop(color, offsetY = ShadowOffset.sm, blur = ShadowBlur.sm) | ||
| ) | ||
| override val pressed = elevation( | ||
| inner(color, offsetY = ShadowOffset.xs, blur = ShadowBlur.xs4), | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.xs, | ||
| blur = ShadowBlur.xs3, | ||
| spread = ShadowSpread.negativeSm | ||
| ) | ||
| ) | ||
| override val disabled = elevation( | ||
| drop(color, offsetY = ShadowOffset.xs, blur = ShadowBlur.xs4) | ||
| ) | ||
| } | ||
|
|
||
| private class Md(color: Color) : PressableElevationStates { | ||
| override val default = elevation( | ||
| drop(color, offsetY = ShadowOffset.lg, blur = ShadowBlur.lg) | ||
| ) | ||
| override val pressed = elevation( | ||
| inner(color, offsetY = ShadowOffset.xs, blur = ShadowBlur.xs3), | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.sm, | ||
| blur = ShadowBlur.sm, | ||
| spread = ShadowSpread.negativeXs | ||
| ) | ||
| ) | ||
| override val disabled = elevation( | ||
| drop(color, offsetY = ShadowOffset.sm, blur = ShadowBlur.xs) | ||
| ) | ||
| } | ||
|
|
||
| private class Lg(color: Color) : PressableElevationStates { | ||
| override val default = elevation( | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.xl, | ||
| blur = ShadowBlur.lg, | ||
| spread = ShadowSpread.negativeLg | ||
| ) | ||
| ) | ||
| override val pressed = elevation( | ||
| inner(color, offsetY = ShadowOffset.sm, blur = ShadowBlur.xs2), | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.md, | ||
| blur = ShadowBlur.md, | ||
| spread = ShadowSpread.negativeLg | ||
| ) | ||
| ) | ||
| override val disabled = elevation( | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.md, | ||
| blur = ShadowBlur.sm, | ||
| spread = ShadowSpread.negativeMd | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| private class Modal(color: Color) : ElevationStates { | ||
| override val default = elevation( | ||
| drop( | ||
| color, | ||
| offsetY = ShadowOffset.xl3, | ||
| blur = ShadowBlur.xl3, | ||
| spread = ShadowSpread.negativeSm | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun elevation(vararg shadows: Shadow) = Elevation(shadows.toList()) | ||
|
|
||
| private fun drop( | ||
| color: Color, | ||
| offsetX: Dp = ShadowOffset.none, | ||
| offsetY: Dp, | ||
| blur: Dp, | ||
| spread: Dp = ShadowSpread.none | ||
| ) = Shadow( | ||
| type = ShadowType.Drop, | ||
| offsetX = offsetX, | ||
| offsetY = offsetY, | ||
| blur = blur, | ||
| spread = spread, | ||
| color = color | ||
| ) | ||
|
|
||
| private fun inner( | ||
| color: Color, | ||
| offsetY: Dp, | ||
| blur: Dp | ||
| ) = Shadow( | ||
| type = ShadowType.Inner, | ||
| offsetX = ShadowOffset.none, | ||
| offsetY = offsetY, | ||
| blur = blur, | ||
| spread = ShadowSpread.none, | ||
| color = color | ||
| ) |
33 changes: 33 additions & 0 deletions
33
...le/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/theme/tokens/elevation/Interfaces.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,33 @@ | ||
| package com.atls.hyperion.ui.theme.tokens.elevation | ||
|
|
||
| import androidx.compose.runtime.Immutable | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.unit.Dp | ||
|
|
||
| data class Elevation( | ||
| val shadows: List<Shadow> | ||
|
TorinAsakura marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| @Immutable | ||
| data class Shadow( | ||
| val type: ShadowType, | ||
| val offsetX: Dp, | ||
| val offsetY: Dp, | ||
| val blur: Dp, | ||
| val spread: Dp, | ||
| val color: Color | ||
| ) | ||
|
|
||
| enum class ShadowType { | ||
| Drop, | ||
| Inner | ||
| } | ||
|
|
||
| interface ElevationStates { | ||
| val default: Elevation | ||
| } | ||
|
|
||
| interface PressableElevationStates : ElevationStates { | ||
| val pressed: Elevation | ||
| val disabled: Elevation | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
mobile/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/theme/tokens/elevation/Offsets.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,14 @@ | ||
| package com.atls.hyperion.ui.theme.tokens.elevation | ||
|
|
||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| object ShadowOffset { | ||
| val none = 0.dp | ||
| val xs = 1.dp | ||
| val sm = 2.dp | ||
| val md = 3.dp | ||
| val lg = 4.dp | ||
| val xl = 6.dp | ||
| val xl2 = 7.dp | ||
| val xl3 = 12.dp | ||
| } |
12 changes: 12 additions & 0 deletions
12
mobile/kmp/ui/src/commonMain/kotlin/com/atls/hyperion/ui/theme/tokens/elevation/Spreads.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,12 @@ | ||
| package com.atls.hyperion.ui.theme.tokens.elevation | ||
|
|
||
| import androidx.compose.ui.unit.dp | ||
|
|
||
| object ShadowSpread { | ||
| val negativeLg = (-4).dp | ||
| val negativeMd = (-3).dp | ||
| val negativeSm = (-2).dp | ||
| val negativeXs = (-1).dp | ||
| val none = 0.dp | ||
| val xs = 1.dp | ||
| } |
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.