Преглед изворни кода

move v1tov2diff to README.md (#1387)

bogobogo пре 7 година
родитељ
комит
6296769ce8
1 измењених фајлова са 311 додато и 28 уклоњено
  1. 311
    28
      README.md

+ 311
- 28
README.md Прегледај датотеку

@@ -1,44 +1,327 @@
1
+#  React Native Navigation v2 (WIP)
2
+We are rebuilding react-native-navigation
1 3
 
2
-<h1 align="center">
3
-  <img src="./logo.png"/><br>
4
-  React Native Navigation
5
-</h1>
4
+- [Why?](#why-rebuild-react-native-navigation)
5
+- [Where is it standing now?](#where-is-it-standing-now)
6
+- [Getting Started](#getting-started-with-v2)
7
+- [Usage](#usage)
6 8
 
7
-[![NPM Version](https://img.shields.io/npm/v/react-native-navigation.svg?style=flat)](https://www.npmjs.com/package/react-native-navigation)
8
-[![NPM Downloads](https://img.shields.io/npm/dm/react-native-navigation.svg?style=flat)](https://www.npmjs.com/package/react-native-navigation)
9
-[![Build Status](https://travis-ci.org/wix/react-native-navigation.svg?branch=master)](https://travis-ci.org/wix/react-native-navigation)
10
-[![Join us on Discord](https://img.shields.io/badge/discord-react--native--navigation-738bd7.svg?style=flat)](https://discord.gg/DhkZjq2)
9
+## Why Rebuild react-native-navigation?
11 10
 
12
-## Important
13
-Latest stable version is `1.1.x` and is published to npm under tag `latest`. It supports react-native 0.43 and above.
14
-<br><br>We are currently redesigning and rewriting this project under branch `v2`.
15
-<br>As a result, new features and pull requests on the current stable version will take more time to process.
11
+### A New Improved Core Architecture
12
+react-native-navigation has a few issues which are unsolvable in it’s current architecture. <br>
13
+These issues originate from the same problem: you cannot specify on which screen you wish to make an action. Whenever you want to push a screen, show a modal or any other action, the action defaults to originate from your current screen. This covers most use cases but there are some edge cases: <br>
14
+* What if you want to update your navbar icons and the user pops the screen? Your icons might update on the wrong screen.
15
+* What if you want to push a screen as a result of a redux action?
16 16
 
17
-### tldr;
17
+There are ways to solve some of these problems in v1 but they are not straightforward. We want to change that.
18 18
 
19
-React Native Navigation provides 100% native platform navigation on both iOS and Android for React Native apps. The JavaScript API is simple and cross-platform - just install it in your app and give your users the native feel they deserve. Using redux? No problem: React Native Navigation comes with optional redux support out of the box. Ready to get started? Check out the [docs](https://wix.github.io/react-native-navigation/).
19
+#### New API
20
+To solve this problem in v2, every screen receives as a prop it’s containerId. Whenever you want to perform an action from that screen you need to pass the containerId to the function:
21
+```js
22
+Navigator.pop(this.props.containerId)
23
+```
24
+### Built for Contributors
25
+Currently, it requires a lot of work to accept pull requests. We need to manually make sure that everything works before we approve them because v1 is not thoroughly tested. <br>
26
+v2 is written with contributors in mind from day one.
20 27
 
21
-<img src="https://github.com/wix/react-native/blob/master/src/videos/demo.gif?raw=true" width="240">&nbsp;&nbsp;&nbsp;&nbsp;
22
-<img src="https://github.com/wix/mobile/blob/master/src/videos/final_element_Transition.mp4.gif?raw=true" width="240">
28
+#### Written In TDD
29
+v2 is written in Test Driven Development. We have a test for every feature including features that are not implemented yet. This makes accepting pull requests extremely easy: If our tests pass, your pull request is accepted.
23 30
 
24
-## Quick Links
25
-* [Documentation](https://wix.github.io/react-native-navigation/#/)
26
-* [Stack Overflow](http://stackoverflow.com/questions/tagged/react-native-navigation)
27
-* [Chat with us](https://discord.gg/DhkZjq2)
28
-* Bootstrap - If you prefer to learn more about the library and the APIs through code, head over to [the bootstrap example app](https://github.com/wix/react-native-navigation-bootstrap) or the more feature rich [JuneDomingo/movieapp](https://github.com/JuneDomingo/movieapp)
29 31
 
30
-----
32
+## Where is it standing now?
33
+v2 currently supports most of react-native-navigation’s basic functions but it is still behind v1.
34
+Here is the full comparison of features between v1 and v2 (will be updated regulary):
35
+### Top Level API
31 36
 
32
-One of the major things missing from React Native core is fully featured native navigation. Navigation includes the entire skeleton of your app with critical components like nav bars, tab bars and side menu drawers.
37
+|    API              | v1  | v2 |
38
+|--------------------|-----|----|
39
+| startTabBasedApp   |   ✅    |   ✅  |
40
+| startSinglePageApp |   ✅   |  ✅   |
41
+| registerScreen     |   ✅   |  ✅   |
42
+| drawer             |    ✅  |    ✅ |
43
+### Screen API
33 44
 
34
-If you're trying to deliver a user experience that's on par with the best native apps out there, you simply can't compromise on JS-based components trying to fake the real thing.
45
+|  API              | v1     | v2         |
46
+|---------------------|--------|------------|
47
+| push                |  ✅     |   ✅       |
48
+| pop                 |  ✅     |  ✅        |
49
+| showModal           |  ✅     |  ✅        |
50
+| popToRoot           |   ✅     |   ✅         |
51
+| resetTo             |   ✅     |    ✅        |
52
+| dismissModal        |   ✅     |     ✅       |
53
+| dismissAllModals    |   ✅     |      ✅      |
54
+| showLightBox        |   ✅     |      [Contribute](CONTRIBUTING.md)      |
55
+| dismissLightBox     |   ✅     |       [Contribute](CONTRIBUTING.md)       |
56
+| handleDeepLink      |   ✅     |       [Contribute](CONTRIBUTING.md)       |
57
+| setOnNavigatorEvent |   ✅     |       [Contribute](CONTRIBUTING.md)       |
58
+| setButtons          |   ✅     |         [Contribute](CONTRIBUTING.md)     |
59
+| setTitle            |   ✅     |         [Contribute](CONTRIBUTING.md)     |
60
+| toggleDrawer        |   ✅     |        [Contribute](CONTRIBUTING.md)   |
61
+| toggleTabs          |   ✅     |        [Contribute](CONTRIBUTING.md)     |
62
+| setTabBadge         |    ✅    |       [Contribute](CONTRIBUTING.md)     |
63
+| switchToTab         |    ✅    |        [Contribute](CONTRIBUTING.md)    |
64
+| toggleNavBar        |   ✅     |      [Contribute](CONTRIBUTING.md)      |
65
+| Screen Visibility   |   ✅     |       ✅     |
35 66
 
36
-For example, this package replaces the native [NavigatorIOS](https://facebook.github.io/react-native/docs/navigatorios.html) that has been [abandoned](https://facebook.github.io/react-native/docs/navigator-comparison.html) in favor of JS-based solutions that are easier to maintain. For more details see in-depth discussion [here](https://github.com/wix/react-native-controllers#why-do-we-need-this-package).
67
+Element tranisitions, adding buttons and styles are not yet implemented. [Contribute](CONTRIBUTING.md)
37 68
 
69
+## Getting started with v2
70
+If v2 supports everything you need for your app we encourage you to use it.
38 71
 
39
-## License
72
+### Installation
73
+1. Download react-native-navigation v2
74
+```bash
75
+yarn add react-native-navigation@alpha
76
+```
77
+##### iOS
78
+2. In Xcode, in Project Navigator (left pane), right-click on the `Libraries` > `Add files to [project name]`. Add `./node_modules/react-native-navigation/lib/ios/ReactNativeNavigation.xcodeproj` ([screenshots](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#step-1))
40 79
 
41
-The MIT License.
80
+3. In Xcode, in Project Navigator (left pane), click on your project (top) and select the `Build Phases` tab (right pane). In the `Link Binary With Libraries` section add `libReactNativeNavigation.a` ([screenshots](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#step-2))
81
+
82
+4. In Xcode, in Project Navigator (left pane), click on your project (top) and select the `Build Settings` tab (right pane). In the `Header Search Paths` section add `$(SRCROOT)/../node_modules/react-native-navigation/lib/ios`. Make sure on the right to mark this new path `recursive` ([screenshots](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#step-3))
83
+
84
+5. In Xcode, under your project files, modify `AppDelegate.m`. add:
85
+
86
+`#import <ReactNativeNavigation/ReactNativeNavigation.h>`
87
+
88
+remove everything in the method didFinishLaunchingWithOptions and add:
89
+
90
+```
91
+NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
92
+[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
93
+```
94
+
95
+##### Android
96
+2. Add the following in `android/settings.gradle`.
97
+
98
+	```groovy
99
+	include ':react-native-navigation'
100
+	project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-	navigation/lib/android/app/')
101
+	```
102
+
103
+3. Update project dependencies in `android/app/build.gradle`.
104
+	```groovy
105
+	android {
106
+		compileSdkVersion 25
107
+		buildToolsVersion "25.0.1"
108
+		...
109
+	}
110
+
111
+	dependencies {
112
+		compile fileTree(dir: "libs", include: ["*.jar"])
113
+		compile "com.android.support:appcompat-v7:23.0.1"
114
+		compile "com.facebook.react:react-native:+"
115
+		compile project(':react-native-navigation')
116
+	}
117
+	```
118
+
119
+4. In `MainActivity.java` it should extend `com.reactnativenavigation.controllers.SplashActivity` instead of `ReactActivity`.
120
+
121
+	This file can be located in `android/app/src/main/java/com/yourproject/`.
122
+
123
+	```java
124
+	import com.reactnativenavigation.controllers.SplashActivity;
125
+
126
+	public class MainActivity extends SplashActivity {
127
+
128
+	}
129
+	```
130
+
131
+	If you have any **react-native** related methods, you can safely delete them.
132
+
133
+5. In `MainApplication.java`, add the following
134
+	```java
135
+	import com.reactnativenavigation.NavigationApplication;
136
+
137
+	public class MainApplication extends NavigationApplication {
138
+
139
+		@Override
140
+		public boolean isDebug() {
141
+			// Make sure you are using BuildConfig from your own application
142
+			return BuildConfig.DEBUG;
143
+		}
144
+
145
+		protected List<ReactPackage> getPackages() {
146
+			// Add additional packages you require here
147
+			// No need to add RnnPackage and MainReactPackage
148
+			return Arrays.<ReactPackage>asList(
149
+				// eg. new VectorIconsPackage()
150
+			);
151
+		}
152
+
153
+		@Override
154
+		public List<ReactPackage> createAdditionalReactPackages() {
155
+			return getPackages();
156
+		}
157
+	}
158
+	```
159
+
160
+	Make sure that `isDebug` and `createAdditionalReactPackages` methods are implemented.
161
+
162
+6. Update `AndroidManifest.xml` and set **android:name** value to `.MainApplication`
163
+	```xml
164
+	<application
165
+		android:name=".MainApplication"
166
+		...
167
+	/>
168
+## Usage
169
+### Top Screen API
170
+
171
+#### Navigation
172
+```js
173
+import Navigation from 'react-native-navigation';
174
+```
175
+#### Events - On App Launched
176
+How to initiate your app.
177
+
178
+```js
179
+Navigation.events().onAppLaunched(() => {
180
+    Navigation.setRoot({
181
+      container: {
182
+        name: 'navigation.playground.WelcomeScreen'
183
+      }
184
+    });
185
+  });
186
+```
187
+
188
+#### registerContainer(screenID, generator)
189
+Every screen component in your app must be registered with a unique name. The component itself is a traditional React component extending React.Component.
190
+```js
191
+Navigation.registerContainer(`navigation.playground.WelcomeScreen`, () => WelcomeScreen);
192
+```
193
+
194
+#### setRoot({params})
195
+Start a Single page app with two side menus:
196
+```js
197
+Navigation.setRoot({
198
+      container: {
199
+        name: 'navigation.playground.WelcomeScreen'
200
+      },
201
+      sideMenu: {
202
+        left: {
203
+          container: {
204
+            name: 'navigation.playground.TextScreen',
205
+            passProps: {
206
+              text: 'This is a left side menu screen'
207
+            }
208
+          }
209
+        },
210
+        right: {
211
+          container: {
212
+            name: 'navigation.playground.TextScreen',
213
+            passProps: {
214
+              text: 'This is a right side menu screen'
215
+            }
216
+          }
217
+        }
218
+      }
219
+    });
220
+```
221
+Start a tab based app:
222
+```js
223
+Navigation.setRoot({
224
+      tabs: [
225
+        {
226
+          container: {
227
+            name: 'navigation.playground.TextScreen',
228
+            passProps: {
229
+              text: 'This is tab 1',
230
+              myFunction: () => 'Hello from a function!'
231
+            }
232
+          }
233
+        },
234
+        {
235
+          container: {
236
+            name: 'navigation.playground.TextScreen',
237
+            passProps: {
238
+              text: 'This is tab 2'
239
+            }
240
+          }
241
+        }
242
+      ]
243
+    });
244
+```
245
+### Screen API
246
+
247
+#### push(params)
248
+Push a new screen into this screen's navigation stack.
249
+```js
250
+Navigation.push(this.props.containerId, {
251
+      name: 'navigation.playground.PushedScreen',
252
+      passProps: {}
253
+    });
254
+```
255
+#### pop(containerId)
256
+Pop the top screen from this screen's navigation stack.
257
+```js
258
+Navigation.pop(this.props.containerId);
259
+```
260
+#### popTo(params)
261
+```js
262
+Navigation.popTo(this.props.containerId, this.props.previousScreenIds[0]);
263
+```
264
+#### popToRoot()
265
+Pop all the screens until the root from this screen's navigation stack
266
+```js
267
+Navigation.popToRoot(this.props.containerId);
268
+```
269
+#### showModal(params = {})
270
+Show a screen as a modal.
271
+```js
272
+Navigation.showModal({
273
+      container: {
274
+        name: 'navigation.playground.ModalScreen',
275
+        passProps: {
276
+            key: 'value'
277
+        }
278
+      }
279
+    });
280
+```
281
+#### dismissModal(containerId)
282
+Dismiss modal.
283
+```js
284
+Navigation.dismissModal(this.props.containerId);
285
+```
286
+#### dismissAllModals()
287
+Dismiss all the current modals at the same time.
288
+```js
289
+Navigation.dismissAllModals();
290
+```
291
+#### Screen Lifecycle - onStop() and onStart()
292
+
293
+The onStop() and onStart() functions are lifecycle functions that are added to the screen and run when a screen apears and disappears from the screen. To use them simply add them to your component like any other react lifecycle function:
294
+
295
+```js
296
+class LifecycleScreen extends Component {
297
+  constructor(props) {
298
+    super(props);
299
+    this.state = {
300
+      text: 'nothing yet'
301
+    };
302
+  }
303
+
304
+  onStart() {
305
+    this.setState({ text: 'onStart' });
306
+  }
307
+
308
+  onStop() {
309
+    alert('onStop'); //eslint-disable-line
310
+  }
311
+
312
+  componentWillUnmount() {
313
+    alert('componentWillUnmount'); //eslint-disable-line
314
+  }
315
+
316
+  render() {
317
+    return (
318
+      <View style={styles.root}>
319
+        <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
320
+	<Text style={styles.h1}>{this.state.text}</Text>
321
+      </View>
322
+    );
323
+  }
324
+}
325
+```
42 326
 
43
-See [LICENSE](LICENSE)
44 327