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

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?

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

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
Set up an Automator Service by opening Automator, clicking “New
Document”, and choosing “Service”.
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
Save and remember what name you give the action.
Open “System Preferences”, go to “Keyboard” and select the “Shortcuts” tab. Select “Services” on the left column and find your
service by name.
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.

run adb shell input keyevent KEYCODE_MENU in your terminal

Related

'npm' is not recognized as internal or external command, in windows 11

when I'm typing commands which starts with npm, it shows the massage of ,
"'npm' is not recognized as internal or external command"
Download node.js
First of all Download and install node.js from here Nodejs.org
In windows 11
There are two ways to do this
the short way is,
1. Go to settings
2. Now you are on System window, click About
3. Next, Click on Advanced system settings button
4. Then, Click Environment Variable on the dialogue box
5. From Environment Variable, Select Path6. And then click Edit
7. click New
8. At the text box, add ; C:\Program Files\node.js\
9. Click Ok all the open dialogue box
Reference: Fix ~ npm not recognized as internal or external command (Note: this is my own blog[include images also)

How to set React_Editor to PhpStorm so that when you click on the error it jumps to the code?

I'm using PhpStorm in Mac to code and i want to debug my errors. I have a message in my terminal to set the editor for React Native tools.
PRO TIP
When you see Red Box with stack trace, you can click any
stack frame to jump to the source file. The packager will launch your
editor of choice. It will first look at REACT_EDITOR environment
variable, then at EDITOR.
To set it up, you can add something like
export REACT_EDITOR=atom to your ~/.bashrc or ~/.zshrc depending on
which shell you use.
I've added these lines to ~/.bashrc but nothing happened when i click on the error :
export PATH=$PATH:/usr/local/bin/pstorm
export REACT_EDITOR=pstorm
How can i set correctly REACT_EDITOR to PhpStorm so that when i click on the error it jumps to my code?
For mac os you need to add to ~/.bashrc or .zprofile:
Add export REACT_EDITOR="webstorm" or pstorm
Don't forget to close all of your terminal windows and restart the react-native packager before you try it.
Create a shortcut to open WebStorm:
Open WebStorm
Press ⇧ twice to open the search window
Type “Create Command Line Launcher…” and press Enter
Click OK
That's it.
/usr/local/bin should be in the PATH environment variable by default. You should be able to run webstorm from anywhere in the shell. Run webstorm /usr/local/bin/webstorm to test the command.
You can find a code which opens editors here or in your project node_modules/#react-native-community/cli-tools/build/launchEditor.js
I solved this problem by creating symlink.
sudo ln -s /Applications/WebStorm.app/Contents/MacOS/webstorm /usr/local/bin/webstorm

Android emulator not opening in vs code

When I use `flutter in vs code I am able to start the android emulator easily but when I do it in vs code with react native I get this:
Command 'React Native: Launch Android Emulator' resulted in an error (Error while executing command 'emulator -list-avds': Command failed: emulator -list-avds 'emulator' is not recognized as an internal or external command, operable program or batch file. )
This error is killing me please help. I am using expo CLI with react native.
In windows you can go to Start > Control Panel > System > Advanced System Settings > Environment Variables .
Then under System Variables find Path and double click on it and add this path C:\Users\<your-username>\AppData\Local\Android\sdk\emulator
or in windows 7 append the path with a ; at the end of line.
Then click the OK buttons to get out.
If you already have a Command Prompt window open, close it then re-open and the emulator -list-avds command should then work.

Reload a React Native app on an Android device manually via command line

I'd like to manually force a Reload of my React Native app on demand without physically shaking the device. (I'm getting carpal tunnel.)
I know that Live Reload / Hot Reload are available. I'm looking for a on-demand command line solution.
Using the cmd line you can send a command to the Android device.
adb shell input text "RR"
This command tells the Android device to type the character "R" twice which is the React Native command to Reload on Android.
The adb shell command has many useful features many of which are described here:
ADB Shell Input Events
To open the developer menu:
adb shell input keyevent 82
Just posting it here in case you didn't know this trick
long press the menu button in your android device. Then you'll get this menu
tap the reload option and you are good to go
I use the following command. It doesn't reload the app, but it brings up the developper menu on the device, so I can then press the "Reload" option:
adb shell input keyevent KEYCODE_MENU
I develop with a real device (not the emulator) and sending the "double-R" through adb doesn't work (it just shows the keyboard and types 2 Rs).
Add the following script to your package.json:
"android-shake": "adb shell input keyevent 82"
Then you will be able to call
yarn android-shake
If you are looking for ios then checkout my answer on this link
One trick would be to add this command on ~/.bashrc profile in the case you're using unix.
use your favorite editor (ex: nano on Ubuntu) and type nano ~/.bashrc
on the end of file write alias rnreload='adb shell input text "RR"'
save it and run source ~/.bashrc in order to active it.
Now whenever you need, just type rnreload on a terminal.
Next time you enter your computer it should be already done.
Also, there's the possibility to add an other alias as well: alias rnshake='adb shell input keyevent 82' which "shakes" android. You can use it to access other commands like Hot Reloading, Debugger, Inspector, etc.
Made an autohotkey script to reload and open the menu with keyboard shortcuts.
^+r:: run, %comspec% /c adb shell input text "RR",,hide
^+e:: run, %comspec% /c adb shell input keyevent 82,,hide
ctrl+shift+r to reload
ctrl+shift+e to open dev menu
If you're on a Mac and using Hammerspoon, you can put the following bit of code in your ~/.hammerspoon/init.lua file:
hyper = {'ctrl', 'alt', 'cmd'}
placid = {'ctrl', 'cmd'}
-- React native reload JS on connected device
hs.hotkey.bind(placid, 'R', function()
os.execute('/Users/peter/Library/Android/sdk/platform-tools/adb shell input text "RR"')
end)
-- React native show dev menu on connected device
hs.hotkey.bind(hyper, 'R', function()
os.execute('/Users/peter/Library/Android/sdk/platform-tools/adb shell input keyevent 82')
end)
the os.execute command doesn't load your ENV (doing so would make running commands really slow), so make sure to run which adb in your terminal to figure out what the exact path to adb is. (in my case it was /Users/peter/Library/Android/sdk/platform-tools/adb).
Now you can reload your app using ctrl+cmd+R and show the dev menu using ctrl+option+cmd+R from anywhere and without even bothering to cmd-tab out of your favorite editor!
For device you have just to shake your device than a menu appears so click on Reload

How to keep weblogic running after closing putty window

I’ve started weblogic through putty:
./startWebLogic.sh
After that server started successfully.
But when I close the putty window, the server stops working
How can I keep weblogic running after I close the putty window?
Thanks!
You will want to use something like the following:
nohup ./startWebLogic.sh &
Nohup is a unix command, used to start another program, in such a way that it does not terminate when the parent process is terminated.
You can also output it to a file if you'd like:
nohup ./startWebLogic.sh > admin_server.out &
Simple Steps:
after the login through putty follow the below steps:
Go directory of server where "startWebLogic.sh" this command located.
typed command "screen" press enter (A new Screen will opened)
In the new screen type your run command "./startWebLogic.sh".
Press Ctrl+a then press d(without holding Ctrl) you will return back previous screen)
if like to go again your server log screen typed command "screen -r"
Akbar