Skip to content

Commit

Permalink
Migrate from Accompanist SwipeRefresh to PullRefresh (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
AfigAliyev committed Mar 25, 2023
1 parent 4ad6b19 commit d2bcc30
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
4 changes: 3 additions & 1 deletion core/core-designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ android.namespace = "com.maximillianleonov.cinemax.core.designsystem"

dependencies {
api(libs.bundles.androidx.compose)
api(libs.accompanist.swiperefresh)
api(libs.accompanist.placeholder.material)
api(libs.coil.compose)

implementation(libs.androidx.compose.material)

debugApi(libs.androidx.compose.ui.tooling)
debugApi(libs.androidx.compose.ui.test.manifest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

package com.maximillianleonov.cinemax.core.designsystem.component

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator
import com.google.accompanist.swiperefresh.SwipeRefreshState
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.maximillianleonov.cinemax.core.designsystem.theme.CinemaxTheme

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun CinemaxSwipeRefresh(
isRefreshing: Boolean,
Expand All @@ -36,24 +39,23 @@ fun CinemaxSwipeRefresh(
backgroundColor: Color = CinemaxTheme.colors.primaryVariant,
contentColor: Color = CinemaxTheme.colors.accent,
indicatorPadding: PaddingValues = PaddingValues(0.dp),
indicator: @Composable (state: SwipeRefreshState, refreshTrigger: Dp) -> Unit =
{ state, refreshTrigger ->
SwipeRefreshIndicator(
state = state,
refreshTriggerDistance = refreshTrigger,
backgroundColor = backgroundColor,
contentColor = contentColor
)
},
swipeRefreshState: SwipeRefreshState = rememberSwipeRefreshState(isRefreshing = isRefreshing),
indicatorAlignment: Alignment = Alignment.TopCenter,
scale: Boolean = true,
content: @Composable () -> Unit
) {
SwipeRefresh(
modifier = modifier,
state = swipeRefreshState,
onRefresh = onRefresh,
indicatorPadding = indicatorPadding,
indicator = indicator,
content = content
)
val state = rememberPullRefreshState(refreshing = isRefreshing, onRefresh = onRefresh)
Box(modifier = modifier.pullRefresh(state = state)) {
content()

PullRefreshIndicator(
modifier = Modifier
.padding(indicatorPadding)
.align(indicatorAlignment),
refreshing = isRefreshing,
state = state,
backgroundColor = backgroundColor,
contentColor = contentColor,
scale = scale
)
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ androidx-annotation = { module = "androidx.annotation:annotation", version.ref =

androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-compose-material = { module = "androidx.compose.material:material" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
Expand Down Expand Up @@ -108,7 +109,6 @@ accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-
accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanist" }
accompanist-pager-indicators = { module = "com.google.accompanist:accompanist-pager-indicators", version.ref = "accompanist" }
accompanist-placeholder-material = { module = "com.google.accompanist:accompanist-placeholder-material", version.ref = "accompanist" }
accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "accompanist" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }

detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
Expand Down

0 comments on commit d2bcc30

Please sign in to comment.