Attempt to fix view jitter when switching keyboards.

This commit is contained in:
Cody Henthorne 2023-01-25 10:01:30 -05:00 committed by Greyson Parrelli
parent b4a34599d7
commit aa2075c78f
5 changed files with 14 additions and 45 deletions

View file

@ -16,11 +16,9 @@
*/ */
package org.thoughtcrime.securesms.components; package org.thoughtcrime.securesms.components;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build; import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -107,10 +105,6 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
} }
private void updateKeyboardState() { private void updateKeyboardState() {
updateKeyboardState(Integer.MAX_VALUE);
}
private void updateKeyboardState(int previousHeight) {
if (viewInset == 0) viewInset = getViewInset(); if (viewInset == 0) viewInset = getViewInset();
getWindowVisibleDisplayFrame(rect); getWindowVisibleDisplayFrame(rect);
@ -130,11 +124,7 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
onKeyboardOpen(keyboardHeight); onKeyboardOpen(keyboardHeight);
} }
} else if (keyboardOpen) { } else if (keyboardOpen) {
if (previousHeight == keyboardHeight) { onKeyboardClose();
onKeyboardClose();
} else {
postDelayed(() -> updateKeyboardState(keyboardHeight), 100);
}
} }
} }
@ -159,7 +149,6 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
} }
} }
@TargetApi(VERSION_CODES.LOLLIPOP)
private int getViewInset() { private int getViewInset() {
try { try {
Field attachInfoField = View.class.getDeclaredField("mAttachInfo"); Field attachInfoField = View.class.getDeclaredField("mAttachInfo");

View file

@ -253,11 +253,7 @@ class AddMessageDialogFragment : KeyboardEntryDialogFragment(R.layout.v2_media_a
binding.hud.showSoftkey(binding.content.addAMessageInput) binding.hud.showSoftkey(binding.content.addAMessageInput)
} else { } else {
requestedEmojiDrawer = true requestedEmojiDrawer = true
binding.hud.hideSoftkey(binding.content.addAMessageInput) { binding.hud.show(binding.content.addAMessageInput, emojiDrawerStub.get())
binding.hud.post {
binding.hud.show(binding.content.addAMessageInput, emojiDrawerStub.get())
}
}
} }
} }

View file

@ -1,10 +1,8 @@
package org.thoughtcrime.securesms.stories.viewer.reply.composer package org.thoughtcrime.securesms.stories.viewer.reply.composer
import android.app.Dialog
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
@ -147,6 +145,10 @@ class StoryReplyComposer @JvmOverloads constructor(
emojiDrawer.onCloseEmojiSearch() emojiDrawer.onCloseEmojiSearch()
} }
fun close() {
inputAwareLayout.hideCurrentInput(input)
}
private fun onEmojiToggleClicked() { private fun onEmojiToggleClicked() {
if (!emojiDrawer.isInitialised) { if (!emojiDrawer.isInitialised) {
callback?.onInitializeEmojiDrawer(emojiDrawer) callback?.onInitializeEmojiDrawer(emojiDrawer)
@ -159,12 +161,8 @@ class StoryReplyComposer @JvmOverloads constructor(
callback?.onHideEmojiKeyboard() callback?.onHideEmojiKeyboard()
} else { } else {
isRequestingEmojiDrawer = true isRequestingEmojiDrawer = true
inputAwareLayout.hideSoftkey(input) { inputAwareLayout.show(input, emojiDrawer)
inputAwareLayout.post { emojiDrawer.post { callback?.onShowEmojiKeyboard() }
inputAwareLayout.show(input, emojiDrawer)
emojiDrawer.post { callback?.onShowEmojiKeyboard() }
}
}
} }
} }
@ -175,22 +173,4 @@ class StoryReplyComposer @JvmOverloads constructor(
fun onShowEmojiKeyboard() = Unit fun onShowEmojiKeyboard() = Unit
fun onHideEmojiKeyboard() = Unit fun onHideEmojiKeyboard() = Unit
} }
companion object {
fun installIntoBottomSheet(context: Context, dialog: Dialog): StoryReplyComposer {
val container: ViewGroup = dialog.findViewById(R.id.container)
val oldComposer: StoryReplyComposer? = container.findViewById(R.id.input)
if (oldComposer != null) {
return oldComposer
}
val composer = StoryReplyComposer(context)
composer.id = R.id.input
container.addView(composer)
return composer
}
}
} }

View file

@ -338,6 +338,10 @@ class StoryGroupReplyFragment :
override fun onPageSelected(child: StoryViewsAndRepliesPagerParent.Child) { override fun onPageSelected(child: StoryViewsAndRepliesPagerParent.Child) {
currentChild = child currentChild = child
updateNestedScrolling() updateNestedScrolling()
if (currentChild != StoryViewsAndRepliesPagerParent.Child.REPLIES) {
composer.close()
}
} }
private fun updateNestedScrolling() { private fun updateNestedScrolling() {

View file

@ -10,11 +10,11 @@
<TextView <TextView
android:id="@+id/empty_notice" android:id="@+id/empty_notice"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:text="@string/StoryGroupReplyFragment__no_replies_yet" android:text="@string/StoryGroupReplyFragment__no_replies_yet"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toTopOf="@+id/bottom_bar"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />