mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Modify handleKeyboardInsets to handle insets correctly
This commit is contained in:
parent
8e6db87f6e
commit
ec9bb3f89b
5 changed files with 26 additions and 35 deletions
|
|
@ -89,6 +89,7 @@ class LoginActivity : AccountAuthenticatorActivity() {
|
|||
|
||||
binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||
applyEdgeToEdgeAllInsets(binding!!.root)
|
||||
binding?.aboutPrivacyPolicy?.handleKeyboardInsets()
|
||||
with(binding!!) {
|
||||
setContentView(root)
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
|||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = UploadCategoriesFragmentBinding.inflate(inflater, container, false)
|
||||
binding!!.llContainerButtons.handleKeyboardInsets()
|
||||
return binding!!.root
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ class DepictsFragment : UploadBaseFragment(), DepictsContract.View {
|
|||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = UploadDepictsFragmentBinding.inflate(inflater, container, false)
|
||||
_binding!!.navigationButtonsContainer.handleKeyboardInsets()
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
|
|||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentUploadMediaDetailFragmentBinding.inflate(inflater, container, false)
|
||||
_binding!!.mediaDetailCardView.handleKeyboardInsets()
|
||||
// intialise the adapter early to prevent uninitialized access
|
||||
uploadMediaDetailAdapter = UploadMediaDetailAdapter(
|
||||
this,
|
||||
|
|
|
|||
|
|
@ -166,35 +166,20 @@ fun applyEdgeToEdgeBottomInsets(view: View) = view.applyEdgeToEdgeInsets { inset
|
|||
* and accounts for navigation bar insets to avoid double offsets.
|
||||
*/
|
||||
fun View.handleKeyboardInsets() {
|
||||
var existingBottomMargin = 0
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
|
||||
existingBottomMargin = if (view.getTag(R.id.initial_margin_bottom) != null) {
|
||||
view.getTag(R.id.initial_margin_bottom) as Int
|
||||
val existingBottomMargin = if (getTag(R.id.initial_margin_bottom) != null) {
|
||||
getTag(R.id.initial_margin_bottom) as Int
|
||||
} else {
|
||||
view.setTag(R.id.initial_margin_bottom, view.marginBottom)
|
||||
view.marginBottom
|
||||
setTag(R.id.initial_margin_bottom, marginBottom)
|
||||
marginBottom
|
||||
}
|
||||
|
||||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
|
||||
|
||||
// Animate during IME transition
|
||||
ViewCompat.setWindowInsetsAnimationCallback(
|
||||
this,
|
||||
object : WindowInsetsAnimationCompat.Callback(
|
||||
DISPATCH_MODE_CONTINUE_ON_SUBTREE
|
||||
) {
|
||||
override fun onProgress(
|
||||
insets: WindowInsetsCompat,
|
||||
runningAnimations: MutableList<WindowInsetsAnimationCompat>
|
||||
): WindowInsetsCompat {
|
||||
val lp = layoutParams as MarginLayoutParams
|
||||
|
||||
val navBarInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
|
||||
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
|
||||
val imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
|
||||
|
||||
// Avoid extra space due to system nav bar when the keyboard is shown
|
||||
val imeBottomMargin = imeInsets.bottom - navBarInsets.bottom
|
||||
|
||||
lp.bottomMargin = if (imeVisible && imeBottomMargin >= existingBottomMargin)
|
||||
|
|
@ -202,10 +187,12 @@ fun View.handleKeyboardInsets() {
|
|||
else existingBottomMargin
|
||||
|
||||
layoutParams = lp
|
||||
return WindowInsetsCompat.CONSUMED
|
||||
|
||||
insets
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
ViewCompat.requestApplyInsets(this)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue