@@ -77,13 +77,13 @@ public TextInputPlugin(
7777 new TextInputChannel .TextInputMethodHandler () {
7878 @ Override
7979 public void show () {
80- controlTextInputWindowInsetsAnimation (150 );
80+ // controlTextInputWindowInsetsAnimation(150);
8181 showTextInput (mView );
8282 }
8383
8484 @ Override
8585 public void hide () {
86- controlTextInputWindowInsetsAnimation (100 );
86+ // controlTextInputWindowInsetsAnimation(100);
8787 hideTextInput (mView );
8888 }
8989
@@ -149,37 +149,51 @@ public void setKeyboardInset(int bottomInset) {
149149 }
150150
151151 private class CustomWindowInsetsAnimationControlListener implements WindowInsetsAnimationControlListener {
152- private Insets targetInsets ;
152+ private int offset ;
153+ int baseInset ;
153154
154155 CustomWindowInsetsAnimationControlListener () {
155- targetInsets = Insets .of (0 , 0 , 0 , 0 );
156+ // targetInsets = Insets.of(0, 0, 0, 0);
156157 }
157158
158- CustomWindowInsetsAnimationControlListener ( Insets insets ) {
159- targetInsets = insets ;
159+ void setOffset ( int offset ) {
160+ this . offset = offset ;
160161 }
161162
162- void setInsets (Insets insets ) {
163- targetInsets = insets ;
163+ void setBaseInset (int baseInset ) {
164+ this .baseInset = baseInset ;
165+ }
166+
167+ void computeBaseInset (View view ) {
168+ int mask = android .view .WindowInsets .Type .ime ();
169+ Insets finalInsets = view .getRootWindowInsets ().getInsets (mask );
170+ if (baseInset < finalInsets .bottom ) setBaseInset (finalInsets .bottom );
164171 }
165172
166173 public void onCancelled (WindowInsetsAnimationController controller ) {}
167174
168175 public void onFinished (WindowInsetsAnimationController controller ) {}
169176
170177 public void onReady (WindowInsetsAnimationController controller , int types ) {
171- controller .setInsetsAndAlpha (targetInsets , 1f , 1f );
178+ if (controller .isReady () && (controller .getTypes () & types ) > 0 ) {
179+ controller .setInsetsAndAlpha (Insets .of (0 , 0 , 0 , baseInset + offset ), 1f , 1f );
180+ }
181+ // controller.finish(true);
172182 }
173183 }
174184
175- private void controlTextInputWindowInsetsAnimation (int bottomInset ) {
176- Log .e ("flutter" , "IN THE WINDOW WindowInsetsAnimationController !!!!!!!!!: " + bottomInset );
177- Insets targetInsets = Insets .of (0 , 0 , 0 , bottomInset );
178- if (mInsetsListener == null ) {
179- mInsetsListener = new CustomWindowInsetsAnimationControlListener (targetInsets );
180- } else {
181- mInsetsListener .setInsets (targetInsets );
182- }
185+ private void controlTextInputWindowInsetsAnimation (int offset ) {
186+ Log .e ("flutter" , "IN THE WINDOW WindowInsetsAnimationController !!!!!!!!!: " + offset + " " + mInsetsListener .baseInset );
187+ // if (mInsetsListener == null) {
188+ // mInsetsListener = new CustomWindowInsetsAnimationControlListener();
189+ // mInsetsListener.setBaseInset(0);
190+ // mInsetsListener.setOffset(offset);
191+ // } else {
192+ // mInsetsListener.setOffset(offset);
193+ // }
194+ setupInsetsListener ();
195+ mInsetsListener .setOffset (offset );
196+ mInsetsListener .computeBaseInset (mView );
183197 mView .getWindowInsetsController ().controlWindowInsetsAnimation (
184198 android .view .WindowInsets .Type .ime (),
185199 -1 , // duration.
@@ -189,6 +203,12 @@ private void controlTextInputWindowInsetsAnimation(int bottomInset) {
189203 );
190204 }
191205
206+ private void setupInsetsListener () {
207+ if (mInsetsListener == null ) {
208+ mInsetsListener = new CustomWindowInsetsAnimationControlListener ();
209+ }
210+ }
211+
192212 @ NonNull
193213 public InputMethodManager getInputMethodManager () {
194214 return mImm ;
@@ -371,6 +391,8 @@ public void sendTextInputAppPrivateCommand(String action, Bundle data) {
371391 private void showTextInput (View view ) {
372392 view .requestFocus ();
373393 mImm .showSoftInput (view , 0 );
394+ setupInsetsListener ();
395+ mInsetsListener .computeBaseInset (mView );
374396 }
375397
376398 private void hideTextInput (View view ) {
@@ -382,6 +404,8 @@ private void hideTextInput(View view) {
382404 // field(by text field here I mean anything that keeps the keyboard open).
383405 // See: https://github.com/flutter/flutter/issues/34169
384406 mImm .hideSoftInputFromWindow (view .getApplicationWindowToken (), 0 );
407+ setupInsetsListener ();
408+ mInsetsListener .computeBaseInset (mView );
385409 }
386410
387411 private void notifyViewEntered () {
0 commit comments