Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfc72a9d authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix IME not showing when clicking input-field during predictive back

Bug: 339200746
Flag: android.view.inputmethod.predictive_back_ime STAGING
Test: atest FrameworksCoreTests:ImeBackAnimationControllerTest
Test: Manual, i.e. immediately refocus input-field after commiting predictive ime back gesture in apps that use jetpack compose
Change-Id: I675fddaf1d93b59a2fe025b43af942edcc3343fb
parent c78496f9
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -206,20 +206,11 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
            mInsetsController.setPredictiveBackImeHideAnimInProgress(true);
            notifyHideIme();
        }
        if (mStartRootScrollY != 0) {
            // RootView is panned, ensure that it is scrolled back to the intended scroll position
            if (triggerBack) {
                // requesting ime as invisible
                mInsetsController.setRequestedVisibleTypes(0, ime());
                // changes the animation state and notifies RootView of changed insets, which
                // causes it to reset its scrollY to 0f (animated)
                mInsetsController.onAnimationStateChanged(ime(), /*running*/ true);
            } else {
        if (mStartRootScrollY != 0 && !triggerBack) {
            // This causes RootView to update its scroll back to the panned position
            mInsetsController.getHost().notifyInsetsChanged();
        }
    }
    }

    private void notifyHideIme() {
        ImeTracker.Token statsToken = ImeTracker.forLogging().onStart(ImeTracker.TYPE_HIDE,
@@ -233,6 +224,12 @@ public class ImeBackAnimationController implements OnBackAnimationCallback {
        // the IME away
        mInsetsController.getHost().getInputMethodManager()
                .notifyImeHidden(mInsetsController.getHost().getWindowToken(), statsToken);

        // requesting IME as invisible during post-commit
        mInsetsController.setRequestedVisibleTypes(0, ime());
        // Changes the animation state. This also notifies RootView of changed insets, which causes
        // it to reset its scrollY to 0f (animated) if it was panned
        mInsetsController.onAnimationStateChanged(ime(), /*running*/ true);
    }

    private void reset() {
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static org.testng.Assert.assertEquals;
import android.content.Context;
import android.graphics.Insets;
import android.platform.test.annotations.Presubmit;
import android.util.SparseArray;
import android.view.animation.BackGestureInterpolator;
import android.view.animation.Interpolator;
import android.view.inputmethod.InputMethodManager;
@@ -54,6 +55,8 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.lang.reflect.Field;

/**
 * Tests for {@link ImeBackAnimationController}.
 *
@@ -104,6 +107,13 @@ public class ImeBackAnimationControllerTest {
            when(mInsetsController.getHost()).thenReturn(mViewRootInsetsControllerHost);
            when(mViewRootInsetsControllerHost.getInputMethodManager()).thenReturn(
                    inputMethodManager);
            try {
                Field field = InsetsController.class.getDeclaredField("mSourceConsumers");
                field.setAccessible(true);
                field.set(mInsetsController, new SparseArray<InsetsSourceConsumer>());
            } catch (NoSuchFieldException | IllegalAccessException e) {
                throw new RuntimeException("Unable to set mSourceConsumers", e);
            }
        });
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    }