Skip to content

Commit

Permalink
Use shared-prefs to avoid onboarding screen that blocks the UI in exp…
Browse files Browse the repository at this point in the history
…o dev client (#374)

This PR gets rid of the onboarding modal that pops up with
expo-dev-client apps after launch.

Since the modal is blocking JS looper, it prevents the app from
establishing devtools connection which may lead to timeouts and hence
prevent "app ready" events. As a consequence, the IDE fails to recognize
the app is properly launched.

Before, we've been using `disableOnboarding` flag passed as URL
parameter when launching the app. However, it appears like it's never
worked properly (see this fix here:
expo/expo#29697). For the time being we decided
to use an alternative approach in which we write onboarding parameter
into shared props that are used to store the information whether the
popup should be displayed or not.
  • Loading branch information
kmagiera authored Jun 12, 2024
1 parent 8c633f9 commit 10bf08a
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions packages/vscode-extension/src/devices/AndroidEmulatorDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ export class AndroidEmulatorDevice extends DeviceBase {
await exec(ADB_PATH, ["-s", this.serial!, "shell", "input", "keyevent", "82"]);
}

async configureExpoDevMenu(packageName: string) {
// this code disables expo devmenu popup when the app is launched. When dev menu
// is displayed, it blocks the JS loop and hence react devtools are unable to establish
// the connection, and hence we never get the app ready event.
const prefsXML = `<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n<map><boolean name="isOnboardingFinished" value="true"/></map>`;
await exec(
ADB_PATH,
[
"-s",
this.serial!,
"shell",
`run-as ${packageName} sh -c 'mkdir -p /data/data/${packageName}/shared_prefs && cat > /data/data/${packageName}/shared_prefs/expo.modules.devmenu.sharedpreferences.xml'`,
],
{
// pass serialized prefs as input:
input: prefsXML,
}
);
}

async configureMetroPort(packageName: string, metroPort: number) {
// read preferences
let prefs: any;
Expand Down Expand Up @@ -230,7 +250,7 @@ export class AndroidEmulatorDevice extends DeviceBase {
"-a",
"android.intent.action.VIEW",
"-d",
expoDeeplink + "&disableOnboarding=1", // disable onboarding dialog via deeplink query param,
expoDeeplink,
]);
}

Expand All @@ -242,7 +262,8 @@ export class AndroidEmulatorDevice extends DeviceBase {
build.packageName === EXPO_GO_PACKAGE_NAME ? "expo-go" : "expo-dev-client";
const expoDeeplink = await fetchExpoLaunchDeeplink(metroPort, "android", deepLinkChoice);
if (expoDeeplink) {
this.launchWithExpoDeeplink(metroPort, devtoolsPort, expoDeeplink);
await this.configureExpoDevMenu(build.packageName);
await this.launchWithExpoDeeplink(metroPort, devtoolsPort, expoDeeplink);
} else {
await this.configureMetroPort(build.packageName, metroPort);
await this.launchWithBuild(build);
Expand Down

0 comments on commit 10bf08a

Please sign in to comment.