fix: stabilise description dialog shaking#20376
fix: stabilise description dialog shaking#20376HS0204 wants to merge 1 commit intoankidroid:mainfrom
Conversation
There was a problem hiding this comment.
Feel free to play with this and make it shorter. Code is untested.
How to apply a patch: https://github.com/ankidroid/Anki-Android/wiki/Development-Guide/#applying-a-patch
Index: AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EditDeckDescriptionDialog.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EditDeckDescriptionDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EditDeckDescriptionDialog.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EditDeckDescriptionDialog.kt (revision 3d9df21b057d59e111275a485de6ad6f1b1fc7f0)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EditDeckDescriptionDialog.kt (date 1772581113685)
@@ -26,6 +26,7 @@
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
+import androidx.core.widget.doAfterTextChanged
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
@@ -134,31 +135,13 @@
}
}
- binding.deckDescriptionInput.addTextChangedListener(
- object : TextWatcher {
- override fun beforeTextChanged(
- s: CharSequence?,
- start: Int,
- count: Int,
- after: Int,
- ) {}
-
- override fun onTextChanged(
- s: CharSequence?,
- start: Int,
- before: Int,
- count: Int,
- ) {}
-
- override fun afterTextChanged(s: Editable?) {
- // stabilise TextInputLayout by posting a deferred requestLayout()
- // after the current layout pass completes
- binding.deckDescriptionInput.post {
- (binding.deckDescriptionInput.parent as? View)?.requestLayout()
- }
- }
- },
- )
+ with (binding.deckDescriptionInput) {
+ doAfterTextChanged {
+ // stabilise TextInputLayout by posting a deferred requestLayout()
+ // after the current layout pass completes
+ (this.parent as? View)?.post { requestLayout() }
+ }
+ }
setupFlows()
}| ) {} | ||
|
|
||
| override fun afterTextChanged(s: Editable?) { | ||
| // stabilise TextInputLayout by posting a deferred requestLayout() |
There was a problem hiding this comment.
This mostly explains the 'what', could you have another pass at making this explain the 'why'. It doesn't need to be very verbose.
I feel the PR description is excellent, but the code/commit message doesn't explain it as well, and the code & commit message will last much longer than the PR
- TextInputLayout's layout recalculation causes view shaking on multiline input - Defer a final requestLayout() until after the current layout pass completes
3d9df21 to
f05c242
Compare
|
@david-allison I've changed the code and the comments. I've also tested it locally on a device and it worked. Thank you for the helpful advice on writing maintainable code! Please let me know if I've tweaked the comments too simply. |
Purpose / Description
When multiple lines are entered in edit deck description dialog, the dialog shakes.
This was caused by a conflict between the calculation performed by
TextInputLayoutand the changes to the height ofTextInputEditText.This PR stabilises the description dialog by resolving the conflicting frame calculations.
Fixes
Approach
dialog_deck_description.xml,NestedScrollView-TextInputLayout-TextInputEditText.TextInputLayout, it was stable without shaking and I identified that main cause was from it.TextInputLayouttriggered multiplerequestLayout()calls within the same frame asTextInputEditTextheight changes.requestLayout()to the end of the message queue viapost {}, ensuring it runs afterTextInputLayout's internal layout pass completes.How Has This Been Tested?
Manually tested on a device. Compared the behaviour before and after the fix.
WhatsApp.Video.2026-03-02.at.19.20.03.mp4
WhatsApp.Video.2026-03-02.at.19.20.02.mp4
Learning (optional, can help others)
N/A
Checklist
Please, go through these checks before submitting the PR.