Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button for dev menu #42

Merged
merged 3 commits into from
Apr 5, 2024
Merged

Add button for dev menu #42

merged 3 commits into from
Apr 5, 2024

Conversation

jakub-gonet
Copy link
Member

@jakub-gonet jakub-gonet commented Mar 27, 2024

Adds a button in IDE settings that opens dev menu. On iOs it uses native module to open it, on Android we spawn adb process and send KEYCODE_MENU (code 82) to the emulator.

Resolves #30.

Android iOS
android.mov
ios.mov

Copy link

vercel bot commented Mar 27, 2024

@jakub-gonet is attempting to deploy a commit to the software-mansion Team on Vercel.

To accomplish this, @jakub-gonet needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

Comment on lines 137 to 141
if (platform === Platform.IOS) {
this.devtools.send("rnp_iosDevMenu");
} else {
await (this.device as AndroidEmulatorDevice).openDevMenu();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This should live in metro.ts ideally.
  • Can't be method on DeviceBase because needs devtools to send an event – no need to add it into method signature nor class state.
  • Polimorphism failed me here but if never disappoint.

Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, added some minor comments inline. Please address these before merging.

@@ -130,6 +130,14 @@ export function PreviewAppWrapper({ children, ...rest }) {
newRoute && push(newRoute);
});

agent._bridge.addListener("rnp_iosDevMenu", (_payload) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the prefix we use recently for commands to RNIDE_ IIRC. Can you update it here

<SettingsDropdown project={project} disabled={devicesNotFound}>
<SettingsDropdown
project={project}
isDeviceRunning={projectState.status === "running"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not worth adding extra parameter given we already pass project down

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to call getProjectState() which returns a promise which is harder to work with so I opted to use the status if we have it there.

@@ -281,6 +281,13 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
this.deviceSession?.openNavigation(navigationItemID);
}

public async openDevMenu() {
const currentDevice = this.projectState.selectedDevice;
if (currentDevice !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this check? Seems like the device session implementation should deal with this type of edge cases and here should should just delegate it to it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a hard time structuring this code. We'd need to pass selectedDevice to device session. We could also add platform() callback to DeviceBase which would be really convenient but it kinda defeats the purpose of subclassing.

Initially I thought this wasn't the best idea but right now seems like not bad solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best solution would be to create openDevMenu in BaseDevice but in case of iOS it'd need devtools which I don't like.

@@ -37,6 +37,10 @@ export class AndroidEmulatorDevice extends DeviceBase {
super();
}

public platform(): Platform {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to public get platform

@jakub-gonet jakub-gonet merged commit 816815f into main Apr 5, 2024
1 of 2 checks passed
@jakub-gonet jakub-gonet deleted the jgonet/dev-menu branch April 5, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add button to launch developer menu
2 participants