-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from phucynwa/support_staggered_grid
Support Staggered Grid
- Loading branch information
Showing
4 changed files
with
519 additions
and
2 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
60 changes: 60 additions & 0 deletions
60
lib/src/commonMain/kotlin/my/nanihadesuka/compose/LazyHorizontalStaggeredGridScrollbar.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package my.nanihadesuka.compose | ||
|
||
import androidx.compose.foundation.gestures.Orientation | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import my.nanihadesuka.compose.controller.rememberLazyStaggeredGridStateController | ||
import my.nanihadesuka.compose.generic.ElementScrollbar | ||
|
||
@Composable | ||
fun LazyHorizontalStaggeredGridScrollbar( | ||
state: LazyStaggeredGridState, | ||
modifier: Modifier = Modifier, | ||
reverseLayout: Boolean = false, | ||
settings: ScrollbarSettings = ScrollbarSettings.Default, | ||
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null, | ||
content: @Composable () -> Unit | ||
) { | ||
if (!settings.enabled) content() | ||
else Box(modifier) { | ||
content() | ||
InternalLazyHorizontalGridScrollbar( | ||
state = state, | ||
reverseLayout = reverseLayout, | ||
settings = settings, | ||
indicatorContent = indicatorContent, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Use this variation if you want to place the scrollbar independently of the list position | ||
*/ | ||
@Composable | ||
fun InternalLazyHorizontalGridScrollbar( | ||
state: LazyStaggeredGridState, | ||
modifier: Modifier = Modifier, | ||
reverseLayout: Boolean = false, | ||
settings: ScrollbarSettings = ScrollbarSettings.Default, | ||
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null, | ||
) { | ||
val controller = rememberLazyStaggeredGridStateController( | ||
state = state, | ||
reverseLayout = reverseLayout, | ||
thumbMinLength = settings.thumbMinLength, | ||
thumbMaxLength = settings.thumbMaxLength, | ||
alwaysShowScrollBar = settings.alwaysShowScrollbar, | ||
selectionMode = settings.selectionMode, | ||
orientation = Orientation.Horizontal | ||
) | ||
|
||
ElementScrollbar( | ||
orientation = Orientation.Horizontal, | ||
stateController = controller, | ||
modifier = modifier, | ||
settings = settings, | ||
indicatorContent = indicatorContent | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
lib/src/commonMain/kotlin/my/nanihadesuka/compose/LazyVerticalStaggeredGridScrollbar.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package my.nanihadesuka.compose | ||
|
||
import androidx.compose.foundation.gestures.Orientation | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import my.nanihadesuka.compose.controller.rememberLazyStaggeredGridStateController | ||
import my.nanihadesuka.compose.generic.ElementScrollbar | ||
|
||
@Composable | ||
fun LazyVerticalStaggeredGridScrollbar( | ||
state: LazyStaggeredGridState, | ||
modifier: Modifier = Modifier, | ||
reverseLayout: Boolean = false, | ||
settings: ScrollbarSettings = ScrollbarSettings.Default, | ||
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null, | ||
content: @Composable () -> Unit | ||
) { | ||
if (!settings.enabled) content() | ||
else Box(modifier) { | ||
content() | ||
InternalLazyVerticalGridScrollbar( | ||
state = state, | ||
reverseLayout = reverseLayout, | ||
settings = settings, | ||
indicatorContent = indicatorContent, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Use this variation if you want to place the scrollbar independently of the list position | ||
*/ | ||
@Composable | ||
fun InternalLazyVerticalGridScrollbar( | ||
state: LazyStaggeredGridState, | ||
modifier: Modifier = Modifier, | ||
reverseLayout: Boolean = false, | ||
settings: ScrollbarSettings = ScrollbarSettings.Default, | ||
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null, | ||
) { | ||
val controller = rememberLazyStaggeredGridStateController( | ||
state = state, | ||
reverseLayout = reverseLayout, | ||
thumbMinLength = settings.thumbMinLength, | ||
thumbMaxLength = settings.thumbMaxLength, | ||
alwaysShowScrollBar = settings.alwaysShowScrollbar, | ||
selectionMode = settings.selectionMode, | ||
orientation = Orientation.Vertical | ||
) | ||
|
||
ElementScrollbar( | ||
orientation = Orientation.Vertical, | ||
stateController = controller, | ||
modifier = modifier, | ||
settings = settings, | ||
indicatorContent = indicatorContent | ||
) | ||
} |
Oops, something went wrong.