generated from JetBrains/compose-multiplatform-ios-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
8c6516b
commit e9373e2
Showing
8 changed files
with
188 additions
and
91 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
68 changes: 68 additions & 0 deletions
68
shared/src/commonMain/kotlin/net/schacher/mcc/shared/design/compose/PagerHeader.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,68 @@ | ||
package net.schacher.mcc.shared.design.compose | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.foundation.pager.PagerState | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.TextUnit | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import kotlinx.coroutines.launch | ||
import net.schacher.mcc.shared.design.theme.ContentPadding | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun PagerHeader( | ||
pageLabels: List<String>, | ||
pagerState: PagerState, | ||
modifier: Modifier = Modifier, | ||
fontSize: TextUnit = 24.sp, | ||
onLabelClick: (Int) -> Unit | ||
) { | ||
val scope = rememberCoroutineScope() | ||
|
||
val selectedItem = pagerState.currentPage | ||
val state = rememberLazyListState() | ||
|
||
scope.launch { | ||
if (selectedItem > 0) { | ||
state.scrollToItem(selectedItem - 1, 0) | ||
} else { | ||
state.scrollToItem(selectedItem, 0) | ||
} | ||
} | ||
|
||
LazyRow( | ||
modifier = modifier, | ||
state = state, | ||
userScrollEnabled = false | ||
) { | ||
pageLabels.forEachIndexed { index, it -> | ||
item { | ||
val selected = selectedItem == index | ||
|
||
Text( | ||
text = it, | ||
fontSize = fontSize, | ||
color = MaterialTheme.colors.onBackground, | ||
fontWeight = FontWeight.SemiBold, | ||
modifier = Modifier | ||
.padding( | ||
start = if (index == 0) ContentPadding else 0.dp, | ||
end = 12.dp | ||
) | ||
.noRippleClickable { onLabelClick(index) } | ||
.alpha(if (selected) 1f else 0.35f), | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.