Prevent crash that happened once
This commit is contained in:
parent
44a61a2be2
commit
2ed6fa3246
2 changed files with 13 additions and 5 deletions
|
@ -42,6 +42,10 @@ abstract class GenericFragment<T : ViewDataBinding> : Fragment() {
|
||||||
protected val binding get() = _binding!!
|
protected val binding get() = _binding!!
|
||||||
protected var useMaterialSharedAxisXForwardAnimation = true
|
protected var useMaterialSharedAxisXForwardAnimation = true
|
||||||
|
|
||||||
|
protected fun isBindingAvailable(): Boolean {
|
||||||
|
return _binding != null
|
||||||
|
}
|
||||||
|
|
||||||
protected val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
protected val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||||
override fun handleOnBackPressed() {
|
override fun handleOnBackPressed() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
|
|
@ -212,11 +212,15 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
.addOnGlobalLayoutListener(
|
.addOnGlobalLayoutListener(
|
||||||
object : OnGlobalLayoutListener {
|
object : OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
|
if (isBindingAvailable()) {
|
||||||
binding.chatMessagesList
|
binding.chatMessagesList
|
||||||
.viewTreeObserver
|
.viewTreeObserver
|
||||||
.removeOnGlobalLayoutListener(this)
|
.removeOnGlobalLayoutListener(this)
|
||||||
Log.i("[Chat Room] Messages have been displayed, scrolling to first unread message if any")
|
Log.i("[Chat Room] Messages have been displayed, scrolling to first unread message if any")
|
||||||
scrollToFirstUnreadMessageOrBottom(false)
|
scrollToFirstUnreadMessageOrBottom(false)
|
||||||
|
} else {
|
||||||
|
Log.e("[Chat Room] Binding not available in onGlobalLayout callback!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue