Skip to content

Commit

Permalink
BugFix
Browse files Browse the repository at this point in the history
  • Loading branch information
lang-v committed Sep 10, 2020
1 parent bd4de2c commit 620db48
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.core.view.NestedScrollingParent2
import androidx.core.view.ViewCompat
import androidx.core.widget.NestedScrollView
import java.util.concurrent.locks.ReentrantLock
import javax.security.auth.login.LoginException
import kotlin.math.abs
Expand Down Expand Up @@ -111,22 +112,26 @@ class ElasticView @JvmOverloads constructor(
// //target.invalidate()
// return
// }
val scrollOffset = getScrollOffset()
// 判断是否滑动到边界,滑动到边界的情况交给parent处理
if (canScroll(target, dx = dx, dy = dy)) {
if (type == ViewCompat.TYPE_TOUCH) {
if (!isMove) {
isMove = true
allowFling = false
Log.e(TAG,"禁止Fling")
}
} else if (type == ViewCompat.TYPE_NON_TOUCH) {
/**
* 这个判断很 重要
*/
if (!allowFling) return//fling被禁止
if (!allowFling) {
return
}//fling被禁止oo
isFling = true
if (abs(getScrollOffset()) >= 100 || abs(dx+dy)*dampingTemp < 5) {
if (abs(scrollOffset) >= 100 || abs(dx+dy)*dampingTemp < 5) {
allowFling = false//禁止fling
springBack(getScrollOffset(), animTimeLong)
springBack(scrollOffset, animTimeLong)
return
}
}
Expand All @@ -136,10 +141,8 @@ class ElasticView @JvmOverloads constructor(
scrollBy((dx * dampingTemp).toInt(), (dy * dampingTemp).toInt())
calcDamping()
} else {//此处有两种情况 一是未到边界的滑动,二是已经移动过布局,但是现在开始反向滑动了
Log.e(TAG,"else isMove=$isMove")
if (isMove) {
if (scrollOffset != 0) {
val temp = if (orientation == VERTICAL) dy * damping else dx * damping
val scrollOffset = getScrollOffset()
//防止越界,如果数据越界就设为边界值
val offset =
if (scrollOffset <= 0 && temp > -scrollOffset) -scrollOffset
Expand Down Expand Up @@ -169,15 +172,15 @@ class ElasticView @JvmOverloads constructor(
* 手指离开屏幕时是滑动由drag变成fling开始惯性滑动
*/
override fun onStopNestedScroll(target: View, type: Int) {
//这是最后一次调用此方法
if (isMove && isFling) {
//这是最后一次调用此方法
if (isFling) {
allowFling = true
isFling = false
return
}
if (!isMove) return
isMove = false
val scrollOffset = getScrollOffset()
if (!isMove ) return
isMove = false
if (headerAdapter != null && scrollOffset < 0 && scrollOffset <= -headerAdapter!!.offset) {
springBack(headerAdapter!!.offset + scrollOffset, animTimeShort)
if (isLoading()) return
Expand All @@ -204,7 +207,7 @@ class ElasticView @JvmOverloads constructor(
} else {
super.scrollBy(x, 0)
}
if (isLoading()) return
// if (isLoading()) return
val scrollOffset = getScrollOffset()
//更新控件header,footer状态
if (scrollOffset < 0) {
Expand Down Expand Up @@ -340,13 +343,15 @@ class ElasticView @JvmOverloads constructor(
private fun springBack(offset: Int, animTime: Long) {
//if (isLoading()) return
// lock.lock()
// val view:View? = null
animator = if (animator != null) {
animator!!.cancel()
val tmp =-
if (isLoading()) {
getScrollOffset() +
if (headerAdapter != null && headerAdapter!!.isDoing) headerAdapter!!.offset
else -footerAdapter!!.offset
else if (footerAdapter != null && footerAdapter!!.isDoing) -footerAdapter!!.offset
else -offset
}else
-offset
ValueAnimator.ofInt(0, tmp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import sl.view.elasticviewlibrary.R

class BaseFooter(private val context: Context, offset:Int):ElasticView.FooterAdapter(offset) {
private lateinit var view: View
private val icon by lazy { view.findViewById<ImageView>(R.id.footerImg) }
private val progressBar by lazy { view.findViewById<ProgressBar>(R.id.footerProgressBar) }
private val text by lazy { view.findViewById<TextView>(R.id.footerText) }
private val icon by lazy { view.findViewById<ImageView>(R.id.img) }
private val progressBar by lazy { view.findViewById<ProgressBar>(R.id.progressBar) }
private val text by lazy { view.findViewById<TextView>(R.id.text) }

//icon的方向
private val DIRECTION_DOWN = true
private val DIRECTION_UP = false
private var direction = DIRECTION_DOWN

override fun getContentView(viewGroup: ViewGroup): View {
view = LayoutInflater.from(context).inflate(R.layout.base_layout_footer, viewGroup, false)
view = LayoutInflater.from(context).inflate(R.layout.base_layout, viewGroup, false)
return view
}
override fun scrollProgress(progress: Int) {}
Expand Down
4 changes: 3 additions & 1 deletion elasticviewlibrary/src/main/res/layout/base_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@android:color/holo_red_dark"
android:orientation="horizontal">

<RelativeLayout
Expand All @@ -17,7 +18,8 @@
android:layout_height="30dp"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@drawable/ic_arrow_downward_gray_50dp" />
android:src="@drawable/ic_arrow_downward_gray_50dp"
android:contentDescription="loading" />

<ProgressBar
android:id="@+id/progressBar"
Expand Down
37 changes: 0 additions & 37 deletions elasticviewlibrary/src/main/res/layout/base_layout_footer.xml

This file was deleted.

0 comments on commit 620db48

Please sign in to comment.