Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SwipeRefresh] Deprecate SwipeRefresh #1385

Merged
merged 7 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -58,9 +58,6 @@ A library which provides [Compose Material](https://developer.android.com/jetpac
### 🖌️ [Drawable Painter](./drawablepainter/)
A library which provides a way to use Android Drawables as Jetpack Compose Painters.

### ⬇️ [Swipe to Refresh](./swiperefresh/)
A library that provides a layout implementing the swipe-to-refresh UX pattern, similar to Android's [SwipeRefreshLayout](https://developer.android.com/jetpack/androidx/releases/swiperefreshlayout).

### 🌏 [Web](./web/)
A wrapper around WebView for basic WebView support in Jetpack Compose.

Expand All @@ -70,6 +67,9 @@ A library providing a collection of utilities for adaptive layouts.
### 📐 [Insets](./insets/) (Deprecated)
See our [Migration Guide](https://google.github.io/accompanist/insets/) for migrating to Insets in Compose.

### ⬇️ [Swipe to Refresh](./swiperefresh/) (Deprecated)
See our [Migration Guide](https://google.github.io/accompanist/swiperefresh/) for migrating to PullRefresh in Compose Material.

---

## Future?
Expand Down
37 changes: 37 additions & 0 deletions docs/swiperefresh.md
Expand Up @@ -2,6 +2,43 @@

[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-swiperefresh)](https://search.maven.org/search?q=g:com.google.accompanist)

!!! warning
**This library is deprecated, with official pull refresh support in androidx.compose.material.pullrefresh The migration guide and original documentation is below.

## Migration

Accompanist SwipeRefresh has been replaced by PullRefresh in [Compose Material 1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-material#1.3.0). The implementation is similar but instead of being a Composable function, it is a Modifier that can be applied to a Composable function.

A simple example is as follows:

```kotlin
val viewModel: MyViewModel = viewModel()
val refreshing by viewModel.isRefreshing

val pullRefreshState = rememberPullRefreshState(refreshing, { viewModel.refresh() })

Box(Modifier.pullRefresh(pullRefreshState)) {
LazyColumn(Modifier.fillMaxSize()) {
...
}

PullRefreshIndicator(refreshing, pullRefreshState, Modifier.align(Alignment.TopCenter))
}
```

### Migration steps

1. Replace SwipeRefresh with a Box or other layout of your choice, save your `onRefresh` lambda for the next step.
2. Replace `rememberSwipeRefreshState()` with `rememberPullRefreshState(refreshing, onRefresh)`
3. Add either the default `PullRefreshIndicator` or your own custom implementation to your layout.

### Custom Indicator

Instead of using the provided `PullRefreshIndicator` composable, you can create your own custom indicator.
A full sample can be seen in the [Compose samples](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material/material/samples/src/main/java/androidx/compose/material/samples/PullRefreshSamples.kt;l=91?q=pullrefresh).

## Original Docs

A library which provides a layout which provides the swipe-to-refresh UX pattern, similar to Android's [`SwipeRefreshLayout`](https://developer.android.com/training/swipe/add-swipe-interface).

<figure>
Expand Down
Expand Up @@ -19,21 +19,27 @@ package com.google.accompanist.sample.placeholder
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDownward
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.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource
Expand All @@ -43,8 +49,6 @@ import com.google.accompanist.placeholder.material.placeholder
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.R
import com.google.accompanist.sample.randomSampleImageUrl
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import kotlinx.coroutines.delay

class PlaceholderBasicSample : ComponentActivity() {
Expand All @@ -59,7 +63,7 @@ class PlaceholderBasicSample : ComponentActivity() {
}
}

@OptIn(ExperimentalCoilApi::class)
@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class)
@Composable
private fun Sample() {
Scaffold(
Expand All @@ -81,10 +85,12 @@ private fun Sample() {
}
}

SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing = refreshing),
onRefresh = { refreshing = true },
) {
val state = rememberPullRefreshState(
refreshing = refreshing,
onRefresh = { refreshing = true }
)

Box(Modifier.pullRefresh(state)) {
LazyColumn(contentPadding = padding) {
if (refreshing.not()) {
item {
Expand All @@ -104,6 +110,12 @@ private fun Sample() {
)
}
}

PullRefreshIndicator(
refreshing = refreshing,
state = state,
modifier = Modifier.align(Alignment.TopCenter)
)
}
}
}
Expand Up @@ -19,20 +19,26 @@ package com.google.accompanist.sample.placeholder
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDownward
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.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource
Expand All @@ -44,8 +50,6 @@ import com.google.accompanist.placeholder.material.placeholder
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.R
import com.google.accompanist.sample.randomSampleImageUrl
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import kotlinx.coroutines.delay

class PlaceholderFadeSample : ComponentActivity() {
Expand All @@ -60,7 +64,7 @@ class PlaceholderFadeSample : ComponentActivity() {
}
}

@OptIn(ExperimentalCoilApi::class)
@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class)
@Composable
private fun Sample() {
Scaffold(
Expand All @@ -82,10 +86,12 @@ private fun Sample() {
}
}

SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing = refreshing),
onRefresh = { refreshing = true },
) {
val state = rememberPullRefreshState(
refreshing = refreshing,
onRefresh = { refreshing = true }
)

Box(Modifier.pullRefresh(state)) {
LazyColumn(contentPadding = padding) {
if (refreshing.not()) {
item {
Expand All @@ -108,6 +114,12 @@ private fun Sample() {
)
}
}

PullRefreshIndicator(
refreshing = refreshing,
state = state,
modifier = Modifier.align(Alignment.TopCenter)
)
}
}
}
Expand Up @@ -19,20 +19,26 @@ package com.google.accompanist.sample.placeholder
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDownward
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.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource
Expand All @@ -44,8 +50,6 @@ import com.google.accompanist.placeholder.material.shimmer
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.R
import com.google.accompanist.sample.randomSampleImageUrl
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import kotlinx.coroutines.delay

