Skip to content

Instantly share code, notes, and snippets.

@Grohden
Created November 14, 2024 17:20
Show Gist options
  • Save Grohden/773c25a0ca8483886201d179df0414ee to your computer and use it in GitHub Desktop.
Save Grohden/773c25a0ca8483886201d179df0414ee to your computer and use it in GitHub Desktop.
Exploring react native alternative dev commands

I've recently got annoyed that I had to do manual reloads (usually click focus simulatro + cmd+ctrl+z + click reload + click focus IDE) from outside of my IDE, so here's my little adventure trying to make a shortcut that interacts with the simulator or the android emulator in jetbrains

For android we have a solution straightforward solution, just run an adb command and add it as an external tool + hook into the shortcut:

adb shell input keyevent 82

For iOS it was a little bit complicated.. I first thought of using simctl to do commands but that doesn't seem to do anything similar to what adb does, so I came up with an apple script (based on this:

tell application "System Events"
    -- Activate the Simulator if it's not already frontmost
    tell application "Simulator" to activate

    -- Simulate the key press: Ctrl + Cmd + Z
    keystroke "z" using {control down, command down}
end tell

With it, I can just run osascript ./file.applescript and the reload menu will work, I can then hook it into an external action + bind the keyboard shortcut

Althought this one was ok, I relized with this comment that we can just curl the dev server:

curl localhost:8081/reload

And since reload is mainly the command I use, I'll be just using it instead of the menu

Note: I might get back to the applescript cuz sometimes RN loses connection with metro and metro commands will not work... but lets see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment