Skip to content

Commit b39efb7

Browse files
committed
修复安卓在SpringScrollView正在做减速动画的时候,点击无法立即获得焦点的问题。
1 parent fc8c5df commit b39efb7

6 files changed

Lines changed: 25 additions & 16 deletions

File tree

android/app/app.iml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
9898
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
9999
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
100+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
100101
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_app_manifest" />
101102
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_app_info_output_file" />
102103
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_main_apk_resources" />
@@ -125,7 +126,7 @@
125126
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
126127
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
127128
</content>
128-
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
129+
<orderEntry type="jdk" jdkName="Android API 26 Platform (1)" jdkType="Android SDK" />
129130
<orderEntry type="sourceFolder" forTests="false" />
130131
<orderEntry type="library" name="Gradle: org.webkit:android-jsc:r174650@aar" level="project" />
131132
<orderEntry type="library" name="Gradle: com.android.support:support-vector-drawable:27.1.1@aar" level="project" />

android/app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ android {
140140
}
141141

142142
dependencies {
143-
compile project(':lottie-react-native')
144-
compile project(':react-native-spring-scroll-view')
145-
compile fileTree(dir: "libs", include: ["*.jar"])
146-
compile "com.android.support:appcompat-v7:26.0.0"
147-
compile "com.facebook.react:react-native:+" // From node_modules
143+
api project(':lottie-react-native')
144+
api project(':react-native-spring-scroll-view')
145+
api fileTree(dir: "libs", include: ["*.jar"])
146+
api "com.android.support:appcompat-v7:26.0.0"
147+
api "com.facebook.react:react-native:+" // From node_modules
148148
}
149149

150150
// Run this once to be able to run the application with BUCK

src/SpringScrollView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
277277
this._indicatorAnimation && this._indicatorAnimation.stop();
278278
this._indicatorAnimation = Animated.timing(this._indicatorOpacity, {
279279
toValue: 0,
280-
delay: 1000,
281-
duration: 1000,
280+
delay: 500,
281+
duration: 500,
282282
useNativeDriver: true
283283
});
284284
this._indicatorAnimation.start(({ finished }) => {

src/android/react-native-spring-scroll-view.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
122122
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
123123
</content>
124-
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
124+
<orderEntry type="jdk" jdkName="Android API 26 Platform (1)" jdkType="Android SDK" />
125125
<orderEntry type="sourceFolder" forTests="false" />
126126
<orderEntry type="library" name="Gradle: com.facebook.soloader:soloader:0.1.0@aar" level="project" />
127127
<orderEntry type="library" name="Gradle: org.webkit:android-jsc:r174650@aar" level="project" />

src/android/src/main/java/com/bolan9999/DecelerateAnimation.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
abstract class DecelerateAnimation {
99
protected ValueAnimator animator;
10+
public boolean animating;
1011

1112
public DecelerateAnimation(float base, float v, float dampingCoefficient) {
1213
int duration = 0;
@@ -33,13 +34,15 @@ public void onAnimationUpdate(ValueAnimator animator) {
3334
onUpdate((float) animator.getAnimatedValue());
3435
}
3536
});
37+
this.animating = true;
3638
animator.addListener(new Animator.AnimatorListener() {
3739
@Override
3840
public void onAnimationStart(Animator animation) {
3941
}
4042

4143
@Override
4244
public void onAnimationEnd(Animator animation) {
45+
DecelerateAnimation.this.animating = false;
4346
onEnd();
4447
}
4548

@@ -54,8 +57,10 @@ public void onAnimationRepeat(Animator animation) {
5457
animator.start();
5558
}
5659

57-
public void cancel() {
60+
public boolean cancel() {
61+
boolean cancel=this.animating;
5862
animator.cancel();
63+
return cancel;
5964
}
6065

6166
protected abstract void onEnd();

src/android/src/main/java/com/bolan9999/SpringScrollView.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44
import android.os.Build;
55
import android.support.annotation.NonNull;
6-
import android.telephony.TelephonyManager;
76
import android.view.MotionEvent;
87
import android.view.VelocityTracker;
98
import android.view.ViewGroup;
@@ -127,7 +126,9 @@ public boolean onTouch(View view, MotionEvent evt) {
127126
private void onDown(MotionEvent evt) {
128127
beginPoint.x = lastPoint.x = evt.getX();
129128
beginPoint.y = lastPoint.y = evt.getY();
130-
cancelAllAnimations();
129+
if (cancelAllAnimations()) {
130+
this.dragging = true;
131+
}
131132
if (momentumScrolling) {
132133
momentumScrolling = false;
133134
sendEvent("onMomentumScrollEnd", null);
@@ -150,7 +151,7 @@ private void onUp(MotionEvent evt) {
150151
tracker.computeCurrentVelocity(1);
151152
float vy = tracker.getYVelocity();
152153
float vx = tracker.getXVelocity();
153-
if (inverted && Build.VERSION.SDK_INT>=28) {
154+
if (inverted && Build.VERSION.SDK_INT >= 28) {
154155
vx = -vx;
155156
vy = -vy;
156157
}
@@ -371,15 +372,17 @@ protected void onUpdate(float value) {
371372
verticalAnimation.start();
372373
}
373374

374-
private void cancelAllAnimations() {
375+
private boolean cancelAllAnimations() {
376+
boolean cancel = false;
375377
if (verticalAnimation != null) {
376-
verticalAnimation.cancel();
378+
cancel = verticalAnimation.cancel();
377379
verticalAnimation = null;
378380
}
379381
if (horizontalAnimation != null) {
380-
horizontalAnimation.cancel();
382+
cancel = horizontalAnimation.cancel();
381383
horizontalAnimation = null;
382384
}
385+
return cancel;
383386
}
384387

385388

0 commit comments

Comments
 (0)