Skip to content

Commit dad2800

Browse files
authored
Merge pull request #1385 from google/ben/swiperefresh_deprecation
[SwipeRefresh] Deprecate SwipeRefresh
2 parents 9706080 + 07071a7 commit dad2800

File tree

18 files changed

+164
-39
lines changed

18 files changed

+164
-39
lines changed

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ A library which provides [Compose Material](https://developer.android.com/jetpac
5858
### 🖌️ [Drawable Painter](./drawablepainter/)
5959
A library which provides a way to use Android Drawables as Jetpack Compose Painters.
6060

61-
### ⬇️ [Swipe to Refresh](./swiperefresh/)
62-
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).
63-
6461
### 🌏 [Web](./web/)
6562
A wrapper around WebView for basic WebView support in Jetpack Compose.
6663

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

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

7575
## Future?

docs/swiperefresh.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22

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

5+
!!! warning
6+
**This library is deprecated, with official pull refresh support in androidx.compose.material.pullrefresh The migration guide and original documentation is below.
7+
8+
## Migration
9+
10+
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.
11+
12+
A simple example is as follows:
13+
14+
```kotlin
15+
val viewModel: MyViewModel = viewModel()
16+
val refreshing by viewModel.isRefreshing
17+
18+
val pullRefreshState = rememberPullRefreshState(refreshing, { viewModel.refresh() })
19+
20+
Box(Modifier.pullRefresh(pullRefreshState)) {
21+
LazyColumn(Modifier.fillMaxSize()) {
22+
...
23+
}
24+
25+
PullRefreshIndicator(refreshing, pullRefreshState, Modifier.align(Alignment.TopCenter))
26+
}
27+
```
28+
29+
### Migration steps
30+
31+
1. Replace SwipeRefresh with a Box or other layout of your choice, save your `onRefresh` lambda for the next step.
32+
2. Replace `rememberSwipeRefreshState()` with `rememberPullRefreshState(refreshing, onRefresh)`
33+
3. Add either the default `PullRefreshIndicator` or your own custom implementation to your layout.
34+
35+
### Custom Indicator
36+
37+
Instead of using the provided `PullRefreshIndicator` composable, you can create your own custom indicator.
38+
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).
39+
40+
## Original Docs
41+
542
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).
643

744
<figure>

sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderBasicSample.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,27 @@ package com.google.accompanist.sample.placeholder
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22+
import androidx.compose.foundation.layout.Box
2223
import androidx.compose.foundation.layout.fillMaxSize
2324
import androidx.compose.foundation.layout.padding
2425
import androidx.compose.foundation.lazy.LazyColumn
26+
import androidx.compose.material.ExperimentalMaterialApi
2527
import androidx.compose.material.MaterialTheme
2628
import androidx.compose.material.Scaffold
2729
import androidx.compose.material.Text
2830
import androidx.compose.material.TopAppBar
2931
import androidx.compose.material.icons.Icons
3032
import androidx.compose.material.icons.filled.ArrowDownward
33+
import androidx.compose.material.pullrefresh.PullRefreshIndicator
34+
import androidx.compose.material.pullrefresh.pullRefresh
35+
import androidx.compose.material.pullrefresh.rememberPullRefreshState
3136
import androidx.compose.runtime.Composable
3237
import androidx.compose.runtime.LaunchedEffect
3338
import androidx.compose.runtime.getValue
3439
import androidx.compose.runtime.mutableStateOf
3540
import androidx.compose.runtime.remember
3641
import androidx.compose.runtime.setValue
42+
import androidx.compose.ui.Alignment
3743
import androidx.compose.ui.Modifier
3844
import androidx.compose.ui.graphics.vector.rememberVectorPainter
3945
import androidx.compose.ui.res.stringResource
@@ -43,8 +49,6 @@ import com.google.accompanist.placeholder.material.placeholder
4349
import com.google.accompanist.sample.AccompanistSampleTheme
4450
import com.google.accompanist.sample.R
4551
import com.google.accompanist.sample.randomSampleImageUrl
46-
import com.google.accompanist.swiperefresh.SwipeRefresh
47-
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
4852
import kotlinx.coroutines.delay
4953

5054
class PlaceholderBasicSample : ComponentActivity() {
@@ -59,7 +63,7 @@ class PlaceholderBasicSample : ComponentActivity() {
5963
}
6064
}
6165

