mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 04:39:04 +00:00
Use WindowInsetsListener to adjust chat layout
Remove old applyScrollContentWindowInsets helper and IME listeners Add ViewCompat.setOnApplyWindowInsetsListener on root view Translate chatBarView and recyclerView by IME height and pad for nav-bar insets Force initial inset dispatch with ViewCompat.requestApplyInsets()
This commit is contained in:
parent
f374acad5c
commit
7ca86538e3
1 changed files with 32 additions and 1 deletions
|
|
@ -8,6 +8,8 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.isGone
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
|
@ -140,7 +142,36 @@ open class ChatFragment : BaseFragment<FragmentChatBinding>() {
|
|||
}
|
||||
}
|
||||
}
|
||||
binding?.chatBarView?.let { applyScrollContentWindowInsets(it) }
|
||||
|
||||
binding?.root.apply {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this!!) { _, insets ->
|
||||
val ime = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
|
||||
val nav = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
|
||||
binding?.chatBarView?.translationY = -ime.toFloat()
|
||||
binding?.chatBarView?.setPadding(
|
||||
binding?.chatBarView!!.paddingLeft,
|
||||
binding?.chatBarView!!.paddingTop,
|
||||
binding?.chatBarView!!.paddingRight,
|
||||
nav
|
||||
)
|
||||
|
||||
|
||||
binding?.recyclerView?.translationY = -ime.toFloat()
|
||||
|
||||
|
||||
binding?.recyclerView?.setPadding(
|
||||
binding?.recyclerView!!.paddingLeft,
|
||||
binding?.recyclerView!!.paddingTop,
|
||||
binding?.recyclerView!!.paddingRight,
|
||||
ime + nav
|
||||
)
|
||||
|
||||
insets
|
||||
}
|
||||
ViewCompat.requestApplyInsets(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue