Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Give FlutterView a view ID #27052

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -424,7 +432,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);

configureWindowForTransparency();
setContentView(createFlutterView());

View flutterView = createFlutterView();
flutterView.setId(FLUTTER_VIEW_ID);
setContentView(flutterView);

configureStatusBarForFullscreenFlutterExperience();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ public void tearDown() {
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);
Expand Down