62-
@OptIn(ExperimentalCoilApi::class)
66+
@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class)
6367
@Composable
6468
private fun Sample() {
6569
Scaffold(
@@ -81,10 +85,12 @@ private fun Sample() {
8185
}
8286
}
8387

84-
SwipeRefresh(
85-
state = rememberSwipeRefreshState(isRefreshing = refreshing),
86-
onRefresh = { refreshing = true },
87-
) {
88+
val state = rememberPullRefreshState(
89+
refreshing = refreshing,
90+
onRefresh = { refreshing = true }
91+
)
92+
93+
Box(Modifier.pullRefresh(state)) {
8894
LazyColumn(contentPadding = padding) {
8995
if (refreshing.not()) {
9096
item {
@@ -104,6 +110,12 @@ private fun Sample() {
104110
)
105111
}
106112
}
113+
114+
PullRefreshIndicator(
115+
refreshing = refreshing,
116+
state = state,
117+
modifier = Modifier.align(Alignment.TopCenter)
118+
)
107119
}
108120
}
109121
}

sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderFadeSample.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@ package com.google.accompanist.sample.placeholder
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22+
import androidx.compose.foundation.layout.Box
2223
import androidx.compose.foundation.layout.fillMaxSize
2324
import androidx.compose.foundation.lazy.LazyColumn
25+
import androidx.compose.material.ExperimentalMaterialApi
2426
import androidx.compose.material.MaterialTheme
2527
import androidx.compose.material.Scaffold
2628
import androidx.compose.material.Text
2729
import androidx.compose.material.TopAppBar
2830
import androidx.compose.material.icons.Icons
2931
import androidx.compose.material.icons.filled.ArrowDownward
32+
import androidx.compose.material.pullrefresh.PullRefreshIndicator
33+
import androidx.compose.material.pullrefresh.pullRefresh
34+
import androidx.compose.material.pullrefresh.rememberPullRefreshState
3035
import androidx.compose.runtime.Composable
3136
import androidx.compose.runtime.LaunchedEffect
3237
import androidx.compose.runtime.getValue
3338
import androidx.compose.runtime.mutableStateOf
3439
import androidx.compose.runtime.remember
3540
import androidx.compose.runtime.setValue
41+
import androidx.compose.ui.Alignment
3642
import androidx.compose.ui.Modifier
3743
import androidx.compose.ui.graphics.vector.rememberVectorPainter
3844
import androidx.compose.ui.res.stringResource
@@ -44,8 +50,6 @@ import com.google.accompanist.placeholder.material.placeholder
4450
import com.google.accompanist.sample.AccompanistSampleTheme
4551
import com.google.accompanist.sample.R
4652
import com.google.accompanist.sample.randomSampleImageUrl
47-
import com.google.accompanist.swiperefresh.SwipeRefresh
48-
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
4953
import kotlinx.coroutines.delay
5054

5155
class PlaceholderFadeSample : ComponentActivity() {
@@ -60,7 +64,7 @@ class PlaceholderFadeSample : ComponentActivity() {
6064
}
6165
}
6266

63-
@OptIn(ExperimentalCoilApi::class)
67+
@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class)
6468
@Composable
6569
private fun Sample() {
6670
Scaffold(
@@ -82,10 +86,12 @@ private fun Sample() {
8286
}
8387
}
8488

85-
SwipeRefresh(
86-
state = rememberSwipeRefreshState(isRefreshing = refreshing),
87-
onRefresh = { refreshing = true },
88-
) {
89+
val state = rememberPullRefreshState(
90+
refreshing = refreshing,
91+
onRefresh = { refreshing = true }
92+
)
93+
94+
Box(Modifier.pullRefresh(state)) {
8995
LazyColumn(contentPadding = padding) {
9096
if (refreshing.not()) {
9197
item {
@@ -108,6 +114,12 @@ private fun Sample() {
108114
)
109115
}
110116
}
117+
118+
PullRefreshIndicator(
119+
refreshing = refreshing,
120+
state = state,
121+
modifier = Modifier.align(Alignment.TopCenter)
122+
)
111123
}
112124
}
113125
}

sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderShimmerSample.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@ package com.google.accompanist.sample.placeholder
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22+
import androidx.compose.foundation.layout.Box
2223
import androidx.compose.foundation.layout.fillMaxSize
2324
import androidx.compose.foundation.lazy.LazyColumn
25+
import androidx.compose.material.ExperimentalMaterialApi
2426
import androidx.compose.material.MaterialTheme
2527
import androidx.compose.material.Scaffold
2628
import androidx.compose.material.Text
2729
import androidx.compose.material.TopAppBar
2830
import androidx.compose.material.icons.Icons
2931
import androidx.compose.material.icons.filled.ArrowDownward
32+
import androidx.compose.material.pullrefresh.PullRefreshIndicator
33+
import androidx.compose.material.pullrefresh.pullRefresh
34+
import androidx.compose.material.pullrefresh.rememberPullRefreshState
3035
import androidx.compose.runtime.Composable
3136
import androidx.compose.runtime.LaunchedEffect
3237
import androidx.compose.runtime.getValue
3338
import androidx.compose.runtime.mutableStateOf
3439
import androidx.compose.runtime.remember
3540
import androidx.compose.runtime.setValue
41+
import androidx.compose.ui.Alignment
3642
import androidx.compose.ui.Modifier
3743
import androidx.compose.ui.graphics.vector.rememberVectorPainter
3844
import androidx.compose.ui.res.stringResource
@@ -44,8 +50,6 @@ import com.google.accompanist.placeholder.material.shimmer
4450
import com.google.accompanist.sample.AccompanistSampleTheme
4551
import com.google.accompanist.sample.R
4652
import com.google.accompanist.sample.randomSampleImageUrl
47-
import com.google.accompanist.swiperefresh.SwipeRefresh
48-
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
4953
import kotlinx.coroutines.delay
5054

5155
class PlaceholderShimmerSample : ComponentActivity() {
@@ -60,7 +64,7 @@ class PlaceholderShimmerSample : ComponentActivity() {
6064
}
6165
}
6266

63-
@OptIn(ExperimentalCoilApi::class)
67+
@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class)
6468
@Composable
6569
private fun Sample() {
6670
Scaffold(
@@ -82,10 +86,12 @@ private fun Sample() {
8286
}
8387
}
8488

85-
SwipeRefresh(
86-
state = rememberSwipeRefreshState(isRefreshing = refreshing),
87-
onRefresh = { refreshing = true },
88-
) {
89+
val state = rememberPullRefreshState(
90+
refreshing = refreshing,
91+
onRefresh = { refreshing = true }
92+
)
93+
94+
Box(Modifier.pullRefresh(state)) {
8995
LazyColumn(contentPadding = padding) {
9096
if (refreshing.not()) {
9197
item {
@@ -108,6 +114,12 @@ private fun Sample() {
108114
)
109115
}
110116
}
117+
118+
PullRefreshIndicator(
119+
refreshing = refreshing,
120+
state = state,
121+
modifier = Modifier.align(Alignment.TopCenter)
122+
)
111123
}
112124
}
113125
}

sample/src/main/java/com/google/accompanist/sample/swiperefresh/DocsSamples.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
@file:Suppress("UNUSED_ANONYMOUS_PARAMETER")
17+
@file:Suppress("UNUSED_ANONYMOUS_PARAMETER", "DEPRECATION")
1818

1919
package com.google.accompanist.sample.swiperefresh
2020

sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshBasicSample.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SwipeRefreshBasicSample : ComponentActivity() {
6262
}
6363
}
6464

