Give FlutterView a view ID (flutter/engine#27052)

This commit is contained in:
Emmanuel Garcia
2021-06-29 21:02:06 -07:00
committed by GitHub
parent 08b5e902a1
commit 277ee46c46
2 changed files with 24 additions and 1 deletions

View File

@@ -209,6 +209,14 @@ public class FlutterActivity extends Activity
implements FlutterActivityAndFragmentDelegate.Host, LifecycleOwner {
private static final String TAG = "FlutterActivity";
/**
* The ID of the {@code FlutterView} created by this activity.
*
* <p>This ID can be used to lookup {@code FlutterView} in the Android view hierarchy. For more,
* see {@link android.view.View#findViewById}.
*/
public static final int FLUTTER_VIEW_ID = 0xF1F2;
/**
* Creates an {@link Intent} that launches a {@code FlutterActivity}, which creates a {@link
* FlutterEngine} that executes a {@code main()} Dart entrypoint, and displays the "/" route as
@@ -424,7 +432,11 @@ public class FlutterActivity extends Activity
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
configureWindowForTransparency();
setContentView(createFlutterView());
View flutterView = createFlutterView();
flutterView.setId(FLUTTER_VIEW_ID);
setContentView(flutterView);
configureStatusBarForFullscreenFlutterExperience();
}

View File

@@ -68,6 +68,17 @@ public class FlutterActivityTest {
FlutterInjector.reset();
}
@Test
public void flutterViewHasId() {
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity activity = activityController.get();
activity.onCreate(null);
assertNotNull(activity.findViewById(FlutterActivity.FLUTTER_VIEW_ID));
}
@Test
public void itCreatesDefaultIntentWithExpectedDefaults() {
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);