Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 155c5d5

Browse files
committed
PArtially working
1 parent f41f73b commit 155c5d5

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

lib/web_ui/lib/src/engine/text_editing/text_editing.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
876876
_lastEditingState!.applyToDomElement(domElement);
877877
}
878878

879+
void setKeyboardInset(int bottomInset) {
880+
print('DART:UI SETTING KEYBOARD INSET IN DEFAULTTEXTEDITINGSTRATEGY');
881+
}
882+
879883
void placeElement() {
880884
domElement.focus();
881885
}
@@ -1321,6 +1325,10 @@ class TextEditingChannel {
13211325
cleanForms();
13221326
break;
13231327

1328+
case 'TextInput.setKeyboardInset':
1329+
implementation.setKeyboardInset(call.arguments);
1330+
break;
1331+
13241332
default:
13251333
throw StateError(
13261334
'Unsupported method call on the flutter/textinput channel: ${call.method}');
@@ -1510,6 +1518,11 @@ class HybridTextEditing {
15101518
}
15111519
}
15121520

1521+
/// Responds to the 'TextInput.setKeyboardInset' message.
1522+
void setKeyboardInset(int bottomInset) {
1523+
editingElement!.setKeyboardInset(bottomInset);
1524+
}
1525+
15131526
/// A CSS class name used to identify all elements used for text editing.
15141527
@visibleForTesting
15151528
static const String textEditingClass = 'flt-text-editing';

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) {
532532
viewportMetrics.viewInsetRight = 0;
533533
viewportMetrics.viewInsetBottom = finalInsets.bottom;
534534
viewportMetrics.viewInsetLeft = 0;
535+
Log.e("flutter", "JAVA INSETS: " + finalInsets.bottom);
535536
} else {
536537
// We zero the left and/or right sides to prevent the padding the
537538
// navigation bar would have caused.

shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,10 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
136136
break;
137137

138138
case "TextInput.setKeyboardInset":
139-
textInputMethodHandler.setKeyboardInset();
140139
try {
141140
final JSONObject arguments = (JSONObject) args;
142141
final int bottomInset = arguments.getInt("bottomInset");
143-
textInputMethodHandler.sendAppPrivateCommand(bottomInset);
142+
textInputMethodHandler.setKeyboardInset(bottomInset);
144143
result.success(null);
145144
} catch (JSONException exception) {
146145
result.error("error", exception.getMessage(), null);

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)