Skip to content

Commit

Permalink
Disabled async layout inflation because of scroll state handling bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakhimulin Damir committed Jan 28, 2021
1 parent 9fcc859 commit f40ca94
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
12 changes: 8 additions & 4 deletions rekukler/src/main/java/com/rerekt/rekukler/ViewBinder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -19,7 +20,9 @@ class ViewBinder<Type: Any, Binding: ViewBinding> (
) {

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) {}
}

Expand All @@ -29,9 +32,10 @@ class ViewBinder<Type: Any, Binding: ViewBinding> (
.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)
// }
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion sample/src/main/java/com/rerekt/sample/ui/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import com.rerekt.sample.R

open class AppActivity: AppCompatActivity() {

private val listFragment: ListFragment
get() = supportFragmentManager.fragments.filterIsInstance<ListFragment>().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) {
Expand Down
27 changes: 12 additions & 15 deletions sample/src/main/java/com/rerekt/sample/ui/ListFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f40ca94

Please sign in to comment.