Skip to content

Commit 9f37cd1

Browse files
author
yangyufei
committed
1.add time recover,2.fix half window translate bug
1 parent c506f52 commit 9f37cd1

4 files changed

Lines changed: 67 additions & 13 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828

2929
implementation 'com.android.support:recyclerview-v7:28.0.0'
3030

31-
// api project(':library')
31+
api project(':library')
3232
// implementation 'com.github.JarvisGG:NestedTouchScrollingLayout:v1.0.0'
33-
implementation 'com.jarvis.library.NestedTouchScrollingLayout:library:1.0.0'
33+
// implementation 'com.jarvis.library.NestedTouchScrollingLayout:library:1.0.0'
3434
}

app/src/main/java/jarvis/com/nestedtouchscrollinglayout/fragment/RecyclerViewFragment.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import android.view.ViewGroup;
1616
import android.widget.TextView;
1717

18+
import jarvis.com.library.NestedTouchScrollingLayout;
1819
import jarvis.com.nestedtouchscrollinglayout.R;
1920

2021
/**
@@ -29,6 +30,8 @@ public class RecyclerViewFragment extends BaseChildFragment {
2930

3031
private RecyclerView mContainerRecycler;
3132

33+
private NestedTouchScrollingLayout mNestedTouchScrollingLayout;
34+
3235
private Bundle arg;
3336

3437

@@ -44,13 +47,31 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
4447
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
4548
View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
4649
mContainerRecycler = view.findViewById(R.id.container_rv);
50+
mNestedTouchScrollingLayout = view.findViewById(R.id.fragment_wrapper);
4751
return view;
4852
}
4953

5054
@Override
5155
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
5256
super.onViewCreated(view, savedInstanceState);
5357

58+
mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
59+
@Override
60+
public void onNestChildScrollChange(float deltaY) {
61+
62+
}
63+
64+
@Override
65+
public void onNestChildScrollRelease(float deltaY, int velocityY) {
66+
mNestedTouchScrollingLayout.recover(0, null, 300);
67+
}
68+
69+
@Override
70+
public void onNestChildHorizationScroll(boolean show) {
71+
72+
}
73+
});
74+
5475
mContainerRecycler.setLayoutManager(new LinearLayoutManager(RecyclerViewFragment.this.getContext(), LinearLayoutManager.VERTICAL, false));
5576
mContainerRecycler.setAdapter(new InnerAdapter(RecyclerViewFragment.this.getContext(), 0x9966CC));
5677

app/src/main/java/jarvis/com/nestedtouchscrollinglayout/fragment/WebViewFragment.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class WebViewFragment extends BaseChildFragment {
3232

3333
private WebView mWebView;
3434

35+
private NestedTouchScrollingLayout mNestedTouchScrollingLayout;
36+
3537
@Override
3638
public void onCreate(@Nullable Bundle savedInstanceState) {
3739
super.onCreate(savedInstanceState);
@@ -43,13 +45,31 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
4345
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
4446
View view = inflater.inflate(R.layout.fragment_webview, container, false);
4547
mWebView = view.findViewById(R.id.web_view);
48+
mNestedTouchScrollingLayout = view.findViewById(R.id.fragment_wrapper);
4649
return view;
4750
}
4851

4952
@Override
5053
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
5154
super.onViewCreated(view, savedInstanceState);
5255

56+
mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
57+
@Override
58+
public void onNestChildScrollChange(float deltaY) {
59+
60+
}
61+
62+
@Override
63+
public void onNestChildScrollRelease(float deltaY, int velocityY) {
64+
mNestedTouchScrollingLayout.recover(0);
65+
}
66+
67+
@Override
68+
public void onNestChildHorizationScroll(boolean show) {
69+
70+
}
71+
});
72+
5373
initWebSettings();
5474
initWebViewClient();
5575

library/src/main/java/jarvis/com/library/NestedTouchScrollingLayout.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public class NestedTouchScrollingLayout extends FrameLayout implements NestedScr
7373
*/
7474
private boolean isLeftorRightTouchLimit = true;
7575

76+
private boolean isFingerHolderTouch = false;
77+
7678
private List<INestChildScrollChange> mNestChildScrollChangeCallbacks;
7779

7880

@@ -200,12 +202,15 @@ public boolean onTouchEvent(MotionEvent event) {
200202
mDownSheetTranslation = mSheetTranslation;
201203
velocityTracker.clear();
202204

205+
isFingerHolderTouch = true;
206+
203207
if (mChildView instanceof WebView) {
204208
mWebViewContentHeight = (int) (((WebView)mChildView).getContentHeight() * ((WebView)mChildView).getScale());
205209
}
206210
}
207211

208212
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
213+
isFingerHolderTouch = false;
209214
isLeftorRightTouchLimit = true;
210215
}
211216

@@ -293,7 +298,8 @@ private boolean isChildCanScroll(MotionEvent event, float deltaY) {
293298
return (fingerDown && canScrollUp) || (fingerUp && canScrollDown);
294299
}
295300

296-
private boolean canScrollUp(View view, float x, float y) {
301+
protected boolean canScrollUp(View view, float x, float y) {
302+
297303
if (view instanceof WebView) {
298304
return canWebViewScrollUp();
299305
}
@@ -314,7 +320,7 @@ private boolean canScrollUp(View view, float x, float y) {
314320
return view.canScrollVertically(-1);
315321
}
316322

317-
private boolean canScrollDown(View view, float x, float y) {
323+
protected boolean canScrollDown(View view, float x, float y) {
318324
if (view instanceof WebView) {
319325
return canWebViewScrollDown();
320326
}
@@ -414,6 +420,10 @@ public void setTranslation(float transY) {
414420
if (mChildView != null) {
415421
mChildView.setTranslationY(transY);
416422
}
423+
if (transY == 0) {
424+
mDownSheetTranslation = getMeasuredHeight();
425+
mOriginTranslate = 0;
426+
}
417427
}
418428

419429
/**
@@ -425,8 +435,12 @@ public void recover(int target) {
425435
}
426436

427437
public void recover(int target, final Runnable runnable) {
438+
recover(target, runnable, 300);
439+
}
440+
441+
public void recover(int target, final Runnable runnable, int time) {
428442
currentAnimator = ObjectAnimator.ofFloat(this, SHEET_TRANSLATION, target);
429-
currentAnimator.setDuration(300);
443+
currentAnimator.setDuration(time);
430444
currentAnimator.setInterpolator(new DecelerateInterpolator(1.6f));
431445
currentAnimator.addListener(new CancelDetectionAnimationListener() {
432446
@Override
@@ -483,13 +497,6 @@ private void onActionRelease(MotionEvent event) {
483497
mTransYAnim.setDuration(200L);
484498
mTransYAnim.setInterpolator(PathInterpolatorCompat.create(0.4F, 0.0F, 0.2F, 1.0F));
485499

486-
mTransYAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
487-
@Override
488-
public void onAnimationUpdate(ValueAnimator valueAnimator) {
489-
490-
}
491-
});
492-
493500
mTransYAnim.start();
494501
}
495502

@@ -578,5 +585,11 @@ public int getNestedScrollAxes() {
578585
return super.getNestedScrollAxes();
579586
}
580587

581-
}
588+
public boolean isFingerHolderTouch() {
589+
return isFingerHolderTouch;
590+
}
582591

592+
public float getMinFlingVelocity() {
593+
return minFlingVelocity;
594+
}
595+
}

0 commit comments

Comments
 (0)