Skip to content

Commit d5ec12d

Browse files
committed
feat: implement state restoration and fix rotation snap in ExpressivePullToRefresh
- Added onSaveInstanceState/onRestoreInstanceState for persistent refresh state. - Improved updateIndicatorPosition to prevent immediate rotation snap when refreshing. - Cleaned up implementation comments. - Bumped version to v1.0.5.
1 parent 93c5115 commit d5ec12d

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Platform](https://img.shields.io/badge/platform-Android-blue.svg)](https://developer.android.com/)
44
[![API](https://img.shields.io/badge/API-26%2B-brightgreen.svg)](https://android-arsenal.com/api?level=26)
55
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
6-
[![JitPack](https://img.shields.io/badge/JitPack-1.0.4-green.svg)](https://jitpack.io/#Netsnake-TN/ExpressivepullToRefresh)
6+
[![JitPack](https://img.shields.io/badge/JitPack-1.0.5-green.svg)](https://jitpack.io/#Netsnake-TN/ExpressivepullToRefresh)
77

88
A Material Design 3 Expressive Pull-to-Refresh component for Android. Provides two distinct indicator styles with smooth animations, haptic feedback, and seamless integration for all scrollable views.
99

@@ -62,7 +62,7 @@ dependencyResolutionManagement {
6262

6363
```gradle
6464
dependencies {
65-
implementation 'com.github.Netsnake-TN:ExpressivepullToRefresh:v1.0.4'
65+
implementation 'com.github.Netsnake-TN:ExpressivepullToRefresh:v1.0.5'
6666
}
6767
```
6868

refresh/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
minSdk 26
1212
targetSdk 36
1313
versionCode 1
14-
versionName "1.0.4"
14+
versionName "1.0.5"
1515

1616
consumerProguardFiles 'consumer-rules.pro'
1717
}
@@ -51,7 +51,7 @@ afterEvaluate {
5151
release(MavenPublication) {
5252
groupId = 'com.github.Netsnake-TN'
5353
artifactId = 'ExpressivepullToRefresh'
54-
version = '1.0.4'
54+
version = '1.0.5'
5555
from components.release
5656
}
5757
}

refresh/src/main/java/com/expressive/refresh/ExpressivePullToRefresh.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,61 @@ private void setTargetOffsetTop(int offset) {
238238
invalidate();
239239
}
240240

241+
@Override
242+
protected android.os.Parcelable onSaveInstanceState() {
243+
android.os.Parcelable superState = super.onSaveInstanceState();
244+
SavedState ss = new SavedState(superState);
245+
ss.mRefreshing = mRefreshing;
246+
return ss;
247+
}
248+
249+
@Override
250+
protected void onRestoreInstanceState(android.os.Parcelable state) {
251+
if (!(state instanceof SavedState)) {
252+
super.onRestoreInstanceState(state);
253+
return;
254+
}
255+
SavedState ss = (SavedState) state;
256+
super.onRestoreInstanceState(ss.getSuperState());
257+
if (ss.mRefreshing) {
258+
post(() -> setRefreshing(true, false));
259+
}
260+
}
261+
262+
static class SavedState extends BaseSavedState {
263+
boolean mRefreshing;
264+
265+
SavedState(android.os.Parcelable superState) {
266+
super(superState);
267+
}
268+
269+
SavedState(android.os.Parcel android) {
270+
super(android);
271+
mRefreshing = android.readInt() == 1;
272+
}
273+
274+
@Override
275+
public void writeToParcel(android.os.Parcel out, int flags) {
276+
super.writeToParcel(out, flags);
277+
out.writeInt(mRefreshing ? 1 : 0);
278+
}
279+
280+
public static final android.os.Parcelable.Creator<SavedState> CREATOR = new android.os.Parcelable.Creator<SavedState>() {
281+
@Override
282+
public SavedState createFromParcel(android.os.Parcel in) {
283+
return new SavedState(in);
284+
}
285+
286+
@Override
287+
public SavedState[] newArray(int size) {
288+
return new SavedState[size];
289+
}
290+
};
291+
}
292+
241293
private void updateIndicatorPosition() {
242294
if (mLoadingIndicator != null) {
243295
float dragPercent = Math.min(1.5f, (float) mCurrentTargetOffsetTop / mTotalDragDistance);
244-
245296
float rawScale = Math.min(1f, dragPercent / 0.7f);
246297
float scale = mRefreshing ? 1f : (float) (Math.pow(rawScale, 2) * (3 - 2 * rawScale));
247298

@@ -253,10 +304,8 @@ private void updateIndicatorPosition() {
253304
mLoadingIndicator.setRotation(dragPercent * 360f);
254305
stopLoadingAnimation();
255306
} else {
256-
mLoadingIndicator.setRotation(0);
257307
startLoadingAnimation();
258308
}
259-
260309
layoutIndicator();
261310
}
262311
}

0 commit comments

Comments
 (0)