Skip to content

Commit

Permalink
not scroll to top when setdata
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenceDut committed Jul 8, 2019
1 parent d4085ec commit 8f678ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.silencedut.core.provider.legend.ILegendDateProvider
import com.silencedut.diffadapter.DiffAdapter
import com.silencedut.diffadapter.data.BaseMutableData
import com.silencedut.diffadapter.rvhelper.RvHelper
import com.silencedut.diffadapter.rvhelper.RvHelper.Companion
import com.silencedut.diffadapter.utils.DiffModelProvider
import com.silencedut.diffadapterdemo.adapter.LegendHolder
import com.silencedut.diffadapterdemo.adapter.LegendViewData
Expand Down Expand Up @@ -197,7 +198,7 @@ class LOLActivity : AppCompatActivity(){
return
}
mRVTest?.let {
RvHelper.scrollToBottom(it,(0 until diffAdapter.itemCount).random())
RvHelper.scrollTo(it, (0 until diffAdapter.itemCount).random())
}

val time = (300 until 500L).random()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,6 @@ public void setDatas(List<? extends BaseMutableData> datas) {

List<BaseMutableData> newList = new ArrayList<>(datas);
mDifferHelper.submitList(newList);
if(mAttachedRecyclerView!=null) {
mDiffHandler.postDelayed(new Runnable() {
@Override
public void run() {
RvHelper.Companion.scrollToBottom(mAttachedRecyclerView,0);
}
},1000);
}
}

public void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@ class RvHelper {
return recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange()
}

fun scrollToBottom(recyclerView: RecyclerView?,position:Int) {
@Deprecated("no use anymore",ReplaceWith("RvHelper.scrollTo(recyclerView,position)" ))
fun scrollToBottom(recyclerView: RecyclerView?, position: Int) {
recyclerView?.layoutManager?.let {
if(it is LinearLayoutManager) {
if (it is LinearLayoutManager) {
it.scrollToPositionWithOffset(position, 0)
}
}
}

fun scrollTo(recyclerView: RecyclerView?, position: Int, delayed: Long = 0) {

recyclerView?.postDelayed({
recyclerView.layoutManager?.let {
if (it is LinearLayoutManager) {
it.scrollToPositionWithOffset(position, 0)
}
}
},delayed)

}

/**
* 关闭默认局部刷新动画,对性能要求高的地方试用,比如一些公屏等刷新频繁的
*/
Expand All @@ -36,7 +49,7 @@ class RvHelper {
it.changeDuration = 0
it.moveDuration = 0
it.removeDuration = 0
if(it is SimpleItemAnimator) {
if (it is SimpleItemAnimator) {
it.supportsChangeAnimations = false
}
}
Expand Down

0 comments on commit 8f678ca

Please sign in to comment.