Fix scroll to bottom button always visible if last item is taller than RecyclerView

This commit is contained in:
Andrew 2023-05-11 19:48:10 +09:30 committed by GitHub
commit 57476cd56e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -211,10 +211,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
var searchViewItem: MenuItem? = null
private val isScrolledToBottom: Boolean
get() {
val position = layoutManager?.findFirstCompletelyVisibleItemPosition() ?: 0
return position == 0
}
get() = binding?.conversationRecyclerView?.isScrolledToBottom ?: true
private val layoutManager: LinearLayoutManager?
get() { return binding?.conversationRecyclerView?.layoutManager as LinearLayoutManager? }

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.recyclerview.widget.RecyclerView
@ColorInt
fun Context.getColorFromAttr(
@ -13,4 +14,10 @@ fun Context.getColorFromAttr(
): Int {
theme.resolveAttribute(attrColor, typedValue, resolveRefs)
return typedValue.data
}
}
val RecyclerView.isScrolledToBottom: Boolean
get() {
val contentHeight = height - (paddingTop + paddingBottom)
return computeVerticalScrollRange() == computeVerticalScrollOffset() + contentHeight
}