Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arbitrary stop calls on JS item animator #728

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/publish-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ echo "copying to $TARGET.."
rm -rf "$TARGET"
cp -r dist "$TARGET"

echo "copy complete."
echo "copy complete."
2 changes: 1 addition & 1 deletion src/core/ItemAnimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default interface ItemAnimator {
}

export class BaseItemAnimator implements ItemAnimator {
public static USE_NATIVE_DRIVER = true;
public static USE_NATIVE_DRIVER = false;
public animateWillMount(atX: number, atY: number, itemIndex: number): object | undefined {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,24 @@ export class DefaultJSItemAnimator extends BaseItemAnimator {
}

public animateWillUpdate(fromX: number, fromY: number, toX: number, toY: number, itemRef: object, itemIndex: number): void {
this._hasAnimatedOnce = true;
//no need
}

public animateShift(fromX: number, fromY: number, toX: number, toY: number, itemRef: object, itemIndex: number): boolean {
if (!this._isTimerOn) {
this._isTimerOn = true;
if (!this._hasAnimatedOnce) {
setTimeout(() => {
this._hasAnimatedOnce = true;
}, 700);
}
}
if (fromX !== toX || fromY !== toY) {
if (!this.shouldAnimateOnce || this.shouldAnimateOnce && !this._hasAnimatedOnce) {
const viewRef = itemRef as UnmountAwareView;
const animXY = new Animated.ValueXY({ x: fromX, y: fromY });
animXY.addListener((value) => {
if (viewRef._isUnmountedForRecyclerListView || (this.shouldAnimateOnce && this._hasAnimatedOnce)) {
if (viewRef._isUnmountedForRecyclerListView) {
animXY.stopAnimation();
return;
}
Expand All @@ -51,19 +59,9 @@ export class DefaultJSItemAnimator extends BaseItemAnimator {
useNativeDriver: BaseItemAnimator.USE_NATIVE_DRIVER,
}).start(() => {
viewRef._lastAnimVal = null;
this._hasAnimatedOnce = true;
});
return true;
}
} else {
if (!this._isTimerOn) {
this._isTimerOn = true;
if (!this._hasAnimatedOnce) {
setTimeout(() => {
this._hasAnimatedOnce = true;
}, 1000);
}
}
}
return false;
}
Expand Down