https://github.com/s1rius/android-nest-scroll-ptr
android pull-to-refresh layout work with nested-scroll
https://github.com/s1rius/android-nest-scroll-ptr
android jetpack-compose kotlin nestedscroll pull-to-refresh
Last synced: about 1 year ago
JSON representation
android pull-to-refresh layout work with nested-scroll
- Host: GitHub
- URL: https://github.com/s1rius/android-nest-scroll-ptr
- Owner: s1rius
- License: mit
- Created: 2019-10-05T15:30:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-24T15:22:47.000Z (about 4 years ago)
- Last Synced: 2025-04-10T23:42:30.142Z (about 1 year ago)
- Topics: android, jetpack-compose, kotlin, nestedscroll, pull-to-refresh
- Language: Kotlin
- Homepage:
- Size: 15.3 MB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# android-nest-scroll-ptr
[中文介绍](https://github.com/s1rius/android-nest-scroll-ptr/blob/master/README_CN.md)
This library implements pull-to-refresh logic and work with nested-scroll. It is easy to use and extend.
It is driven by a [StateMachine](https://github.com/Tinder/StateMachine)

### Requirements
- minsdk 14/21(compose)
- kotlin | compose
### Features
- driven by a FSM
- work with nested-scroll
- Jetpack Compose implementation
- easy to customize the layout
### Demo
- Ins
- Wechat
- Wechat Moment
- NestedScroll Sample
### Use NSPtr in your application
- add the dependency
```
repositories {
...
mavenCentral()
...
}
dependencies {
...
// android view system implementation
implementation "wtf.s1.ui:nsptr-view:x.x.x"
// jetpack compose implementation
implementation "wtf.s1.ui:nsptr-compose:x.x.x"
...
}
```
- use in Compose
```kotlin
val coroutine = rememberCoroutineScope()
val nsPtrState = remember {
NSPtrState(
coroutineScope = coroutine
) {
// todo refresh block
it.dispatchPtrEvent(Event.RefreshComplete)
}
}
NSPtrLayout(
nsPtrState = nsPtrState,
modifier = Modifier.fillMaxSize(),
) {
NSPtrEZHeader(
modifier = Modifier
.offset(0.dp, 12.dp),
nsPtrState = nsPtrState
)
LazyColumn(Modifier.ptrContent()) {
items(10) { index ->
// todo
}
}
}
```
- add a layout to view hierarchy
```kotlin
addView(
NSPtrEZLayout(context).apply {
addView(
RecyclerView(context).apply {
// add data and adapter
},
NSPtrLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT
)
)
addPtrListener(object : NSPtrListener {
override fun onRefreshing(ptrLayout: NSPtrLayout) {
super.onRefreshing(ptrLayout)
// do refresh logic
}
})
// auto refresh
isRefreshing = true
},
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
)
```
- or use in XML layouts
```xml
```