1 | # React Native Restart
|
2 |
|
3 | [![npm version](https://img.shields.io/npm/v/react-native-restart.svg?style=flat-square)](https://www.npmjs.com/package/react-native-restart)
|
4 | [![npm downloads](https://img.shields.io/npm/dm/react-native-restart.svg?style=flat-square)](https://www.npmjs.com/package/react-native-restart)
|
5 | [![Build status](https://github.com/avishayil/react-native-restart/actions/workflows/main.yml/badge.svg)](https://github.com/avishayil/react-native-restart/actions/workflows/main.yml)
|
6 |
|
7 | Sometimes you want to reload your app bundle during app runtime. This package will allow you to do it.
|
8 |
|
9 | iOS GIF | Android GIF
|
10 | :-------------------------:|:-------------------------:
|
11 | <img src="./gif/ios.gif" title="iOS GIF" width="250"> | <img src="./gif/android.gif" title="Android GIF" width="250">
|
12 |
|
13 | ## Installation
|
14 |
|
15 | - Using `react-native < 0.62`? install `react-native-restart@0.0.17`
|
16 | - Using `0.71 > react-native >= 0.62`? install `react-native-restart@0.0.24`
|
17 | - Using `react-native >= 0.71`? install `react-native-restart@0.0.25` and above
|
18 |
|
19 | ### With `yarn`
|
20 |
|
21 | ```bash
|
22 | $ yarn add react-native-restart
|
23 | ```
|
24 |
|
25 | ### With `npm`
|
26 | ```bash
|
27 | $ npm install --save react-native-restart
|
28 | ```
|
29 |
|
30 | ## Auto-Linking Setup (react-native >= 0.60)
|
31 |
|
32 | ### iOS
|
33 |
|
34 | ```bash
|
35 | $ cd ios
|
36 | $ pod install
|
37 | ```
|
38 |
|
39 | ### Android
|
40 |
|
41 | No further steps should be taken
|
42 |
|
43 | ## Automatic Installation (Without Auto-Linking)
|
44 |
|
45 | `react-native link react-native-restart` or `npm install -g rnpm && rnpm link react-native-restart`
|
46 |
|
47 | ## Manual Android Installation
|
48 |
|
49 | In `android/settings.gradle`
|
50 | ```gradle
|
51 | ...
|
52 |
|
53 | include ':react-native-restart'
|
54 | project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')
|
55 | ```
|
56 |
|
57 | In `android/app/build.gradle`
|
58 |
|
59 | ```gradle
|
60 | ...
|
61 |
|
62 | dependencies {
|
63 | ...
|
64 |
|
65 | implementation project(':react-native-restart')
|
66 | }
|
67 | ```
|
68 |
|
69 | Register module (in `MainApplication.java`)
|
70 |
|
71 | ```java
|
72 | import com.reactnativerestart.RestartPackage; // <--- Import
|
73 |
|
74 | public class MainApplication extends Application implements ReactApplication {
|
75 |
|
76 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
|
77 | ......
|
78 |
|
79 | /**
|
80 | * A list of packages used by the app. If the app uses additional views
|
81 | * or modules besides the default ones, add more packages here.
|
82 | */
|
83 | @Override
|
84 | protected List<ReactPackage> getPackages() {
|
85 | ...
|
86 | return Arrays.<ReactPackage>asList(
|
87 | new MainReactPackage(),
|
88 | new RestartPackage() // Add this line
|
89 | );
|
90 | }
|
91 | };
|
92 | ......
|
93 | };
|
94 |
|
95 | ```
|
96 |
|
97 | ## Manual iOS Installation
|
98 |
|
99 | ### Importing The Library
|
100 |
|
101 | * 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!
|
102 |
|
103 | ![Add Files To...](http://i.imgur.com/puxHiIg.png)
|
104 |
|
105 | ![Library Imported Successfully](http://i.imgur.com/toZUWg5.png)
|
106 |
|
107 | * Ensure that `libRestart.a` is linked through `Link Binary With Libraries` on `Build Phases`:
|
108 |
|
109 | ![Library Linked](http://i.imgur.com/Sm1birt.png)
|
110 |
|
111 | * Ensure that `Header Search Paths` on `Build Settings` has the path `$(SRCROOT)/../node_modules/react-native-restart` set to `recursive`:
|
112 |
|
113 | * You're All Set!
|
114 |
|
115 | ## CocoaPod iOS Installation
|
116 |
|
117 | In your `ios/Podfile` make sure to use `react-native-restart` from the local
|
118 | `node_modules/`. With that, only your project Pod needs to be linked and
|
119 | no extra configuration is required:
|
120 |
|
121 | ```ruby
|
122 | target 'MyReactApp' do
|
123 | # Make sure you're also using React-Native from ../node_modules
|
124 | pod 'React', :path => '../node_modules/react-native', :subspecs => [
|
125 | 'Core',
|
126 | 'RCTActionSheet',
|
127 | # ... whatever else you use
|
128 | ]
|
129 | # React-Native dependencies such as yoga:
|
130 | pod 'yoga', path: '../node_modules/react-native/ReactCommon/yoga'
|
131 |
|
132 | # The following line uses react-native-restart, linking with
|
133 | # the library and setting the Header Search Paths for you
|
134 | pod 'react-native-restart', :path => '../node_modules/react-native-restart'
|
135 | end
|
136 | ```
|
137 |
|
138 | Remember to run `cd ios && pod install` to update files used by Xcode.
|
139 |
|
140 | ## Usage
|
141 |
|
142 | ```javascript
|
143 | import RNRestart from 'react-native-restart'; // Import package from node modules
|
144 |
|
145 | // Immediately reload the React Native Bundle
|
146 | RNRestart.Restart();
|
147 | ```
|
148 |
|
149 | ## Contributing
|
150 |
|
151 | Contributions are welcome. Please see [CONTRIBUTING.md](CONTRIBUTING.md) if you like to contribute to this library.
|
152 |
|
153 | ## Credits
|
154 |
|
155 | Thanks to Microsoft CodePush library. I simply extracted the code from their library's logic to reload the React Native Bundle.
|