mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Make FlutterFragment usable without requiring it to be attached to an Android Activity. (Attempt 2) (flutter/engine#27397)
This commit is contained in:
parent
9cceca7161
commit
a1fe1c8ca5
@ -276,15 +276,15 @@ import java.util.Arrays;
|
||||
if (host.getRenderMode() == RenderMode.surface) {
|
||||
FlutterSurfaceView flutterSurfaceView =
|
||||
new FlutterSurfaceView(
|
||||
host.getActivity(), host.getTransparencyMode() == TransparencyMode.transparent);
|
||||
host.getContext(), host.getTransparencyMode() == TransparencyMode.transparent);
|
||||
|
||||
// Allow our host to customize FlutterSurfaceView, if desired.
|
||||
host.onFlutterSurfaceViewCreated(flutterSurfaceView);
|
||||
|
||||
// Create the FlutterView that owns the FlutterSurfaceView.
|
||||
flutterView = new FlutterView(host.getActivity(), flutterSurfaceView);
|
||||
flutterView = new FlutterView(host.getContext(), flutterSurfaceView);
|
||||
} else {
|
||||
FlutterTextureView flutterTextureView = new FlutterTextureView(host.getActivity());
|
||||
FlutterTextureView flutterTextureView = new FlutterTextureView(host.getContext());
|
||||
|
||||
flutterTextureView.setOpaque(host.getTransparencyMode() == TransparencyMode.opaque);
|
||||
|
||||
@ -292,7 +292,7 @@ import java.util.Arrays;
|
||||
host.onFlutterTextureViewCreated(flutterTextureView);
|
||||
|
||||
// Create the FlutterView that owns the FlutterTextureView.
|
||||
flutterView = new FlutterView(host.getActivity(), flutterTextureView);
|
||||
flutterView = new FlutterView(host.getContext(), flutterTextureView);
|
||||
}
|
||||
|
||||
// Add listener to be notified when Flutter renders its first frame.
|
||||
|
||||
@ -378,6 +378,9 @@ public class FlutterActivityAndFragmentDelegateTest {
|
||||
// Declare that the host does NOT want Flutter to attach to the surrounding Activity.
|
||||
when(mockHost.shouldAttachEngineToActivity()).thenReturn(false);
|
||||
|
||||
// getActivity() returns null if the activity is not attached
|
||||
when(mockHost.getActivity()).thenReturn(null);
|
||||
|
||||
// Create the real object that we're testing.
|
||||
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
|
||||
|
||||
@ -385,14 +388,21 @@ public class FlutterActivityAndFragmentDelegateTest {
|
||||
// Flutter is attached to the surrounding Activity in onAttach.
|
||||
delegate.onAttach(RuntimeEnvironment.application);
|
||||
|
||||
// Verify that the ActivityControlSurface was NOT told to attach to an Activity.
|
||||
verify(mockFlutterEngine.getActivityControlSurface(), never())
|
||||
.attachToActivity(any(Activity.class), any(Lifecycle.class));
|
||||
// Make sure all of the other lifecycle methods can run safely as well
|
||||
// without a valid Activity
|
||||
delegate.onCreateView(null, null, null, 0);
|
||||
delegate.onStart();
|
||||
delegate.onResume();
|
||||
delegate.onPause();
|
||||
delegate.onStop();
|
||||
delegate.onDestroyView();
|
||||
|
||||
// Flutter is detached from the surrounding Activity in onDetach.
|
||||
delegate.onDetach();
|
||||
|
||||
// Verify that the ActivityControlSurface was NOT told to detach from the Activity.
|
||||
// Verify that the ActivityControlSurface was NOT told to attach or detach to an Activity.
|
||||
verify(mockFlutterEngine.getActivityControlSurface(), never())
|
||||
.attachToActivity(any(Activity.class), any(Lifecycle.class));
|
||||
verify(mockFlutterEngine.getActivityControlSurface(), never()).detachFromActivity();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user