Skip to content

Commit

Permalink
Give FlutterView a view ID (flutter#27052)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored Jun 30, 2021
1 parent 2e86f4b commit 6136cbd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit 6136cbd

Please sign in to comment.