Disable hardware acceleration and keyboard animation (#6535)
Some checks are pending
Android CI / Run tests and generate APK (push) Waiting to run

* Disable hardware acceleration and keyboard animation

This is a temporary commit to see if it fixes issue #3364

* Remove unused import

* Bump up version code and modify version name

* Modify handleKeyboardInsets to handle insets correctly

* Refactor handleKeyboardInsets()

* Refactor handleKeyboardInsets()

* Fix inset in login activity
This commit is contained in:
Ritika Pahwa 2025-10-22 16:44:06 +05:30 committed by GitHub
parent 32ae406cca
commit 2d0255e5fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 36 deletions

View file

@ -24,8 +24,8 @@ android {
applicationId = "fr.free.nrw.commons"
minSdk = 21
targetSdk = 35
versionCode = 1058
versionName = "6.0.2"
versionCode = 1059
versionName = "6.1.0"
setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName())
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

View file

@ -84,6 +84,7 @@
android:parentActivityName=".customselector.ui.selector.CustomSelectorActivity" />
<activity
android:name=".auth.LoginActivity"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
@ -100,8 +101,9 @@
android:name=".upload.UploadActivity"
android:configChanges="orientation|screenSize|keyboard"
android:exported="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustPan">
<intent-filter android:label="@string/intent_share_upload_label">
<action android:name="android.intent.action.SEND" />

View file

@ -89,7 +89,7 @@ class LoginActivity : AccountAuthenticatorActivity() {
binding = ActivityLoginBinding.inflate(layoutInflater)
applyEdgeToEdgeAllInsets(binding!!.root)
binding?.aboutPrivacyPolicy?.handleKeyboardInsets()
binding!!.root.handleKeyboardInsets()
with(binding!!) {
setContentView(root)

View file

@ -166,46 +166,29 @@ 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) {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val existingBottomMargin = if (view.getTag(R.id.initial_margin_bottom) != null) {
view.getTag(R.id.initial_margin_bottom) as Int
} else {
view.setTag(R.id.initial_margin_bottom, view.marginBottom)
view.marginBottom
}
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())
val imeBottomMargin = imeInsets.bottom - navBarInsets.bottom
lp.bottomMargin = if (imeVisible && imeBottomMargin >= existingBottomMargin)
imeBottomMargin + existingBottomMargin
else existingBottomMargin
layoutParams = lp
WindowInsetsCompat.CONSUMED
}
// 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)
imeBottomMargin + existingBottomMargin
else existingBottomMargin
layoutParams = lp
return WindowInsetsCompat.CONSUMED
}
}
)
}
/**