mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fire PlatformViewController FlutterView callbacks (flutter/engine#13015)
Fixes a bug where `PlatformViewController` was not being notified of `FlutterView` attachment changes.
This commit is contained in:
parent
729a871326
commit
4b9fc4c1a5
@ -417,6 +417,7 @@ action("robolectric_tests") {
|
||||
"test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java",
|
||||
"test/io/flutter/embedding/android/FlutterActivityTest.java",
|
||||
"test/io/flutter/embedding/android/FlutterFragmentTest.java",
|
||||
"test/io/flutter/embedding/android/FlutterViewTest.java",
|
||||
"test/io/flutter/embedding/engine/FlutterEngineCacheTest.java",
|
||||
"test/io/flutter/embedding/engine/FlutterJNITest.java",
|
||||
"test/io/flutter/embedding/engine/RenderingComponentTest.java",
|
||||
|
||||
@ -633,6 +633,8 @@ public class FlutterView extends FrameLayout {
|
||||
sendLocalesToFlutter(getResources().getConfiguration());
|
||||
sendViewportMetricsToFlutter();
|
||||
|
||||
flutterEngine.getPlatformViewsController().attachToView(this);
|
||||
|
||||
// Notify engine attachment listeners of the attachment.
|
||||
for (FlutterEngineAttachmentListener listener : flutterEngineAttachmentListeners) {
|
||||
listener.onFlutterEngineAttachedToFlutterView(flutterEngine);
|
||||
@ -668,6 +670,8 @@ public class FlutterView extends FrameLayout {
|
||||
listener.onFlutterEngineDetachedFromFlutterView();
|
||||
}
|
||||
|
||||
flutterEngine.getPlatformViewsController().detachFromView();
|
||||
|
||||
// Disconnect the FlutterEngine's PlatformViewsController from the AccessibilityBridge.
|
||||
flutterEngine.getPlatformViewsController().detachAccessibiltyBridge();
|
||||
|
||||
|
||||
@ -143,14 +143,19 @@ public class FlutterEngine implements LifecycleOwner {
|
||||
* and {@link FlutterLoader#ensureInitializationComplete(Context, String[])}.
|
||||
*/
|
||||
public FlutterEngine(@NonNull Context context) {
|
||||
this(context, FlutterLoader.getInstance());
|
||||
this(context, FlutterLoader.getInstance(), new FlutterJNI());
|
||||
}
|
||||
|
||||
/* package */ FlutterEngine(@NonNull Context context, @NonNull FlutterLoader flutterLoader) {
|
||||
/**
|
||||
* Constructs a new {@code FlutterEngine}. See {@link #FlutterEngine(Context)}.
|
||||
*
|
||||
* {@code flutterJNI} should be a new instance that has never been attached to an engine before.
|
||||
*/
|
||||
public FlutterEngine(@NonNull Context context, @NonNull FlutterLoader flutterLoader, @NonNull FlutterJNI flutterJNI) {
|
||||
this.flutterJNI = flutterJNI;
|
||||
flutterLoader.startInitialization(context);
|
||||
flutterLoader.ensureInitializationComplete(context, null);
|
||||
|
||||
this.flutterJNI = new FlutterJNI();
|
||||
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
|
||||
attachToJni();
|
||||
|
||||
|
||||
@ -121,7 +121,7 @@ public class FlutterJNI {
|
||||
|
||||
// TODO(mattcarroll): add javadocs
|
||||
@UiThread
|
||||
public static native boolean nativeGetIsSoftwareRenderingEnabled();
|
||||
public native boolean nativeGetIsSoftwareRenderingEnabled();
|
||||
|
||||
@Nullable
|
||||
// TODO(mattcarroll): add javadocs
|
||||
|
||||
@ -281,7 +281,7 @@ public class FlutterRenderer implements TextureRegistry {
|
||||
|
||||
// TODO(mattcarroll): describe the native behavior that this invokes
|
||||
public boolean isSoftwareRenderingEnabled() {
|
||||
return FlutterJNI.nativeGetIsSoftwareRenderingEnabled();
|
||||
return flutterJNI.nativeGetIsSoftwareRenderingEnabled();
|
||||
}
|
||||
|
||||
// TODO(mattcarroll): describe the native behavior that this invokes
|
||||
|
||||
@ -38,7 +38,6 @@ import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -162,7 +161,7 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
|
||||
|
||||
dartExecutor = mNativeView.getDartExecutor();
|
||||
flutterRenderer = new FlutterRenderer(mNativeView.getFlutterJNI());
|
||||
mIsSoftwareRenderingEnabled = FlutterJNI.nativeGetIsSoftwareRenderingEnabled();
|
||||
mIsSoftwareRenderingEnabled = mNativeView.getFlutterJNI().nativeGetIsSoftwareRenderingEnabled();
|
||||
mMetrics = new ViewportMetrics();
|
||||
mMetrics.devicePixelRatio = context.getResources().getDisplayMetrics().density;
|
||||
setFocusable(true);
|
||||
|
||||
@ -10,6 +10,7 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivityTest;
|
||||
import io.flutter.embedding.android.FlutterFragmentTest;
|
||||
import io.flutter.embedding.android.FlutterViewTest;
|
||||
import io.flutter.embedding.engine.FlutterEngineCacheTest;
|
||||
import io.flutter.embedding.engine.FlutterJNITest;
|
||||
import io.flutter.embedding.engine.RenderingComponentTest;
|
||||
@ -28,6 +29,7 @@ import io.flutter.util.PreconditionsTest;
|
||||
FlutterFragmentTest.class,
|
||||
FlutterJNITest.class,
|
||||
FlutterRendererTest.class,
|
||||
FlutterViewTest.class,
|
||||
PlatformChannelTest.class,
|
||||
PreconditionsTest.class,
|
||||
RenderingComponentTest.class,
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package io.flutter.embedding.android;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import io.flutter.embedding.engine.FlutterJNI;
|
||||
import io.flutter.embedding.engine.loader.FlutterLoader;
|
||||
import io.flutter.plugin.platform.PlatformViewsController;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import io.flutter.embedding.engine.FlutterEngine;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FlutterViewTest {
|
||||
@Mock FlutterJNI mockFlutterJni;
|
||||
@Mock FlutterLoader mockFlutterLoader;
|
||||
@Spy PlatformViewsController platformViewsController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mockFlutterJni.isAttached()).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attachToFlutterEngine_alertsPlatformViews() {
|
||||
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(RuntimeEnvironment.application, mockFlutterLoader, mockFlutterJni));
|
||||
when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);
|
||||
|
||||
flutterView.attachToFlutterEngine(flutterEngine);
|
||||
|
||||
verify(platformViewsController, times(1)).attachToView(flutterView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detachFromFlutterEngine_alertsPlatformViews() {
|
||||
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(RuntimeEnvironment.application, mockFlutterLoader, mockFlutterJni));
|
||||
when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);
|
||||
|
||||
flutterView.attachToFlutterEngine(flutterEngine);
|
||||
flutterView.detachFromFlutterEngine();
|
||||
|
||||
verify(platformViewsController, times(1)).detachFromView();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user