fix: back navigation from comment replies (#6954)

This commit is contained in:
Thomas W. 2025-01-15 13:44:17 +01:00 committed by GitHub
parent fc4055289e
commit aef23e26e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.ComponentDialog
import androidx.activity.addCallback
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
@ -20,6 +22,14 @@ class CommentsSheet : ExpandablePlayerSheet() {
private val commonPlayerViewModel: CommonPlayerViewModel by activityViewModels()
private val backPressedCallback by lazy(LazyThreadSafetyMode.NONE) {
(dialog as ComponentDialog?)?.onBackPressedDispatcher?.addCallback(owner = viewLifecycleOwner, enabled = false) {
if (childFragmentManager.backStackEntryCount > 0) {
childFragmentManager.popBackStack()
}
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -70,6 +80,7 @@ class CommentsSheet : ExpandablePlayerSheet() {
fun updateFragmentInfo(showBackButton: Boolean, title: String) {
binding.btnBack.isVisible = showBackButton
binding.commentsTitle.text = title
backPressedCallback?.isEnabled = showBackButton
}
companion object {