Skip to content

Commit

Permalink
发布v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Apr 20, 2024
1 parent 0985cce commit 71a97b7
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 114 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,18 @@

```gradle
// 极致体验的Compose刷新组件 (*必须)
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh:1.1.0'
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh:1.1.1'
// 经典样式的指示器 (可选)
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh-indicator-classic:1.1.0'
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh-indicator-classic:1.1.1'
// Lottie动画指示器 (可选)
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh-indicator-lottie:1.1.0'
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh-indicator-lottie:1.1.1'
// 进度条样式的指示器 (可选)
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh-indicator-progress:1.1.0'
implementation 'com.github.jenly1314.UltraSwipeRefresh:refresh-indicator-progress:1.1.1'
```

## 使用

### UltraSwipeRefreshTheme(v1.1.0新增)

UltraSwipeRefreshTheme:主要用于统一管理全局默认配置。

> 通常情况下,一个App使用的刷新样式是统一的,如果你需要进行全局统一刷新组件的样式时,可以通过`UltraSwipeRefreshTheme.config`来动态修改`UltraSwipeRefresh`的全局默认配置。
#### UltraSwipeRefreshTheme使用示例

```kotlin
// 全局设置默认的滑动模式
UltraSwipeRefreshTheme.config = UltraSwipeRefreshTheme.config.copy(
headerScrollMode = NestedScrollMode.Translate,
footerScrollMode = NestedScrollMode.Translate,
)
```

### UltraSwipeRefresh

**Compose** 组件的使用大都比较直观,一般只需看一下 **Composable** 函数对应的参数说明基本就会使用了。
Expand Down Expand Up @@ -168,6 +152,22 @@ fun UltraSwipeRefreshSample() {

> 使用小提示:**headerIndicator/footerIndicator****headerScrollMode/footerScrollMode** 组合使用才更配哦。
### UltraSwipeRefreshTheme(v1.1.0新增)

UltraSwipeRefreshTheme:主要用于统一管理全局默认配置。

> 通常情况下,一个App使用的刷新样式是统一的,如果你需要进行全局统一刷新组件的样式时,可以通过`UltraSwipeRefreshTheme.config`来动态修改`UltraSwipeRefresh`的全局默认配置。
#### UltraSwipeRefreshTheme使用示例

```kotlin
// 全局设置默认的滑动模式
UltraSwipeRefreshTheme.config = UltraSwipeRefreshTheme.config.copy(
headerScrollMode = NestedScrollMode.Translate,
footerScrollMode = NestedScrollMode.Translate,
)
```

### 指示器样式

这里罗列一下目前 **UltraSwipeRefresh** 所包含的一些Header和Footer指示器样式,方便快速查找与参考。
Expand Down Expand Up @@ -198,6 +198,10 @@ fun UltraSwipeRefreshSample() {

## 版本记录

#### v1.1.1 2024-4-20
* 修复BUG:刷新状态变化太快时,导致”完成时的定格提示动画”不执行的问题。([#4]
* 优化一些细节

#### v1.1.0 2023-12-17

* 新增`UltraSwipeRefreshTheme`:用于统一管理全局默认配置
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 2,
"versionName": "1.1.0",
"versionCode": 3,
"versionName": "1.1.1",
"outputFile": "app-release.apk"
}
],
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

VERSION_NAME=1.1.0
VERSION_CODE=2
VERSION_NAME=1.1.1
VERSION_CODE=3
GROUP=com.github.jenly1314.UltraSwipeRefresh

POM_DESCRIPTION=UltraSwipeRefresh for Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,40 +73,28 @@ internal fun ClassicRefreshIndicator(
if (isFooter) {
LaunchedEffect(state.footerState) {
when (state.footerState) {
UltraSwipeFooterState.PullUpToLoad -> {
arrowDegrees.animateTo(180f)
}

UltraSwipeFooterState.ReleaseToLoad -> {
arrowDegrees.animateTo(0f)
}

else -> {

}
else -> arrowDegrees.animateTo(180f)
}
}
} else {
LaunchedEffect(state.headerState) {
when (state.headerState) {
UltraSwipeHeaderState.PullDownToRefresh -> {
arrowDegrees.animateTo(0f)
}

UltraSwipeHeaderState.ReleaseToRefresh -> {
arrowDegrees.animateTo(180f)
}

else -> {

}
else -> arrowDegrees.animateTo(0f)
}
}
}

val alphaState = remember {
derivedStateOf {
if ((state.indicatorOffset > 0f && !isFooter) || (state.indicatorOffset < 0f && isFooter)) {
if ((!isFooter && state.indicatorOffset > 0f) || (isFooter && state.indicatorOffset < 0f)) {
1f
} else {
0f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
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.draw.alpha
Expand Down Expand Up @@ -45,12 +43,14 @@ internal fun LottieRefreshIndicator(
) {
val composition by rememberLottieComposition(spec = spec)

var isPlaying by remember { mutableStateOf(false) }

isPlaying = if (isFooter) {
state.footerState == UltraSwipeFooterState.Loading
} else {
state.headerState == UltraSwipeHeaderState.Refreshing
val isPlaying by remember {
derivedStateOf {
if (isFooter) {
state.footerState == UltraSwipeFooterState.Loading
} else {
state.headerState == UltraSwipeHeaderState.Refreshing
}
}
}

val progress by animateLottieCompositionAsState(
Expand All @@ -64,7 +64,7 @@ internal fun LottieRefreshIndicator(

val alphaState = remember {
derivedStateOf {
if ((state.indicatorOffset > 0f && !isFooter) || (state.indicatorOffset < 0f && isFooter)) {
if ((!isFooter && state.indicatorOffset > 0f) || (isFooter && state.indicatorOffset < 0f)) {
1f
} else {
0f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ internal fun ProgressRefreshIndicator(

val progressState = remember {
derivedStateOf {
if (isFooter) {
state.indicatorOffset.div(
state.loadMoreTrigger.coerceAtMost(-1f)
).coerceIn(0f, 1f)
} else {
state.indicatorOffset.div(
state.refreshTrigger.coerceAtLeast(1f)
).coerceIn(0f, 1f)
when {
!isFooter && state.indicatorOffset > 0f -> {
state.indicatorOffset.div(
state.refreshTrigger.coerceAtLeast(1f)
).coerceIn(0f, 1f)
}

isFooter && state.indicatorOffset < 0f -> {
state.indicatorOffset.div(
state.loadMoreTrigger.coerceAtMost(-1f)
).coerceIn(0f, 1f)
}

else -> 0f
}
}
}
Expand All @@ -67,7 +73,7 @@ internal fun ProgressRefreshIndicator(
Box(modifier = modifier) {
Box(
Modifier
.alpha(if (progressState.value == 0f) 0f else 1f)
.alpha(if (progressState.value > 0f) 1f else 0f)
.fillMaxWidth()
.height(height)
.drawWithCache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ fun UltraSwipeRefresh(
val updatedOnRefresh = rememberUpdatedState(onRefresh)
val updateOnLoadMore = rememberUpdatedState(onLoadMore)

Box(modifier.clipToBounds()) {
Box(modifier) {
RefreshSubComposeLayout(
refreshEnabled = refreshEnabled,
loadMoreEnabled = loadMoreEnabled,
headerIndicator = {
headerIndicator(state)
},
footerIndicator = {
footerIndicator(state)
},
refreshEnabled = refreshEnabled,
loadMoreEnabled = loadMoreEnabled,
) { headerHeight, footerHeight ->

val nestedScrollConnection = remember(state, coroutineScope) {
Expand Down Expand Up @@ -127,6 +127,11 @@ fun UltraSwipeRefresh(
state.isLoading -> state.animateOffsetTo(-footerHeight.toFloat())
state.headerState == UltraSwipeHeaderState.Refreshing || state.footerState == UltraSwipeFooterState.Loading -> {
state.isFinishing = true
if (state.indicatorOffset > headerHeight) {
state.animateOffsetTo(headerHeight.toFloat())
} else if (state.indicatorOffset < -footerHeight) {
state.animateOffsetTo(-footerHeight.toFloat())
}
delay(finishDelayMillis)
state.animateOffsetTo(0f)
}
Expand All @@ -152,13 +157,14 @@ fun UltraSwipeRefresh(
}
}

Box(modifier = Modifier.nestedScroll(nestedScrollConnection)) {
Box(modifier = Modifier.nestedScroll(nestedScrollConnection).clipToBounds()) {
Box(modifier = Modifier
.align(Alignment.TopCenter)
.graphicsLayer {
translationY = obtainHeaderOffset(state, headerScrollMode, headerHeight)
}
.zIndex(obtainZIndex(headerScrollMode))

) {
if (refreshEnabled) {
headerIndicator(state)
Expand Down Expand Up @@ -378,10 +384,8 @@ private fun rememberVibrator(): Vibrator {
@Suppress("DEPRECATION")
private fun Vibrator.vibrate() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.vibrate(
VibrationEffect.createOneShot(20, VibrationEffect.DEFAULT_AMPLITUDE)
)
vibrate(VibrationEffect.createOneShot(20, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
this.vibrate(20)
vibrate(20)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,23 @@ internal class UltraSwipeRefreshNestedScrollConnection(
}

override suspend fun onPreFling(available: Velocity): Velocity {
if (!(state.isRefreshing || state.isLoading || state.isFinishing)) {
when {
refreshEnabled && state.isExceededRefreshTrigger() -> onRefresh()
loadMoreEnabled && state.isExceededLoadMoreTrigger() -> onLoadMore()
state.indicatorOffset != 0f && !state.isSwipeInProgress -> state.animateOffsetTo(0f)
}
if (state.isRefreshing || state.isLoading || state.isFinishing) {
state.isSwipeInProgress = false
return available
}
when {
refreshEnabled && state.isExceededRefreshTrigger() -> onRefresh()
loadMoreEnabled && state.isExceededLoadMoreTrigger() -> onLoadMore()
state.indicatorOffset != 0f && !state.isSwipeInProgress -> state.animateOffsetTo(0f)
}

state.isSwipeInProgress = false
return super.onPreFling(available)
return Velocity.Zero
}

override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
if (state.isRefreshing || state.isLoading || state.isFinishing) {
return available
}
return Velocity.Zero
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ class UltraSwipeRefreshState(isRefreshing: Boolean, isLoading: Boolean) {
*/
internal suspend fun animateOffsetTo(offset: Float) {
mutatorMutex.mutate {
if(!isFinishing) {
updateHeaderState()
updateFooterState()
}
_indicatorOffset.animateTo(offset) {
if (indicatorOffset == 0f && isFinishing) {
isFinishing = false
updateHeaderState()
updateFooterState()
}
}
if(!isFinishing) {
updateHeaderState()
updateFooterState()
}
}
}

Expand Down
Loading

0 comments on commit 71a97b7

Please sign in to comment.