From f40ca94459cecf83225ccf75e6abde82aef2a8e3 Mon Sep 17 00:00:00 2001 From: Rakhimulin Damir Date: Thu, 28 Jan 2021 15:12:46 +0300 Subject: [PATCH] Disabled async layout inflation because of scroll state handling bugs --- .../java/com/rerekt/rekukler/ViewBinder.kt | 12 ++++++--- .../java/com/rerekt/sample/ui/AppActivity.kt | 6 ++++- .../java/com/rerekt/sample/ui/ListFragment.kt | 27 +++++++++---------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/rekukler/src/main/java/com/rerekt/rekukler/ViewBinder.kt b/rekukler/src/main/java/com/rerekt/rekukler/ViewBinder.kt index 17f8b13..555c83f 100644 --- a/rekukler/src/main/java/com/rerekt/rekukler/ViewBinder.kt +++ b/rekukler/src/main/java/com/rerekt/rekukler/ViewBinder.kt @@ -2,6 +2,7 @@ package com.rerekt.rekukler import android.content.res.ColorStateList import android.graphics.drawable.Drawable +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.annotation.* @@ -19,7 +20,9 @@ class ViewBinder ( ) { fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { - val itemView = AsyncLayout(parent.context).apply { inflateAsync(layoutResId) } + // scroll state handling bug + // val itemView = AsyncLayout(parent.context).apply { inflateAsync(layoutResId) } + val itemView = LayoutInflater.from(parent.context).inflate(layoutResId, parent, false) return object : RecyclerView.ViewHolder(itemView) {} } @@ -29,9 +32,10 @@ class ViewBinder ( .apply { holderBinder(item as Type) itemPosition = position - (viewHolder.itemView as AsyncLayout).invokeWhenInflated { - bindingBlock.invoke(binder(getChildAt(0)), item) - } + bindingBlock.invoke(binder.invoke(viewHolder.itemView), item) +// (viewHolder.itemView as AsyncLayout).invokeWhenInflated { +// bindingBlock.invoke(binder(getChildAt(0)), item) +// } } } } diff --git a/sample/src/main/java/com/rerekt/sample/ui/AppActivity.kt b/sample/src/main/java/com/rerekt/sample/ui/AppActivity.kt index 1c50caa..f2fd3f3 100644 --- a/sample/src/main/java/com/rerekt/sample/ui/AppActivity.kt +++ b/sample/src/main/java/com/rerekt/sample/ui/AppActivity.kt @@ -7,10 +7,14 @@ import com.rerekt.sample.R open class AppActivity: AppCompatActivity() { + private val listFragment: ListFragment + get() = supportFragmentManager.fragments.filterIsInstance().firstOrNull() + ?: ListFragment() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - if (savedInstanceState == null) { goTo(ListFragment()) } + if (savedInstanceState == null) { goTo(listFragment) } } private fun goTo(fragment: Fragment) { diff --git a/sample/src/main/java/com/rerekt/sample/ui/ListFragment.kt b/sample/src/main/java/com/rerekt/sample/ui/ListFragment.kt index 3e35cb7..86762a1 100644 --- a/sample/src/main/java/com/rerekt/sample/ui/ListFragment.kt +++ b/sample/src/main/java/com/rerekt/sample/ui/ListFragment.kt @@ -33,23 +33,20 @@ class ListFragment: Fragment(R.layout.fragment_main) { postDelayedListUpdate() } - // Just like network async request @ExperimentalStdlibApi private fun postDelayedListUpdate() { - Handler(Looper.getMainLooper()).postDelayed({ - adapter.items = buildList { - addAll( - (0..10).map { - Article( - id = it, - title = "Title#$it", - description = "Description#$it" - ) - } - ) - add(Loading) - } - }, 500) + adapter.items = buildList { + addAll( + (0..10).map { + Article( + id = it, + title = "Title#$it", + description = "Description#$it" + ) + } + ) + add(Loading) + } } private fun initRecycler() {