65+
@Suppress("DEPRECATION")
6566
@OptIn(ExperimentalCoilApi::class)
6667
@Composable
6768
private fun Sample() {
@@ -84,8 +85,9 @@ private fun Sample() {
8485
}
8586
}
8687

88+
val state = rememberSwipeRefreshState(isRefreshing = true)
8789
SwipeRefresh(
88-
state = rememberSwipeRefreshState(isRefreshing = refreshing),
90+
state = state,
8991
onRefresh = { refreshing = true },
9092
) {
9193
LazyColumn(contentPadding = padding) {

sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshContentPaddingSample.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class SwipeRefreshContentPaddingSample : ComponentActivity() {
7272

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

75+
@Suppress("DEPRECATION")
7576
@Composable
7677
private fun Sample() {
7778
val systemUiController = rememberSystemUiController()

sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshCustomIndicatorSample.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("DEPRECATION")
18+
1719
package com.google.accompanist.sample.swiperefresh
1820

1921
import android.os.Bundle
@@ -71,6 +73,7 @@ class SwipeRefreshCustomIndicatorSample : ComponentActivity() {
7173
}
7274
}
7375

76+
@Suppress("DEPRECATION")
7477
@Composable
7578
private fun Sample() {
7679
Scaffold(

sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshTweakedIndicatorSample.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SwipeRefreshTweakedIndicatorSample : ComponentActivity() {
6363
}
6464
}
6565

66+
@Suppress("DEPRECATION")
6667
@OptIn(ExperimentalCoilApi::class)
6768
@Composable
6869
private fun Sample() {

sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshVerticalPagerSample.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SwipeRefreshVerticalPagerSample : ComponentActivity() {
6868
}
6969
}
7070

71+
@Suppress("DEPRECATION")
7172
@OptIn(ExperimentalPagerApi::class, ExperimentalCoilApi::class)
7273
@Composable
7374
private fun Sample() {

swiperefresh/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
For more information, visit the documentation: https://google.github.io/accompanist/swiperefresh
5+
> :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.
66
77
## Download
88

0 commit comments

Comments
 (0)