Export |ExclusiveAppComponent<Activity>| from FlutterActivity/FlutterFragment class (flutter/engine#30864)
This commit is contained in:
@@ -450,6 +450,15 @@ public class FlutterActivity extends Activity
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Android App Component exclusively attached to {@link
|
||||
* io.flutter.embedding.engine.FlutterEngine}.
|
||||
*/
|
||||
@Override
|
||||
public ExclusiveAppComponent<Activity> getExclusiveAppComponent() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
switchLaunchThemeForNormalTheme();
|
||||
|
||||
@@ -953,6 +953,20 @@ import java.util.Arrays;
|
||||
@NonNull
|
||||
TransparencyMode getTransparencyMode();
|
||||
|
||||
/**
|
||||
* Returns the {@link ExclusiveAppComponent<Activity>} that is associated with {@link
|
||||
* io.flutter.embedding.engine.FlutterEngine}.
|
||||
*
|
||||
* <p>In the scenario where multiple {@link FlutterActivity} or {@link FlutterFragment} share
|
||||
* the same {@link FlutterEngine}, to attach/re-attache a {@link FlutterActivity} or {@link
|
||||
* FlutterFragment} to the shared {@link FlutterEngine}, we MUST manually invoke {@link
|
||||
* ActivityControlSurface#attachToActivity(ExclusiveAppComponent, Lifecycle)}.
|
||||
*
|
||||
* <p>The {@link ExclusiveAppComponent} is exposed here so that subclasses of {@link
|
||||
* FlutterActivity} or {@link FlutterFragment} can access it.
|
||||
*/
|
||||
ExclusiveAppComponent<Activity> getExclusiveAppComponent();
|
||||
|
||||
@Nullable
|
||||
SplashScreen provideSplashScreen();
|
||||
|
||||
|
||||
@@ -746,6 +746,15 @@ public class FlutterFragment extends Fragment
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Android App Component exclusively attached to {@link
|
||||
* io.flutter.embedding.engine.FlutterEngine}.
|
||||
*/
|
||||
@Override
|
||||
public ExclusiveAppComponent<Activity> getExclusiveAppComponent() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
@@ -304,6 +304,19 @@ public class FlutterActivityTest {
|
||||
verify(mockDelegate, times(1)).release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itReturnsExclusiveAppComponent() {
|
||||
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);
|
||||
ActivityController<FlutterActivity> activityController =
|
||||
Robolectric.buildActivity(FlutterActivity.class, intent);
|
||||
FlutterActivity flutterActivity = activityController.get();
|
||||
FlutterActivityAndFragmentDelegate delegate =
|
||||
new FlutterActivityAndFragmentDelegate(flutterActivity);
|
||||
flutterActivity.setDelegate(delegate);
|
||||
|
||||
assertEquals(flutterActivity.getExclusiveAppComponent(), delegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itDelaysDrawing() {
|
||||
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);
|
||||
|
||||
@@ -335,6 +335,11 @@ public class FlutterAndroidComponentTest {
|
||||
return TransparencyMode.transparent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExclusiveAppComponent<Activity> getExclusiveAppComponent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SplashScreen provideSplashScreen() {
|
||||
|
||||
@@ -213,6 +213,15 @@ public class FlutterFragmentTest {
|
||||
assertFalse(mockDelegate.isAttached());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itReturnsExclusiveAppComponent() {
|
||||
FlutterFragment fragment = FlutterFragment.createDefault();
|
||||
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(fragment);
|
||||
fragment.setDelegate(delegate);
|
||||
|
||||
assertEquals(fragment.getExclusiveAppComponent(), delegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() {
|
||||
// We need to mock FlutterJNI to avoid triggering native code.
|
||||
|
||||
Reference in New Issue
Block a user