GelsonMR
GelsonMR

Reputation: 323

How can I enable Live Reload or Hot Reload without having to shake my phone?

I started using React Native for about 2 weeks, and sometimes I need to reinstall the app, then shake the phone again and enable the live reload.

It's funny at the first week, but then it gets boring to have to shake the phone while developing.

Is there any config file which I can set those development properties to be always enabled?

Upvotes: 4

Views: 4535

Answers (3)

Apurva Aggarwal
Apurva Aggarwal

Reputation: 297

run adb shell input keyevent KEYCODE_MENU in your terminal

Upvotes: 0

Maulana Prambadi
Maulana Prambadi

Reputation: 1041

You can add hot reload function with hold the menu button in your phone it show the developer menu setting for react native app

after that you can select the hotreload function

or you can type this on your terminal

adb shell input keyevent 82

Upvotes: 8

soutot
soutot

Reputation: 3671

There's a closed issue related to open the menu by pressing the screen with 3 fingers. You can check if in the latest versions (or in expo) it is working: https://github.com/facebook/react-native/issues/10191

Also there are other 3 solutions:

1) You can run adb shell input keyevent KEYCODE_MENU in your terminal

2) Try this: https://github.com/facebook/react-native/issues/10191#issuecomment-328854286

Open RN dev menu

/usr/local/bin/adb shell input keyevent KEYCODE_MENU Reload RN

/usr/local/bin/adb shell input keyevent 82 /usr/local/bin/adb shell input keyevent 66 /usr/local/bin/adb shell input keyevent 66 (reload was not always working without adding the last line)

In Preferences->Keyboard->Keyboard shortcuts you can then map these services to keyboard shortcuts. I added the shortcuts for the context of my editor (Webstorm) and React Native debugger. In these programs I can now press Ctrl+D to show the developer menu and Ctrl+R to reload which works perfectly.

3) Or you can try this (Android only) https://medium.com/delivery-com-engineering/react-native-stop-shaking-your-phone-1f4863140146

  1. Set up an Automator Service by opening Automator, clicking “New Document”, and choosing “Service”.

  2. Find and select the “Run Shell Script” action. Choose “no input” for “Service receives” and enter: /usr/local/bin/adb shell input keyevent 82 If adb is located elsewhere in your system, change the path to adb. You can find out with: $ which adb

  3. Save and remember what name you give the action.

  4. Open “System Preferences”, go to “Keyboard” and select the “Shortcuts” tab. Select “Services” on the left column and find your service by name.
  5. Click where it says “none” and enter the keyboard shortcut you want to use. Make it something unique or it will conflict with an existing shortcut.

Notes: Android only Must be plugged in If you’ve never run the following with this device, run it first before trying the shortcut: $ adb reverse tcp:8081 tcp:8081

Hope it helps.

Upvotes: 5

Related Questions