class PlaceholderShimmerSample : ComponentActivity() {
Expand All @@ -60,7 +64,7 @@ class PlaceholderShimmerSample : ComponentActivity() {
}
}

@OptIn(ExperimentalCoilApi::class)
@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class)
@Composable
private fun Sample() {
Scaffold(
Expand All @@ -82,10 +86,12 @@ private fun Sample() {
}
}

SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing = refreshing),
onRefresh = { refreshing = true },
) {
val state = rememberPullRefreshState(
refreshing = refreshing,
onRefresh = { refreshing = true }
)

Box(Modifier.pullRefresh(state)) {
LazyColumn(contentPadding = padding) {
if (refreshing.not()) {
item {
Expand All @@ -108,6 +114,12 @@ private fun Sample() {
)
}
}

PullRefreshIndicator(
refreshing = refreshing,
state = state,
modifier = Modifier.align(Alignment.TopCenter)
)
}
}
}
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

@file:Suppress("UNUSED_ANONYMOUS_PARAMETER")
@file:Suppress("UNUSED_ANONYMOUS_PARAMETER", "DEPRECATION")

package com.google.accompanist.sample.swiperefresh

Expand Down
Expand Up @@ -62,6 +62,7 @@ class SwipeRefreshBasicSample : ComponentActivity() {
}
}

@Suppress("DEPRECATION")
@OptIn(ExperimentalCoilApi::class)
@Composable
private fun Sample() {
Expand All @@ -84,8 +85,9 @@ private fun Sample() {
}
}

val state = rememberSwipeRefreshState(isRefreshing = true)
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing = refreshing),
state = state,
onRefresh = { refreshing = true },
) {
LazyColumn(contentPadding = padding) {
Expand Down
Expand Up @@ -72,6 +72,7 @@ class SwipeRefreshContentPaddingSample : ComponentActivity() {

private val listItems = List(40) { randomSampleImageUrl(it) }

@Suppress("DEPRECATION")
@Composable
private fun Sample() {
val systemUiController = rememberSystemUiController()
Expand Down
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.accompanist.sample.swiperefresh

import android.os.Bundle
Expand Down Expand Up @@ -71,6 +73,7 @@ class SwipeRefreshCustomIndicatorSample : ComponentActivity() {
}
}

@Suppress("DEPRECATION")
@Composable
private fun Sample() {
Scaffold(
Expand Down
Expand Up @@ -63,6 +63,7 @@ class SwipeRefreshTweakedIndicatorSample : ComponentActivity() {
}
}

@Suppress("DEPRECATION")
@OptIn(ExperimentalCoilApi::class)
@Composable
private fun Sample() {
Expand Down
Expand Up @@ -68,6 +68,7 @@ class SwipeRefreshVerticalPagerSample : ComponentActivity() {
}
}

@Suppress("DEPRECATION")
@OptIn(ExperimentalPagerApi::class, ExperimentalCoilApi::class)
@Composable
private fun Sample() {
Expand Down
2 changes: 1 addition & 1 deletion swiperefresh/README.md
Expand Up @@ -2,7 +2,7 @@

[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-swiperefresh)](https://search.maven.org/search?q=g:com.google.accompanist)

For more information, visit the documentation: https://google.github.io/accompanist/swiperefresh
> :warning: This library has been deprecated as official support is now available in Compose Material 1.3.0. Please see our [Migration Guide](https://google.github.io/accompanist/swiperefresh/) for how to migrate.

## Download

Expand Down