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" applicationId = "fr.free.nrw.commons"
minSdk = 21 minSdk = 21
targetSdk = 35 targetSdk = 35
versionCode = 1058 versionCode = 1059
versionName = "6.0.2" versionName = "6.1.0"
setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName()) setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName())
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

View file

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

View file

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

View file

@ -166,35 +166,19 @@ fun applyEdgeToEdgeBottomInsets(view: View) = view.applyEdgeToEdgeInsets { inset
* and accounts for navigation bar insets to avoid double offsets. * and accounts for navigation bar insets to avoid double offsets.
*/ */
fun View.handleKeyboardInsets() { fun View.handleKeyboardInsets() {
var existingBottomMargin = 0 ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val existingBottomMargin = if (view.getTag(R.id.initial_margin_bottom) != null) {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
existingBottomMargin = if (view.getTag(R.id.initial_margin_bottom) != null) {
view.getTag(R.id.initial_margin_bottom) as Int view.getTag(R.id.initial_margin_bottom) as Int
} else { } else {
view.setTag(R.id.initial_margin_bottom, view.marginBottom) view.setTag(R.id.initial_margin_bottom, view.marginBottom)
view.marginBottom view.marginBottom
} }
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 lp = layoutParams as MarginLayoutParams
val navBarInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars()) val navBarInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime()) val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
val imeVisible = insets.isVisible(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 val imeBottomMargin = imeInsets.bottom - navBarInsets.bottom
lp.bottomMargin = if (imeVisible && imeBottomMargin >= existingBottomMargin) lp.bottomMargin = if (imeVisible && imeBottomMargin >= existingBottomMargin)
@ -202,11 +186,10 @@ fun View.handleKeyboardInsets() {
else existingBottomMargin else existingBottomMargin
layoutParams = lp layoutParams = lp
return WindowInsetsCompat.CONSUMED
WindowInsetsCompat.CONSUMED
} }
} }
)
}
/** /**
* Holds both initial margin values and system bar insets, providing summed values * Holds both initial margin values and system bar insets, providing summed values