mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Disconnect the view's AndroidKeyProcessor when detaching from the engine (#21307)
This commit is contained in:
parent
6a6d6d7593
commit
11befe419e
@ -70,6 +70,15 @@ public class AndroidKeyProcessor {
|
||||
this.keyEventChannel.setEventResponseHandler(eventResponder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches the key processor from the Flutter engine.
|
||||
*
|
||||
* <p>The AndroidKeyProcessor instance should not be used after calling this.
|
||||
*/
|
||||
public void destroy() {
|
||||
keyEventChannel.setEventResponseHandler(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a key up event is received by the {@link FlutterView}.
|
||||
*
|
||||
|
||||
@ -992,6 +992,8 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
|
||||
textInputPlugin.getInputMethodManager().restartInput(this);
|
||||
textInputPlugin.destroy();
|
||||
|
||||
androidKeyProcessor.destroy();
|
||||
|
||||
if (mouseCursorPlugin != null) {
|
||||
mouseCursorPlugin.destroy();
|
||||
}
|
||||
|
||||
@ -2,7 +2,9 @@ package io.flutter.embedding.android;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.notNull;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@ -56,6 +58,22 @@ public class AndroidKeyProcessorTest {
|
||||
verify(fakeView, times(0)).dispatchKeyEvent(any(KeyEvent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyTest() {
|
||||
FlutterEngine flutterEngine = mockFlutterEngine();
|
||||
KeyEventChannel fakeKeyEventChannel = flutterEngine.getKeyEventChannel();
|
||||
View fakeView = mock(View.class);
|
||||
|
||||
AndroidKeyProcessor processor =
|
||||
new AndroidKeyProcessor(fakeView, fakeKeyEventChannel, mock(TextInputPlugin.class));
|
||||
|
||||
verify(fakeKeyEventChannel, times(1))
|
||||
.setEventResponseHandler(notNull(KeyEventChannel.EventResponseHandler.class));
|
||||
processor.destroy();
|
||||
verify(fakeKeyEventChannel, times(1))
|
||||
.setEventResponseHandler(isNull(KeyEventChannel.EventResponseHandler.class));
|
||||
}
|
||||
|
||||
public void synthesizesEventsWhenKeyDownNotHandled() {
|
||||
FlutterEngine flutterEngine = mockFlutterEngine();
|
||||
KeyEventChannel fakeKeyEventChannel = flutterEngine.getKeyEventChannel();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user