React Native Restart
Sometimes you want to reload your app bundle during app runtime. This package will allow you to do it.
iOS GIF | Android GIF |
---|
| |
Installation
- Using
react-native < 0.62
? install react-native-restart@0.0.17
- Using
0.71 > react-native >= 0.62
? install react-native-restart@0.0.24
- Using
react-native >= 0.71
? install react-native-restart@0.0.27
and above
With yarn
$ yarn add react-native-restart
With npm
$ npm install --save react-native-restart
Auto-Linking Setup (react-native >= 0.60)
iOS
$ cd ios
$ pod install
Android
No further steps should be taken
Automatic Installation (Without Auto-Linking)
react-native link react-native-restart
or npm install -g rnpm && rnpm link react-native-restart
Manual Android Installation
In android/settings.gradle
...
include ':react-native-restart'
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')
In android/app/build.gradle
...
dependencies {
...
implementation project(':react-native-restart')
}
Register module (in MainApplication.java
)
import com.reactnativerestart.RestartPackage;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
......
@Override
protected List<ReactPackage> getPackages() {
...
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RestartPackage()
);
}
};
......
};
Manual iOS Installation
Importing The Library
- Drag the file
Restart.xcodeproj
from /node_modules/react-native-restart/ios
into the Libraries
group in the Project navigator. Ensure that Copy items if needed
is UNCHECKED!
- Ensure that
libRestart.a
is linked through Link Binary With Libraries
on Build Phases
:
CocoaPod iOS Installation
In your ios/Podfile
make sure to use react-native-restart
from the local
node_modules/
. With that, only your project Pod needs to be linked and
no extra configuration is required:
target 'MyReactApp' do
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'RCTActionSheet',
]
pod 'yoga', path: '../node_modules/react-native/ReactCommon/yoga'
pod 'react-native-restart', :path => '../node_modules/react-native-restart'
end
Remember to run cd ios && pod install
to update files used by Xcode.
Usage
import RNRestart from 'react-native-restart';
RNRestart.Restart();
RNRestart.restart();
Contributing
Contributions are welcome. Please see CONTRIBUTING.md if you like to contribute to this library.
Credits
Thanks to Microsoft CodePush library. I simply extracted the code from their library's logic to reload the React Native Bundle.