Skip to content

Commit

Permalink
[SwipeRefresh] Make scrollable requirements clearer in docs (#407)
Browse files Browse the repository at this point in the history
* Improve SwipeRefresh kdoc

Added some info about scrollable content

* Add SwipeRefresh scrollable para to guide

* Fix spotless

* Fix typo
  • Loading branch information
chrisbanes authored May 12, 2021
1 parent 328f7df commit c0ab995
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 17 additions & 1 deletion docs/swiperefresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ SwipeRefresh(

The full example, including the view model implementation can be found [here](https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/swiperefresh/DocsSamples.kt).

The content needs to be 'scrollable' for `SwipeRefresh()` to be able to react to swipe gestures. Layouts such as [`LazyColumn`][lazycolumn] are automatically scrollable, but others such as [`Column`][column] are not. In those instances, you can provide a [`Modifier.verticalScroll`][verticalscroll] modifier to that content like so:

``` kotlin
SwipeRefresh(
// ...
) {
Column(Modifier.verticalScroll(rememberScrollState())) {
// content
}
}
```


### Indicating a refresh without swiping

As this library is built with a seperate state object, it's easy to display a refreshing indicator without a swipe to triggering it.
Expand Down Expand Up @@ -124,4 +137,7 @@ Snapshots of the development version are available in [Sonatype's `snapshots` re
[api_swiperefreshindicator]: ../api/swiperefresh/swiperefresh/com.google.accompanist.swiperefresh/-swipe-refresh-indicator.html
[api_swiperefresh]: ../api/swiperefresh/swiperefresh/com.google.accompanist.swiperefresh/-swipe-refresh.html
[api_rememberstate]: ../api/swiperefresh/swiperefresh/com.google.accompanist.swiperefresh/remember-swipe-refresh-state.html
[sample_customindictor]: https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshCustomIndicatorSample.kt
[sample_customindictor]: https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshCustomIndicatorSample.kt
[lazycolumn]: https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#LazyColumn(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Function1)
[column]: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#Column(androidx.compose.ui.Modifier,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,kotlin.Function1)
[verticalscroll]: https://developer.android.com/jetpack/compose/gestures#scroll-modifiers
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,22 @@ private class SwipeRefreshNestedScrollConnection(
}

/**
* A layout which implements the swipe-to-refresh pattern.
* A layout which implements the swipe-to-refresh pattern, allowing the user to refresh content via
* a vertical swipe gesture.
*
* The layout can be used whenever the user has the ability to refresh content via a vertical
* swipe gesture.
* This layout requires its content to be scrollable so that it receives vertical swipe events.
* The scrollable content does not need to be a direct descendant though. Layouts such as
* [androidx.compose.foundation.lazy.LazyColumn] are automatically scrollable, but others such as
* [androidx.compose.foundation.layout.Column] require you to provide the
* [androidx.compose.foundation.verticalScroll] modifier to that content.
*
* Apps should provide a [onRefresh] block to be notified each time a swipe to refresh gesture
* is completed. That block is responsible for updating the [state] as appropriately,
* typically by setting [SwipeRefreshState.isRefreshing] to `true` once a 'refresh' has been
* started. Once a refresh has completed, the app should then set
* [SwipeRefreshState.isRefreshing] to `false`.
*
* If an app wishes to show just the progress animation, outside of a swipe refresh, it can
* If an app wishes to show the progress animation outside of a swipe gesture, it can
* set [SwipeRefreshState.isRefreshing] as required.
*
* This layout does not clip any of it's contents, including the indicator. If clipping
Expand Down

0 comments on commit c0ab995

Please sign in to comment.