From 84984ef7e1d7242924120cd2f171cb9dd75bc916 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 2 Mar 2024 19:02:53 +0600 Subject: [PATCH] Remove custom Pager Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> --- .../presentation/components/TabbedDialog.kt | 7 +-- .../presentation/components/TabbedScreen.kt | 2 +- .../library/components/LibraryPager.kt | 2 +- .../presentation/core/components/Pager.kt | 56 ------------------- 4 files changed, 5 insertions(+), 62 deletions(-) delete mode 100644 presentation-core/src/main/java/tachiyomi/presentation/core/components/Pager.kt diff --git a/app/src/main/java/eu/kanade/presentation/components/TabbedDialog.kt b/app/src/main/java/eu/kanade/presentation/components/TabbedDialog.kt index dfba8cd612..4ef2e97713 100644 --- a/app/src/main/java/eu/kanade/presentation/components/TabbedDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/components/TabbedDialog.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.wrapContentSize +import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material.icons.Icons @@ -29,7 +30,6 @@ import androidx.compose.ui.util.fastForEachIndexed import kotlinx.collections.immutable.ImmutableList import kotlinx.coroutines.launch import tachiyomi.i18n.MR -import tachiyomi.presentation.core.components.HorizontalPager import tachiyomi.presentation.core.components.material.TabText import tachiyomi.presentation.core.i18n.stringResource @@ -78,9 +78,8 @@ fun TabbedDialog( modifier = Modifier.animateContentSize(), state = pagerState, verticalAlignment = Alignment.Top, - ) { page -> - content(page) - } + pageContent = { page -> content(page) } + ) } } } diff --git a/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt b/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt index 9dae3de14f..efb1e2e049 100644 --- a/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material3.MaterialTheme import androidx.compose.material3.PrimaryTabRow @@ -24,7 +25,6 @@ import dev.icerock.moko.resources.StringResource import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.launch -import tachiyomi.presentation.core.components.HorizontalPager import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.TabText import tachiyomi.presentation.core.i18n.stringResource diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt index db7af58752..6487ab39f6 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -22,7 +23,6 @@ import eu.kanade.tachiyomi.ui.library.LibraryItem import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.library.model.LibraryManga import tachiyomi.i18n.MR -import tachiyomi.presentation.core.components.HorizontalPager import tachiyomi.presentation.core.screens.EmptyScreen import tachiyomi.presentation.core.util.plus diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/Pager.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/Pager.kt deleted file mode 100644 index fb3cbdf749..0000000000 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/Pager.kt +++ /dev/null @@ -1,56 +0,0 @@ -package tachiyomi.presentation.core.components - -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.pager.PageSize -import androidx.compose.foundation.pager.PagerDefaults -import androidx.compose.foundation.pager.PagerScope -import androidx.compose.foundation.pager.PagerSnapDistance -import androidx.compose.foundation.pager.PagerState -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.NestedScrollConnection -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp - -/** - * Horizontal Pager with custom SnapFlingBehavior for a more natural swipe feeling - */ -@Composable -fun HorizontalPager( - state: PagerState, - modifier: Modifier = Modifier, - contentPadding: PaddingValues = PaddingValues(0.dp), - pageSize: PageSize = PageSize.Fill, - beyondBoundsPageCount: Int = 0, - pageSpacing: Dp = 0.dp, - verticalAlignment: Alignment.Vertical = Alignment.CenterVertically, - userScrollEnabled: Boolean = true, - reverseLayout: Boolean = false, - key: ((index: Int) -> Any)? = null, - pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( - state = state, - orientation = Orientation.Horizontal, - ), - pageContent: @Composable PagerScope.(page: Int) -> Unit, -) { - androidx.compose.foundation.pager.HorizontalPager( - state = state, - modifier = modifier, - contentPadding = contentPadding, - pageSize = pageSize, - outOfBoundsPageCount = beyondBoundsPageCount, - pageSpacing = pageSpacing, - verticalAlignment = verticalAlignment, - flingBehavior = PagerDefaults.flingBehavior( - state = state, - pagerSnapDistance = PagerSnapDistance.atMost(0), - ), - userScrollEnabled = userScrollEnabled, - reverseLayout = reverseLayout, - key = key, - pageNestedScrollConnection = pageNestedScrollConnection, - pageContent = pageContent, - ) -}