-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42ba282
commit 31ec69c
Showing
5 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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
40 changes: 32 additions & 8 deletions
40
ui/common/src/main/java/org/kafka/common/extensions/elevation.kt
This file contains 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 |
---|---|---|
@@ -1,17 +1,41 @@ | ||
package org.kafka.common.extensions | ||
|
||
import androidx.compose.foundation.ScrollState | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.foundation.lazy.grid.LazyGridState | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import ui.common.theme.theme.Dimens | ||
|
||
object Elevation { | ||
val LazyListState.elevation: Dp | ||
get() = if (firstVisibleItemIndex == 0) { | ||
// For the first element, use the minimum of scroll offset and default elevation | ||
// i.e. a value between 0 and 4.dp | ||
minOf(firstVisibleItemScrollOffset.toFloat().dp, 24.dp) | ||
val ScrollState.elevation | ||
get() = derivedStateOf { | ||
this.run { ((value / 100) * 2).coerceAtMost(MaxElevation).dp } ?: 0.dp | ||
} | ||
|
||
val LazyListState.elevation: Dp | ||
get() = if (firstVisibleItemIndex == 0) { | ||
// For the first element, use the minimum of scroll offset and default elevation | ||
// i.e. a value between 0 and 4.dp | ||
minOf(firstVisibleItemScrollOffset.toFloat().dp, 24.dp) | ||
} else { | ||
// If not the first element, always set elevation and show the shadow | ||
24.dp | ||
} | ||
|
||
|
||
val LazyListState?.elevation | ||
get() = derivedStateOf { | ||
if (this?.firstVisibleItemIndex == 0) { | ||
minOf(firstVisibleItemScrollOffset.toFloat().dp, MaxElevation.dp) | ||
} else { | ||
// If not the first element, always set elevation and show the shadow | ||
24.dp | ||
Dimens.Spacing20 | ||
} | ||
} | ||
|
||
|
||
fun LazyGridState.elevation(maxElevation: Int = 40) = derivedStateOf { | ||
this.run { firstVisibleItemScrollOffset.coerceAtMost(maxElevation) }.dp | ||
} | ||
|
||
private const val MaxElevation = 20 |
This file contains 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 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