├── .eslintrc
├── .gitignore
├── LICENSE.txt
├── README.md
├── examples
├── App
│ ├── .babelrc
│ ├── .expo
│ │ ├── packager-info.json
│ │ └── settings.json
│ ├── .gitignore
│ ├── .watchmanconfig
│ ├── App.js
│ ├── App.test.js
│ ├── README.md
│ ├── app.json
│ ├── package.json
│ ├── rn-cli.config.js
│ └── yarn.lock
├── Cube
│ ├── .expo
│ │ ├── packager-info.json
│ │ └── settings.json
│ ├── App.js
│ ├── App.test.js
│ ├── Picture.js
│ ├── README.md
│ ├── app.json
│ ├── assets
│ │ ├── 1.jpg
│ │ ├── 2.jpg
│ │ ├── 3.jpg
│ │ ├── 4.jpg
│ │ ├── 5.jpg
│ │ └── 6.jpg
│ ├── package.json
│ └── styles.js
├── SimpleStack
│ ├── .babelrc
│ ├── .flowconfig
│ ├── .gitignore
│ ├── .watchmanconfig
│ ├── App.js
│ ├── Home.js
│ ├── Message.js
│ ├── Messages.js
│ ├── README.md
│ ├── app.json
│ ├── package.json
│ └── styles.js
└── Usage
│ ├── .expo
│ ├── packager-info.json
│ └── settings.json
│ ├── App.js
│ ├── App.test.js
│ ├── app.json
│ ├── package.json
│ └── yarn.lock
├── lib
├── Stack.js
├── StackTransitioner.js
├── animationTypes.js
├── findFirstMatch.js
├── getDimension.js
├── getDuration.js
├── getEasing.js
├── getTransforms.js
├── index.js
├── styles.js
└── transitionTypes.js
├── media
├── cube-ios.gif
├── different-header.gif
├── fade-vertical-android.gif
├── fixed-header.gif
├── no-header.gif
├── per-route-animation-type-ios.gif
├── simple-stack-ios.gif
├── slide-vertical-ios.gif
└── usage-ios.gif
└── package.json
/.eslintrc:
--------------------------------------------------------------------------------
1 | { "extends": "expo/native" }
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 | .DS_Store
3 | .gradle
4 | *.iml
5 | .idea
6 | node_modules
7 | npm-debug.log
8 | android/build
9 | ios/**/*xcuserdata*
10 | ios/**/*xcshareddata*
11 | yarn.lock
12 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Travis Nuttall
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-router-native-stack
2 |
3 | [](https://www.npmjs.com/package/react-router-native-stack)
4 | [](https://www.npmjs.com/package/react-router-native-stack)
5 |
6 | A Stack component for React Router v4 on React Native.
7 |
8 | ## Disclaimer
9 |
10 | This library is in an alpha state. I am still experimenting with the
11 | transitions and animations, and the API will likely evolve and change. I'd
12 | love for you to try it out and give feedback so that we can get to a production
13 | ready state!
14 |
15 | ## Motivation
16 |
17 | React Router v4 supports react native, but doesn't include any animated transitions
18 | out of the box. I created this component to support card stack style screen transitions.
19 |
20 | Here's a basic demo:
21 |
22 | 
23 |
24 | You can run the above demo on Expo with this link: https://exp.host/@traviskn/simplestack
25 |
26 | ## Installation
27 |
28 | Install `react-router-native` and this package:
29 |
30 | `npm install react-router-native react-router-native-stack --save`
31 |
32 | ## Usage
33 |
34 | Here's a simple working example of using the stack.
35 |
36 | ```javascript
37 | import React, { Component } from 'react';
38 | import { Button, StyleSheet, Text, View } from 'react-native';
39 | import { NativeRouter, Route } from 'react-router-native';
40 | import Stack from 'react-router-native-stack';
41 |
42 | function Home({ history }) {
43 | return (
44 |
45 | Home Page
46 |
47 |
53 | );
54 | }
55 |
56 | function Page({ history, match }) {
57 | return (
58 |
59 | You are on a {match.params.name} Page!
60 |
61 | history.goBack()} />
62 |
63 | history.push('/page/pizza')} />
64 |
65 | history.push('/page/taco')} />
66 |
67 | history.push('/page/hamburger')} />
68 |
69 | );
70 | }
71 |
72 | export default class App extends Component {
73 | render() {
74 | return (
75 |
76 |
77 |
78 |
79 |
80 |
81 | );
82 | }
83 | }
84 |
85 | const styles = StyleSheet.create({
86 | screen: {
87 | flex: 1,
88 | flexDirection: 'column',
89 | alignItems: 'center',
90 | justifyContent: 'space-around',
91 | },
92 | });
93 | ```
94 |
95 | This is what the above code looks like running on iOS:
96 |
97 | 
98 |
99 | The stack component uses a [Switch](https://reacttraining.com/react-router/native/api/Switch)
100 | internally to match the current route. It listens for `'PUSH'` and `'POP'` actions
101 | on history to determine whether to transition forward or backwards. It manages a
102 | PanResponder to allow swiping back through the route stack. It keeps track of the
103 | history index when it mounts so that it knows to stop allowing the swipe back transition
104 | when you reach the beginning index.
105 |
106 | ## Animation Options
107 |
108 | In the examples so far you have seen the default iOS transition animation,
109 | `'slide-horizontal'`. In addition to that the stack also supports `'slide-vertical'`,
110 | `'fade-vertical'`, and `'cube'`.
111 |
112 | if you add an `animationType="slide-vertical"` prop to the stack in the previous
113 | example, this is the result:
114 |
115 | 
116 |
117 | `'fade-vertical'` is the default for Android, and looks like this:
118 |
119 | 
120 |
121 | And finally, here's a demo of `animationType="cube"`:
122 |
123 | 
124 |
125 | There is also an animation type of `'none'` if you need to disable animations.
126 |
127 | ### Animating `history.replace()`
128 |
129 | Sometimes it is desirable to animate a route replace, i.e to animate back to a specific route (without using `history.go(-n)`).
130 |
131 | Use `replaceTransitionType` as a prop, with either `POP` or `PUSH` to animate the `REPLACE` event.
132 |
133 | ```javascript
134 | // A call to `history.replace(routePath)` will now transition using the `POP` animation type.
135 | ```
136 |
137 | ## Gesture Handling Options
138 |
139 | By default the stack component allows swiping back for the `slide-horizontal` and `cube` animation types. If you want to
140 | disable this, you can pass in a `gestureEnabled` prop set to false.
141 |
142 | ```javascript
143 | // This stack will not respond to the swipe back gesture
144 |
145 | {/* Your routes here */}
146 |
147 | ```
148 |
149 | ## Customizing Animation Type Per-Route
150 |
151 | If you need, you can configure the animation type on a per-route basis by adding
152 | an `animationType` prop to a specific route. As an example, consider that we took
153 | our previous example and had a separate route for each page:
154 |
155 | ```javascript
156 | import React, { Component } from 'react';
157 | import { Button, StyleSheet, Text, View } from 'react-native';
158 | import { NativeRouter, Route } from 'react-router-native';
159 | import Stack from 'react-router-native-stack';
160 |
161 | function Home({ history }) {
162 | return (
163 |
164 | Home Page
165 |
166 | history.push('/page/pizza')} />
167 |
168 | history.push('/page/taco')} />
169 |
170 | history.push('/page/hamburger')} />
171 |
172 | );
173 | }
174 |
175 | function Page({ history, match }) {
176 | return (
177 |
178 | You are on a {match.url.replace('/page/', '')} Page!
179 |
180 | history.goBack()} />
181 |
182 | history.push('/page/pizza')} />
183 |
184 | history.push('/page/taco')} />
185 |
186 | history.push('/page/hamburger')} />
187 |
188 | );
189 | }
190 |
191 | export default class App extends Component {
192 | render() {
193 | return (
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 | );
203 | }
204 | }
205 |
206 | const styles = StyleSheet.create({
207 | screen: {
208 | flex: 1,
209 | flexDirection: 'column',
210 | alignItems: 'center',
211 | justifyContent: 'space-around',
212 | },
213 | });
214 | ```
215 |
216 | With this updated code we have configured the taco page to use a `slide-vertical`
217 | animation, but all the other pages will use the default `slide-horizontal` animation.
218 | The taco page will control the animation type when it pushes onto the stack, and
219 | when it pops off of the stack. Here's how it looks:
220 |
221 | 
222 |
223 | ## Specifying a Header and/or Footer component per route
224 |
225 | **Scenario 1:** Sometimes you'll want a fixed header/footer that *doesn't* animate between routes.
226 | **Scenario 2:** At other times you'll want to transition between routes that have *different* headers/footers.
227 | **Scenario 3:** And finally, you may want to transition to a route that has *no* fixed header or footer.
228 |
229 | All this is possible by specifying a `headerComponent` and/or `footerComponent` prop on your routes:
230 |
231 | ```js
232 | export default class App extends Component {
233 | render() {
234 | return (
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 | );
244 | }
245 | }
246 | ```
247 |
248 | Go to `examples/App` to see the full setup for the above.
249 |
250 | **Scenario 1:** If your Header and/or Footer matches that of the route you're transitioning to, then that component
251 | will be considered "fixed" and will not be included in the transition animation.
252 |
253 |
254 |
255 | **Scenario 2:** If the route you're transitioning to contains a different Header/Footer than the previous route,
256 | then the Header/Footer for both routes will be contained *within* the transition area, and will be
257 | included in the transition animation.
258 |
259 |
260 |
261 | **Scenario 3:** If you're transitioning to/from a route that contains *no* Header/Footer, then that's treated the
262 | same as Scenario 2, and any Headers/Footers will be contained within the transition area. The route that
263 | contains no Header/Footer will obviously have none rendered, and therefore the main `component` will
264 | occupy the full area available.
265 |
266 |
267 |
268 | **IMPORTANT NOTE:** The above approach makes no assumption as to the look/feel of the Header/Footer
269 | component, including internal animation. As the React Native world moves towards iOS and Android
270 | apps being built simultaneously, using custom header/footer/navigation components that make sense
271 | within the design system of the given app, it follows that we should give the developer full power
272 | over how to animate the mounting/unmounting of the Header and Footer components themselves (as well
273 | as the elements within them). We do pass the Stack component's internal animated value into the Header
274 | and/or Footer component you provide as an `animatedValue` prop that you can use to build your own
275 | animations that run in sync with the Stack's animations.
276 |
277 | Using the `headerComponent` and `footerComponent` props is a simple way to either include or exclude
278 | components from the route transition animation.
279 |
280 | ## Nested routes
281 |
282 | Where one of the Routes in the Stack have nested Routes the default behaviour is to
283 | animate between pages as if you were changing to completely different route.
284 |
285 | Sometimes this behaviour is not what you want (for example when creating a page
286 | to show items, where items can be deep linked to, but only form part of the page).
287 | In this case you can add a key to the Route, and "self"-transitions are then
288 | ignored.
289 |
290 | ```javascript
291 |
292 |
293 | { /* animates moving to /items, but not when changing itemId */ }
294 |
295 |
296 |
297 | const Items = ({match}) =>
298 |
299 | Items finder
300 | Looking at item {match.params.itemId}
301 |
302 | ```
303 |
304 | ## `isAnimating` handler
305 |
306 | Sometimes you'll want your app to respond a certain way while a route transition animation
307 | is occurring. For example you may want to prevent custom ``'s and ``'s from
308 | performing their usual behaviour (manipulating the `history`) should a route transition be
309 | occurring at that very moment. This helps prevent bugs around users pressing the "back" button
310 | before the current route has finished animating in. To this end, you can pass the `Stack` an
311 | `isAnimating` function which will be called with a boolean value based on the current
312 | state of the route transition.
313 |
314 | ```javascript
315 | {
318 | reduxStore.dispatch(myActionHere(value));
319 | }}
320 | >
321 |
322 |
323 |
324 | ```
325 |
326 | One way of handling the above scenario would be to use a redux dispatcher as my `isAnimating`
327 | handler and subsequently have all my ``'s and ``'s subscribe to the necessary bit
328 | of global state to determine whether to `disable` themselves or not. But ultimately, what your
329 | `isAnimating` function looks like, and how you leverage it, is up to you!
330 |
331 | ## Known Limitations
332 |
333 | Currently the stack has no built-in animations for headers or footers, but that
334 | feature is a work in progress! We do pass down the Stack component's internal
335 | animated value as a prop to the header and/or footer components you add as props
336 | to your routes, so you can potentialy build your own custom animation. We hope to
337 | get more options working soon.
338 |
339 | Many stack navigators keep all screens in the stack mounted when you push new
340 | screens onto the stack. This library is different, in that it unmounts the previous
341 | route's screen when a new one is pushed on. If you have state that needs to be
342 | maintained even after a screen unmounts, you will need to store that state in a
343 | parent component that contains the stack or possibly use another state management
344 | solution such as AsyncStorage, Redux, or MobX.
345 |
346 | A common use case for a cube transition is to swipe forward to the next route,
347 | but currently it only supports swiping back to the previous route. An API to
348 | enable swiping forward to a new route is something I hope to work on soon.
349 |
350 | The cube animation doesn't work quite as well on Android as it does on iOS. I
351 | hope to be able to adjust the animation configuration a bit to make it look more
352 | consistent.
353 |
354 | I have made several assumptions about the history route stack while using this library.
355 | I assume in particular that history never mutates, and that you always navigate
356 | forward by pushing and backward by popping routes. It could be that in cases where
357 | you need to deep link or redirect to a specific location in the app that you haven't
358 | built up the expected route stack, and this component won't allow swiping back
359 | when you need it to.
360 |
361 | As I research more use cases I hope to be able to create a more flexible API to
362 | support them.
363 |
364 | ## Acknowledgements
365 |
366 | I drew a lot of inspiration from other libraries and code samples.
367 |
368 | Obviously this library wouldn't exist without the fantastic [React Router](https://reacttraining.com/react-router)!
369 |
370 | [React Navigation](https://reactnavigation.org/) has become one of the leading
371 | navigation solutions for react native, I have used it in many personal and work
372 | projects and I referenced it as a guide for implementing many of the transition
373 | animations in this library.
374 |
375 | For the cube animation I used [this example](https://github.com/underscopeio/cube-transition-example)
376 | by @underscopeio as a reference.
377 |
378 | Many thanks to the authors and maintainers of these open source libraries!
379 |
380 | ## More
381 |
382 | You may be asking, "What about tab and drawer navigation?". As it turns out,
383 | there are already many great open source components to enable drawer and tab
384 | navigation, and you can already use React Router to drive the state of those
385 | components. I hope to add more examples to this repository soon demonstrating
386 | this. For now know that the Stack is just one of several components that you can
387 | combine with React Router to enable just about any navigation pattern you need!
388 |
389 | Check out the `examples/` folder in this repository for more usage examples.
390 |
--------------------------------------------------------------------------------
/examples/App/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["babel-preset-expo"],
3 | "env": {
4 | "development": {
5 | "plugins": ["transform-react-jsx-source",
6 | ["module-resolver", {
7 | "alias": {
8 | "react-router-native-stack": "../.."
9 | }
10 | }]
11 | ]
12 | }
13 | },
14 | }
15 |
--------------------------------------------------------------------------------
/examples/App/.expo/packager-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "expoServerPort": 19000,
3 | "packagerPort": 19001,
4 | "packagerPid": 75427
5 | }
--------------------------------------------------------------------------------
/examples/App/.expo/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "hostType": "tunnel",
3 | "lanType": "ip",
4 | "dev": true,
5 | "strict": false,
6 | "minify": false,
7 | "urlType": "exp",
8 | "urlRandomness": null
9 | }
10 |
--------------------------------------------------------------------------------
/examples/App/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # misc
7 | .env.local
8 | .env.development.local
9 | .env.test.local
10 | .env.production.local
11 |
12 | npm-debug.log*
13 | yarn-debug.log*
14 | yarn-error.log*
15 |
--------------------------------------------------------------------------------
/examples/App/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/examples/App/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Button, StyleSheet, Text, View } from 'react-native';
3 | import { NativeRouter, Route } from 'react-router-native';
4 | import Stack from 'react-router-native-stack';
5 |
6 | function Header() {
7 | return (
8 |
9 | I am a lovely default header
10 |
11 | );
12 | }
13 |
14 | function PizzaHeader() {
15 | return (
16 |
17 | I am a PIZZA header
18 |
19 | );
20 | }
21 |
22 | function Home({ history }) {
23 | return (
24 |
25 | Home Page
26 |
27 | history.push('/page/pizza')} />
28 |
29 | history.push('/page/taco')} />
30 |
31 | history.push('/page/hamburger')} />
32 |
33 | history.push('/fullscreen')} />
34 |
35 | );
36 | }
37 |
38 | function Page({ match, history }) {
39 | return (
40 |
41 | You're on a {match.params.name} Page!
42 |
43 | history.goBack()} />
44 |
45 | history.push('/page/pizza')} />
46 |
47 | history.push('/page/taco')} />
48 |
49 | history.push('/page/hamburger')} />
50 |
51 | history.push('/fullscreen')} />
52 |
53 | );
54 | }
55 |
56 | function FullScreen({ history }) {
57 | return (
58 |
59 | I am a FullScreen
60 | history.goBack()} />
61 |
62 | );
63 | }
64 |
65 | export default class App extends Component {
66 | render() {
67 | return (
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | );
77 | }
78 | }
79 |
80 | const styles = StyleSheet.create({
81 | screen: {
82 | flex: 1,
83 | flexDirection: 'column',
84 | alignItems: 'center',
85 | justifyContent: 'space-around',
86 | },
87 | header: {
88 | flex: -1,
89 | height: 80,
90 | paddingTop: 40,
91 | backgroundColor: 'blue',
92 | flexDirection: 'row',
93 | alignItems: 'center',
94 | justifyContent: 'center',
95 | },
96 | headerText: {
97 | color: 'white',
98 | },
99 | pizzaHeader: {
100 | backgroundColor: 'green',
101 | },
102 | });
103 |
--------------------------------------------------------------------------------
/examples/App/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import App from './App';
3 |
4 | import renderer from 'react-test-renderer';
5 |
6 | it('renders without crashing', () => {
7 | const rendered = renderer.create().toJSON();
8 | expect(rendered).toBeTruthy();
9 | });
10 |
--------------------------------------------------------------------------------
/examples/App/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app).
2 |
3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md).
4 |
5 | ## Table of Contents
6 |
7 | * [Updating to New Releases](#updating-to-new-releases)
8 | * [Available Scripts](#available-scripts)
9 | * [npm start](#npm-start)
10 | * [npm test](#npm-test)
11 | * [npm run ios](#npm-run-ios)
12 | * [npm run android](#npm-run-android)
13 | * [npm run eject](#npm-run-eject)
14 | * [Writing and Running Tests](#writing-and-running-tests)
15 | * [Environment Variables](#environment-variables)
16 | * [Configuring Packager IP Address](#configuring-packager-ip-address)
17 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon)
18 | * [Sharing and Deployment](#sharing-and-deployment)
19 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community)
20 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app)
21 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app)
22 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio)
23 | * [Should I Use ExpoKit?](#should-i-use-expokit)
24 | * [Troubleshooting](#troubleshooting)
25 | * [Networking](#networking)
26 | * [iOS Simulator won't open](#ios-simulator-wont-open)
27 | * [QR Code does not scan](#qr-code-does-not-scan)
28 |
29 | ## Updating to New Releases
30 |
31 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never.
32 |
33 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies.
34 |
35 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility.
36 |
37 | ## Available Scripts
38 |
39 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.
40 |
41 | ### `npm start`
42 |
43 | Runs your app in development mode.
44 |
45 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal.
46 |
47 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script:
48 |
49 | ```
50 | npm start --reset-cache
51 | # or
52 | yarn start --reset-cache
53 | ```
54 |
55 | #### `npm test`
56 |
57 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests.
58 |
59 | #### `npm run ios`
60 |
61 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.
62 |
63 | #### `npm run android`
64 |
65 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App:
66 |
67 | ##### Using Android Studio's `adb`
68 |
69 | 1. Make sure that you can run adb from your terminal.
70 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location).
71 |
72 | ##### Using Genymotion's `adb`
73 |
74 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`.
75 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)).
76 | 3. Make sure that you can run adb from your terminal.
77 |
78 | #### `npm run eject`
79 |
80 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project.
81 |
82 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up.
83 |
84 | ## Customizing App Display Name and Icon
85 |
86 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key.
87 |
88 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string.
89 |
90 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency.
91 |
92 | ## Writing and Running Tests
93 |
94 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html).
95 |
96 | ## Environment Variables
97 |
98 | You can configure some of Create React Native App's behavior using environment variables.
99 |
100 | ### Configuring Packager IP Address
101 |
102 | When starting your project, you'll see something like this for your project URL:
103 |
104 | ```
105 | exp://192.168.0.2:19000
106 | ```
107 |
108 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides.
109 |
110 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable:
111 |
112 | Mac and Linux:
113 |
114 | ```
115 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start
116 | ```
117 |
118 | Windows:
119 | ```
120 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname'
121 | npm start
122 | ```
123 |
124 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`.
125 |
126 | ## Sharing and Deployment
127 |
128 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service.
129 |
130 | ### Publishing to Expo's React Native Community
131 |
132 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account.
133 |
134 | Install the `exp` command-line tool, and run the publish command:
135 |
136 | ```
137 | $ npm i -g exp
138 | $ exp publish
139 | ```
140 |
141 | ### Building an Expo "standalone" app
142 |
143 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself.
144 |
145 | ### Ejecting from Create React Native App
146 |
147 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio.
148 |
149 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html).
150 |
151 | #### Should I Use ExpoKit?
152 |
153 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option.
154 |
155 | ## Troubleshooting
156 |
157 | ### Networking
158 |
159 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports.
160 |
161 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see:
162 |
163 | ```
164 | exp://192.168.0.1:19000
165 | ```
166 |
167 | Try opening Safari or Chrome on your phone and loading
168 |
169 | ```
170 | http://192.168.0.1:19000
171 | ```
172 |
173 | and
174 |
175 | ```
176 | http://192.168.0.1:19001
177 | ```
178 |
179 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received.
180 |
181 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. If you are using a VPN you may need to disable it.
182 |
183 | ### iOS Simulator won't open
184 |
185 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`:
186 |
187 | * "non-zero exit code: 107"
188 | * "You may need to install Xcode" but it is already installed
189 | * and others
190 |
191 | There are a few steps you may want to take to troubleshoot these kinds of errors:
192 |
193 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store.
194 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so.
195 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`.
196 |
197 | ### QR Code does not scan
198 |
199 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses.
200 |
201 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually.
202 |
--------------------------------------------------------------------------------
/examples/App/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "sdkVersion": "27.0.0",
4 | "packagerOpts": {
5 | "config": "./rn-cli.config.js",
6 | "projectRoots": ""
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/examples/App/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "App",
3 | "version": "0.1.0",
4 | "private": true,
5 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
6 | "scripts": {
7 | "start": "react-native-scripts start",
8 | "eject": "react-native-scripts eject",
9 | "android": "react-native-scripts android",
10 | "ios": "react-native-scripts ios",
11 | "test": "jest"
12 | },
13 | "jest": {
14 | "preset": "jest-expo"
15 | },
16 | "dependencies": {
17 | "expo": "^27.0.1",
18 | "prop-types": "^15.6.2",
19 | "react": "16.3.1",
20 | "react-native": "~0.55.2",
21 | "react-router-native": "^4.3.0"
22 | },
23 | "devDependencies": {
24 | "babel-plugin-module-resolver": "^3.1.1",
25 | "escape-string-regexp": "^1.0.5",
26 | "jest-expo": "~27.0.0",
27 | "react-native-scripts": "1.14.0",
28 | "react-test-renderer": "16.3.1"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/App/rn-cli.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const blacklist = require('metro/src/blacklist');
3 | const escape = require('escape-string-regexp');
4 |
5 | module.exports = {
6 | getProjectRoots() {
7 | return [__dirname, path.resolve(__dirname, '../..')];
8 | },
9 | getProvidesModuleNodeModules() {
10 | return ['react-native', 'react', 'prop-types', 'react-router-native'];
11 | },
12 | getBlacklistRE() {
13 | return blacklist([
14 | new RegExp(`^${escape(path.resolve(__dirname, '../..', 'node_modules'))}\\/.*$`),
15 | new RegExp(`^${escape(path.resolve(__dirname, '..', 'Usage/node_modules'))}\\/.*$`),
16 | new RegExp(`^${escape(path.resolve(__dirname, '..', 'SimpleStack/node_modules'))}\\/.*$`),
17 | new RegExp(`^${escape(path.resolve(__dirname, '..', 'Cube/node_modules'))}\\/.*$`),
18 | new RegExp(`^${escape(path.resolve(__dirname, 'node_modules'))}\\/.*/node_modules\\/.*$`),
19 | ]);
20 | },
21 | };
22 |
--------------------------------------------------------------------------------
/examples/Cube/.expo/packager-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "expoServerPort": 19000,
3 | "packagerPort": 19001,
4 | "packagerPid": 39294,
5 | "expoServerNgrokUrl": null,
6 | "packagerNgrokUrl": null,
7 | "ngrokPid": null
8 | }
--------------------------------------------------------------------------------
/examples/Cube/.expo/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "hostType": "tunnel",
3 | "lanType": "ip",
4 | "dev": true,
5 | "strict": false,
6 | "minify": false,
7 | "urlType": "exp",
8 | "urlRandomness": "tj-npf"
9 | }
--------------------------------------------------------------------------------
/examples/Cube/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { NativeRouter, Route } from 'react-router-native';
3 | import Stack from 'react-router-native-stack';
4 | import Picture from './Picture';
5 |
6 | export default class App extends Component {
7 | render() {
8 | return (
9 |
10 |
11 |
12 |
13 |
14 |
15 | );
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/examples/Cube/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import App from './App';
3 |
4 | import renderer from 'react-test-renderer';
5 |
6 | it('renders without crashing', () => {
7 | const rendered = renderer.create().toJSON();
8 | expect(rendered).toBeTruthy();
9 | });
10 |
--------------------------------------------------------------------------------
/examples/Cube/Picture.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Dimensions, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
3 | import one from './assets/1.jpg';
4 | import two from './assets/2.jpg';
5 | import three from './assets/3.jpg';
6 | import four from './assets/4.jpg';
7 | import five from './assets/5.jpg';
8 | import six from './assets/6.jpg';
9 |
10 | export default class Picture extends Component {
11 | render() {
12 | const { height, width } = Dimensions.get('window');
13 |
14 | const imageIndex = parseInt(this.props.match.params.id || 1, 10);
15 |
16 | let image = one;
17 | if (imageIndex === 2) {
18 | image = two;
19 | } else if (imageIndex === 3) {
20 | image = three;
21 | } else if (imageIndex === 4) {
22 | image = four;
23 | } else if (imageIndex === 5) {
24 | image = five;
25 | } else if (imageIndex === 6) {
26 | image = six;
27 | }
28 |
29 | return (
30 |
31 |
32 |
33 | {imageIndex < 6 && (
34 | this.props.history.push(`/${imageIndex + 1}`)}>
37 | Next >
38 |
39 | )}
40 |
41 | );
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/examples/Cube/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app).
2 |
3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md).
4 |
5 | ## Table of Contents
6 |
7 | * [Updating to New Releases](#updating-to-new-releases)
8 | * [Available Scripts](#available-scripts)
9 | * [npm start](#npm-start)
10 | * [npm test](#npm-test)
11 | * [npm run ios](#npm-run-ios)
12 | * [npm run android](#npm-run-android)
13 | * [npm run eject](#npm-run-eject)
14 | * [Writing and Running Tests](#writing-and-running-tests)
15 | * [Environment Variables](#environment-variables)
16 | * [Configuring Packager IP Address](#configuring-packager-ip-address)
17 | * [Adding Flow](#adding-flow)
18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon)
19 | * [Sharing and Deployment](#sharing-and-deployment)
20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community)
21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app)
22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app)
23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio)
24 | * [Should I Use ExpoKit?](#should-i-use-expokit)
25 | * [Troubleshooting](#troubleshooting)
26 | * [Networking](#networking)
27 | * [iOS Simulator won't open](#ios-simulator-wont-open)
28 | * [QR Code does not scan](#qr-code-does-not-scan)
29 |
30 | ## Updating to New Releases
31 |
32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never.
33 |
34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies.
35 |
36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility.
37 |
38 | ## Available Scripts
39 |
40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.
41 |
42 | ### `npm start`
43 |
44 | Runs your app in development mode.
45 |
46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal.
47 |
48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script:
49 |
50 | ```
51 | npm start -- --reset-cache
52 | # or
53 | yarn start -- --reset-cache
54 | ```
55 |
56 | #### `npm test`
57 |
58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests.
59 |
60 | #### `npm run ios`
61 |
62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.
63 |
64 | #### `npm run android`
65 |
66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App:
67 |
68 | ##### Using Android Studio's `adb`
69 |
70 | 1. Make sure that you can run adb from your terminal.
71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location).
72 |
73 | ##### Using Genymotion's `adb`
74 |
75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`.
76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)).
77 | 3. Make sure that you can run adb from your terminal.
78 |
79 | #### `npm run eject`
80 |
81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project.
82 |
83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up.
84 |
85 | ## Customizing App Display Name and Icon
86 |
87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key.
88 |
89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string.
90 |
91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency.
92 |
93 | ## Writing and Running Tests
94 |
95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/tutorial-react-native.html).
96 |
97 | ## Environment Variables
98 |
99 | You can configure some of Create React Native App's behavior using environment variables.
100 |
101 | ### Configuring Packager IP Address
102 |
103 | When starting your project, you'll see something like this for your project URL:
104 |
105 | ```
106 | exp://192.168.0.2:19000
107 | ```
108 |
109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides.
110 |
111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable:
112 |
113 | Mac and Linux:
114 |
115 | ```
116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start
117 | ```
118 |
119 | Windows:
120 | ```
121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname'
122 | npm start
123 | ```
124 |
125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`.
126 |
127 | ## Adding Flow
128 |
129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept.
130 |
131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native.
132 |
133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps:
134 |
135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig)
136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number.
137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`.
138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`).
139 |
140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors.
141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience.
142 |
143 | To learn more about Flow, check out [its documentation](https://flow.org/).
144 |
145 | ## Sharing and Deployment
146 |
147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service.
148 |
149 | ### Publishing to Expo's React Native Community
150 |
151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account.
152 |
153 | Install the `exp` command-line tool, and run the publish command:
154 |
155 | ```
156 | $ npm i -g exp
157 | $ exp publish
158 | ```
159 |
160 | ### Building an Expo "standalone" app
161 |
162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself.
163 |
164 | ### Ejecting from Create React Native App
165 |
166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio.
167 |
168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html).
169 |
170 | #### Should I Use ExpoKit?
171 |
172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option.
173 |
174 | ## Troubleshooting
175 |
176 | ### Networking
177 |
178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports.
179 |
180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see:
181 |
182 | ```
183 | exp://192.168.0.1:19000
184 | ```
185 |
186 | Try opening Safari or Chrome on your phone and loading
187 |
188 | ```
189 | http://192.168.0.1:19000
190 | ```
191 |
192 | and
193 |
194 | ```
195 | http://192.168.0.1:19001
196 | ```
197 |
198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received.
199 |
200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager.
201 |
202 | ### iOS Simulator won't open
203 |
204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`:
205 |
206 | * "non-zero exit code: 107"
207 | * "You may need to install Xcode" but it is already installed
208 | * and others
209 |
210 | There are a few steps you may want to take to troubleshoot these kinds of errors:
211 |
212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store.
213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so.
214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`.
215 |
216 | ### QR Code does not scan
217 |
218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses.
219 |
220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually.
221 |
--------------------------------------------------------------------------------
/examples/Cube/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "sdkVersion": "20.0.0"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/examples/Cube/assets/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/examples/Cube/assets/1.jpg
--------------------------------------------------------------------------------
/examples/Cube/assets/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/examples/Cube/assets/2.jpg
--------------------------------------------------------------------------------
/examples/Cube/assets/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/examples/Cube/assets/3.jpg
--------------------------------------------------------------------------------
/examples/Cube/assets/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/examples/Cube/assets/4.jpg
--------------------------------------------------------------------------------
/examples/Cube/assets/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/examples/Cube/assets/5.jpg
--------------------------------------------------------------------------------
/examples/Cube/assets/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/examples/Cube/assets/6.jpg
--------------------------------------------------------------------------------
/examples/Cube/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Cube",
3 | "version": "0.1.0",
4 | "private": true,
5 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
6 | "scripts": {
7 | "start": "react-native-scripts start",
8 | "eject": "react-native-scripts eject",
9 | "android": "react-native-scripts android",
10 | "ios": "react-native-scripts ios",
11 | "test": "node node_modules/jest/bin/jest.js --watch"
12 | },
13 | "jest": {
14 | "preset": "jest-expo"
15 | },
16 | "dependencies": {
17 | "expo": "^20.0.0",
18 | "react": "16.0.0-alpha.12",
19 | "react-native": "^0.47.0",
20 | "react-router-native": "^4.2.0",
21 | "react-router-native-stack": "file:../../"
22 | },
23 | "devDependencies": {
24 | "eslint": "^4.5.0",
25 | "eslint-config-expo": "^6.0.0",
26 | "jest-expo": "~20.0.0",
27 | "prettier": "^1.5.3",
28 | "react-native-scripts": "1.2.1",
29 | "react-test-renderer": "16.0.0-alpha.12"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/examples/Cube/styles.js:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | export default StyleSheet.create({
4 | container: {
5 | flex: 1,
6 | flexDirection: 'column',
7 | backgroundColor: 'white',
8 | },
9 | linkText: {
10 | color: 'blue',
11 | },
12 | backText: {
13 | color: 'red',
14 | },
15 | screen: {
16 | flex: 1,
17 | flexDirection: 'column',
18 | alignItems: 'center',
19 | justifyContent: 'space-around',
20 | },
21 | });
22 |
--------------------------------------------------------------------------------
/examples/SimpleStack/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["babel-preset-expo"],
3 | "env": {
4 | "development": {
5 | "plugins": ["transform-react-jsx-source"]
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/examples/SimpleStack/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore templates for 'react-native init'
6 | /node_modules/react-native/local-cli/templates/.*
7 |
8 | ; Ignore RN jest
9 | /node_modules/react-native/jest/.*
10 |
11 | ; Ignore RNTester
12 | /node_modules/react-native/RNTester/.*
13 |
14 | ; Ignore the website subdir
15 | /node_modules/react-native/website/.*
16 |
17 | ; Ignore the Dangerfile
18 | /node_modules/react-native/danger/dangerfile.js
19 |
20 | ; Ignore Fbemitter
21 | /node_modules/fbemitter/.*
22 |
23 | ; Ignore "BUCK" generated dirs
24 | /node_modules/react-native/\.buckd/
25 |
26 | ; Ignore unexpected extra "@providesModule"
27 | .*/node_modules/.*/node_modules/fbjs/.*
28 |
29 | ; Ignore polyfills
30 | /node_modules/react-native/Libraries/polyfills/.*
31 |
32 | ; Ignore various node_modules
33 | /node_modules/react-native-gesture-handler/.*
34 | /node_modules/expo/.*
35 | /node_modules/react-navigation/.*
36 | /node_modules/xdl/.*
37 | /node_modules/reqwest/.*
38 | /node_modules/metro-bundler/.*
39 |
40 | [include]
41 |
42 | [libs]
43 | node_modules/react-native/Libraries/react-native/react-native-interface.js
44 | node_modules/react-native/flow/
45 | node_modules/expo/flow/
46 |
47 | [options]
48 | emoji=true
49 |
50 | module.system=haste
51 |
52 | module.file_ext=.js
53 | module.file_ext=.jsx
54 | module.file_ext=.json
55 | module.file_ext=.ios.js
56 |
57 | munge_underscores=true
58 |
59 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
60 |
61 | suppress_type=$FlowIssue
62 | suppress_type=$FlowFixMe
63 | suppress_type=$FlowFixMeProps
64 | suppress_type=$FlowFixMeState
65 | suppress_type=$FixMe
66 |
67 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)
68 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+
69 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
70 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
71 |
72 | unsafe.enable_getters_and_setters=true
73 |
74 | [version]
75 | ^0.56.0
76 |
--------------------------------------------------------------------------------
/examples/SimpleStack/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # expo
4 | .expo/
5 |
6 | # dependencies
7 | /node_modules
8 |
9 | # misc
10 | .env.local
11 | .env.development.local
12 | .env.test.local
13 | .env.production.local
14 |
15 | npm-debug.log*
16 | yarn-debug.log*
17 | yarn-error.log*
18 |
--------------------------------------------------------------------------------
/examples/SimpleStack/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/examples/SimpleStack/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { NativeRouter, Route } from 'react-router-native';
3 | import Stack from 'react-router-native-stack';
4 | import Home from './Home';
5 | import Message from './Message';
6 | import Messages from './Messages';
7 |
8 | export default class App extends Component {
9 | render() {
10 | return (
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | );
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/examples/SimpleStack/Home.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {
3 | Container,
4 | Header,
5 | Left,
6 | Body,
7 | Right,
8 | Title,
9 | Content,
10 | Button,
11 | Icon,
12 | Text,
13 | } from 'native-base';
14 | import { Link } from 'react-router-native';
15 |
16 | export default function Home() {
17 | return (
18 |
19 |
20 |
21 |
22 |
23 | Home
24 |
25 |
26 |
27 |
28 |
29 |
30 | (
33 |
34 | View Messages
35 |
36 |
37 | )}
38 | />
39 |
40 |
41 | );
42 | }
43 |
--------------------------------------------------------------------------------
/examples/SimpleStack/Message.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {
3 | Container,
4 | Header,
5 | Left,
6 | Body,
7 | Right,
8 | Title,
9 | Content,
10 | Button,
11 | Icon,
12 | Card,
13 | CardItem,
14 | Text,
15 | } from 'native-base';
16 |
17 | export default function Message({ match, history }) {
18 | return (
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | Message
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | {match.params.messageId}
38 |
39 |
40 |
41 |
42 | );
43 | }
44 |
--------------------------------------------------------------------------------
/examples/SimpleStack/Messages.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {
3 | Container,
4 | Header,
5 | Left,
6 | Body,
7 | Right,
8 | Title,
9 | Content,
10 | Button,
11 | Icon,
12 | Text,
13 | List,
14 | ListItem,
15 | } from 'native-base';
16 | import { Link } from 'react-router-native';
17 |
18 | const messages = ['Hello', 'Lunch', 'Meeting'];
19 |
20 | export default function Messages({ history }) {
21 | return (
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | Messages
32 |
33 |
34 |
35 |
36 |
37 |
38 | (
41 | (
45 |
46 |
47 | {message}
48 |
49 |
50 |
51 |
52 |
53 | )}
54 | />
55 | )}
56 | />
57 |
58 |
59 | );
60 | }
61 |
--------------------------------------------------------------------------------
/examples/SimpleStack/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app).
2 |
3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md).
4 |
5 | ## Table of Contents
6 |
7 | * [Updating to New Releases](#updating-to-new-releases)
8 | * [Available Scripts](#available-scripts)
9 | * [npm start](#npm-start)
10 | * [npm test](#npm-test)
11 | * [npm run ios](#npm-run-ios)
12 | * [npm run android](#npm-run-android)
13 | * [npm run eject](#npm-run-eject)
14 | * [Writing and Running Tests](#writing-and-running-tests)
15 | * [Environment Variables](#environment-variables)
16 | * [Configuring Packager IP Address](#configuring-packager-ip-address)
17 | * [Adding Flow](#adding-flow)
18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon)
19 | * [Sharing and Deployment](#sharing-and-deployment)
20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community)
21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app)
22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app)
23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio)
24 | * [Should I Use ExpoKit?](#should-i-use-expokit)
25 | * [Troubleshooting](#troubleshooting)
26 | * [Networking](#networking)
27 | * [iOS Simulator won't open](#ios-simulator-wont-open)
28 | * [QR Code does not scan](#qr-code-does-not-scan)
29 |
30 | ## Updating to New Releases
31 |
32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never.
33 |
34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies.
35 |
36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility.
37 |
38 | ## Available Scripts
39 |
40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.
41 |
42 | ### `npm start`
43 |
44 | Runs your app in development mode.
45 |
46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal.
47 |
48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script:
49 |
50 | ```
51 | npm start -- --reset-cache
52 | # or
53 | yarn start -- --reset-cache
54 | ```
55 |
56 | #### `npm test`
57 |
58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests.
59 |
60 | #### `npm run ios`
61 |
62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.
63 |
64 | #### `npm run android`
65 |
66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App:
67 |
68 | ##### Using Android Studio's `adb`
69 |
70 | 1. Make sure that you can run adb from your terminal.
71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location).
72 |
73 | ##### Using Genymotion's `adb`
74 |
75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`.
76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)).
77 | 3. Make sure that you can run adb from your terminal.
78 |
79 | #### `npm run eject`
80 |
81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project.
82 |
83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up.
84 |
85 | ## Customizing App Display Name and Icon
86 |
87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key.
88 |
89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string.
90 |
91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency.
92 |
93 | ## Writing and Running Tests
94 |
95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html).
96 |
97 | ## Environment Variables
98 |
99 | You can configure some of Create React Native App's behavior using environment variables.
100 |
101 | ### Configuring Packager IP Address
102 |
103 | When starting your project, you'll see something like this for your project URL:
104 |
105 | ```
106 | exp://192.168.0.2:19000
107 | ```
108 |
109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides.
110 |
111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable:
112 |
113 | Mac and Linux:
114 |
115 | ```
116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start
117 | ```
118 |
119 | Windows:
120 | ```
121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname'
122 | npm start
123 | ```
124 |
125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`.
126 |
127 | ## Adding Flow
128 |
129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept.
130 |
131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native.
132 |
133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps:
134 |
135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig)
136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number.
137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`.
138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`).
139 |
140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors.
141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience.
142 |
143 | To learn more about Flow, check out [its documentation](https://flow.org/).
144 |
145 | ## Sharing and Deployment
146 |
147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service.
148 |
149 | ### Publishing to Expo's React Native Community
150 |
151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account.
152 |
153 | Install the `exp` command-line tool, and run the publish command:
154 |
155 | ```
156 | $ npm i -g exp
157 | $ exp publish
158 | ```
159 |
160 | ### Building an Expo "standalone" app
161 |
162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself.
163 |
164 | ### Ejecting from Create React Native App
165 |
166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio.
167 |
168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html).
169 |
170 | #### Should I Use ExpoKit?
171 |
172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option.
173 |
174 | ## Troubleshooting
175 |
176 | ### Networking
177 |
178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports.
179 |
180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see:
181 |
182 | ```
183 | exp://192.168.0.1:19000
184 | ```
185 |
186 | Try opening Safari or Chrome on your phone and loading
187 |
188 | ```
189 | http://192.168.0.1:19000
190 | ```
191 |
192 | and
193 |
194 | ```
195 | http://192.168.0.1:19001
196 | ```
197 |
198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received.
199 |
200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager.
201 |
202 | ### iOS Simulator won't open
203 |
204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`:
205 |
206 | * "non-zero exit code: 107"
207 | * "You may need to install Xcode" but it is already installed
208 | * and others
209 |
210 | There are a few steps you may want to take to troubleshoot these kinds of errors:
211 |
212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store.
213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so.
214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`.
215 |
216 | ### QR Code does not scan
217 |
218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses.
219 |
220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually.
221 |
--------------------------------------------------------------------------------
/examples/SimpleStack/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "sdkVersion": "25.0.0"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/examples/SimpleStack/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "SimpleStack",
3 | "version": "0.1.0",
4 | "private": true,
5 | "devDependencies": {
6 | "react-native-scripts": "1.11.1",
7 | "jest-expo": "25.0.0",
8 | "react-test-renderer": "16.2.0"
9 | },
10 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
11 | "scripts": {
12 | "start": "react-native-scripts start",
13 | "eject": "react-native-scripts eject",
14 | "android": "react-native-scripts android",
15 | "ios": "react-native-scripts ios",
16 | "test": "node node_modules/jest/bin/jest.js"
17 | },
18 | "jest": {
19 | "preset": "jest-expo"
20 | },
21 | "dependencies": {
22 | "expo": "^25.0.0",
23 | "native-base": "^2.3.7",
24 | "react": "16.2.0",
25 | "react-native": "0.52.0",
26 | "react-router-native": "^4.2.0",
27 | "react-router-native-stack": "file:../../"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/SimpleStack/styles.js:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | export default StyleSheet.create({
4 | container: {
5 | flex: 1,
6 | flexDirection: 'column',
7 | backgroundColor: 'white',
8 | },
9 | linkText: {
10 | color: 'blue',
11 | },
12 | backText: {
13 | color: 'red',
14 | },
15 | screen: {
16 | flex: 1,
17 | flexDirection: 'column',
18 | alignItems: 'center',
19 | justifyContent: 'space-around',
20 | },
21 | });
22 |
--------------------------------------------------------------------------------
/examples/Usage/.expo/packager-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "expoServerPort": null,
3 | "packagerPort": null,
4 | "packagerPid": null
5 | }
--------------------------------------------------------------------------------
/examples/Usage/.expo/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "hostType": "tunnel",
3 | "lanType": "ip",
4 | "dev": true,
5 | "strict": false,
6 | "minify": false,
7 | "urlType": "exp",
8 | "urlRandomness": null
9 | }
--------------------------------------------------------------------------------
/examples/Usage/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Button, StyleSheet, Text, View } from 'react-native';
3 | import { NativeRouter, Route } from 'react-router-native';
4 | import Stack from 'react-router-native-stack';
5 |
6 | function Home({ history }) {
7 | return (
8 |
9 | Home Page
10 |
11 | history.push('/page/pizza')} />
12 |
13 | history.push('/page/taco')} />
14 |
15 | history.push('/page/hamburger')} />
16 |
17 | );
18 | }
19 |
20 | function Page({ match, history }) {
21 | return (
22 |
23 | You're on a {match.params.name} Page!
24 |
25 | history.goBack()} />
26 |
27 | history.push('/page/pizza')} />
28 |
29 | history.push('/page/taco')} />
30 |
31 | history.push('/page/hamburger')} />
32 |
33 | );
34 | }
35 |
36 | export default class App extends Component {
37 | render() {
38 | return (
39 |
40 |
41 |
42 |
43 |
44 |
45 | );
46 | }
47 | }
48 |
49 | const styles = StyleSheet.create({
50 | screen: {
51 | flex: 1,
52 | flexDirection: 'column',
53 | alignItems: 'center',
54 | justifyContent: 'space-around',
55 | },
56 | });
57 |
--------------------------------------------------------------------------------
/examples/Usage/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import App from './App';
3 |
4 | import renderer from 'react-test-renderer';
5 |
6 | it('renders without crashing', () => {
7 | const rendered = renderer.create().toJSON();
8 | expect(rendered).toBeTruthy();
9 | });
10 |
--------------------------------------------------------------------------------
/examples/Usage/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "sdkVersion": "20.0.0"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/examples/Usage/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Usage",
3 | "version": "0.1.0",
4 | "private": true,
5 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
6 | "scripts": {
7 | "start": "react-native-scripts start",
8 | "eject": "react-native-scripts eject",
9 | "android": "react-native-scripts android",
10 | "ios": "react-native-scripts ios",
11 | "test": "node node_modules/jest/bin/jest.js --watch"
12 | },
13 | "jest": {
14 | "preset": "jest-expo"
15 | },
16 | "dependencies": {
17 | "expo": "^20.0.0",
18 | "react": "16.0.0-alpha.12",
19 | "react-native": "^0.47.0",
20 | "react-router-native": "^4.2.0",
21 | "react-router-native-stack": "file:../../"
22 | },
23 | "devDependencies": {
24 | "eslint": "^4.5.0",
25 | "eslint-config-expo": "^6.0.0",
26 | "jest-expo": "~20.0.0",
27 | "prettier": "^1.5.3",
28 | "react-native-scripts": "1.2.1",
29 | "react-test-renderer": "16.0.0-alpha.12"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/Stack.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Platform, View, ViewPropTypes } from 'react-native';
3 | import { node, object, bool, string, func, oneOf } from 'prop-types';
4 | import { withRouter } from 'react-router-native';
5 | import StackTransitioner from './StackTransitioner';
6 | import { PUSH, POP } from './transitionTypes';
7 | import { SLIDE_HORIZONTAL, FADE_VERTICAL } from './animationTypes';
8 | import styles from './styles';
9 |
10 | class Stack extends Component {
11 | static propTypes = {
12 | children: node,
13 | history: object,
14 | location: object,
15 | renderHeader: func,
16 | renderTitle: func,
17 | renderLeftSegment: func,
18 | renderRightSegment: func,
19 | animationType: string,
20 | gestureEnabled: bool,
21 | stackViewStyle: ViewPropTypes.style,
22 | replaceTransitionType: oneOf([PUSH, POP]),
23 | isAnimating: func,
24 | };
25 |
26 | static defaultProps = {
27 | animationType: Platform.OS === 'ios' ? SLIDE_HORIZONTAL : FADE_VERTICAL,
28 | gestureEnabled: true,
29 | isAnimating: () => null,
30 | };
31 |
32 | state = {
33 | width: 0,
34 | height: 0,
35 | };
36 |
37 | onLayout = event => {
38 | const { height, width } = event.nativeEvent.layout;
39 | this.setState({ height, width });
40 | };
41 |
42 | render() {
43 | const {
44 | children,
45 | history,
46 | location,
47 | renderHeader,
48 | renderTitle,
49 | renderLeftSegment,
50 | renderRightSegment,
51 | animationType,
52 | gestureEnabled,
53 | stackViewStyle,
54 | replaceTransitionType,
55 | isAnimating,
56 | } = this.props;
57 |
58 | const { height, width } = this.state;
59 |
60 | return (
61 |
62 |
78 |
79 | );
80 | }
81 | }
82 |
83 | export default withRouter(Stack);
84 |
--------------------------------------------------------------------------------
/lib/StackTransitioner.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { node, object, number, bool, string, oneOf, func } from 'prop-types';
3 | import { Animated, PanResponder, View, ViewPropTypes } from 'react-native';
4 | import findFirstMatch from './findFirstMatch';
5 | import getTransforms from './getTransforms';
6 | import getEasing from './getEasing';
7 | import getDuration from './getDuration';
8 | import getDimension from './getDimension';
9 | import { PUSH, POP, REPLACE } from './transitionTypes';
10 | import { NONE } from './animationTypes';
11 | import styles from './styles';
12 |
13 | const ANIMATION_DURATION = 500;
14 | const POSITION_THRESHOLD = 1 / 2;
15 | const RESPOND_THRESHOLD = 1;
16 | const GESTURE_RESPONSE_DISTANCE_HORIZONTAL = 40;
17 |
18 | export default class StackTransitioner extends Component {
19 | static propTypes = {
20 | children: node,
21 | history: object.isRequired,
22 | location: object.isRequired,
23 | width: number.isRequired,
24 | height: number.isRequired,
25 | animationType: string.isRequired,
26 | gestureEnabled: bool,
27 | stackViewStyle: ViewPropTypes.style,
28 | replaceTransitionType: oneOf([PUSH, POP]),
29 | isAnimating: func
30 | };
31 |
32 | state = {
33 | previousLocation: {},
34 | transition: null,
35 | routeAnimationType: null,
36 | children: findFirstMatch(this.props.children, this.props.location),
37 | previousChildren: null,
38 | };
39 |
40 | startingIndex = this.props.history.index;
41 |
42 | animation = null;
43 |
44 | animatedValue = new Animated.Value(0);
45 |
46 | isPanning = false;
47 |
48 | isHorizontal = animationType =>
49 | animationType.indexOf('horizontal') > -1 || animationType === 'cube';
50 |
51 | panResponder = PanResponder.create({
52 | onMoveShouldSetPanResponder: (event, gesture) => {
53 | return (
54 | !this.state.transition &&
55 | this.isHorizontal(this.state.routeAnimationType || this.props.animationType) &&
56 | this.props.gestureEnabled &&
57 | this.props.history.index > this.startingIndex &&
58 | this.props.history.canGo(-1) &&
59 | event.nativeEvent.pageX < GESTURE_RESPONSE_DISTANCE_HORIZONTAL &&
60 | gesture.dx > RESPOND_THRESHOLD
61 | );
62 | },
63 |
64 | onPanResponderGrant: (event, { moveX }) => {
65 | this.isPanning = true;
66 | this.props.history.goBack();
67 | },
68 |
69 | onPanResponderMove: (event, { moveX }) => {
70 | this.animatedValue.setValue(moveX);
71 | },
72 |
73 | onPanResponderRelease: (event, { dx, vx }) => {
74 | const defaultVelocity = this.getDimension() / ANIMATION_DURATION;
75 | const velocity = Math.max(Math.abs(vx), defaultVelocity);
76 | const resetDuration = dx / velocity;
77 | const goBackDuration = (this.getDimension() - dx) / velocity;
78 |
79 | // first check velocity to decide whether to cancel or not
80 | if (vx < -0.5) {
81 | this.cancelNavigation(resetDuration);
82 | return;
83 | } else if (vx > 0.5) {
84 | this.finishNavigation(goBackDuration);
85 | return;
86 | }
87 |
88 | // next use position to decide whether to cancel or not
89 | if (dx / this.getDimension() < POSITION_THRESHOLD) {
90 | this.cancelNavigation(resetDuration);
91 | } else {
92 | this.finishNavigation(goBackDuration);
93 | }
94 | },
95 | });
96 |
97 | cancelNavigation = duration => {
98 | this.animation = Animated.timing(this.animatedValue, {
99 | toValue: 0,
100 | duration,
101 | useNativeDriver: true,
102 | }).start(({ finished }) => {
103 | if (finished) {
104 | this.props.history.push(this.state.previousLocation);
105 | this.afterPan();
106 | }
107 | });
108 | };
109 |
110 | finishNavigation = duration => {
111 | Animated.timing(this.animatedValue, {
112 | toValue: this.getDimension(),
113 | duration,
114 | useNativeDriver: true,
115 | }).start(({ finished }) => {
116 | if (finished) {
117 | this.afterPan();
118 | }
119 | });
120 | };
121 |
122 | afterPan = () => {
123 | this.props.isAnimating(false);
124 | this.isPanning = false;
125 |
126 | this.setState({
127 | previousLocation: {},
128 | transition: null,
129 | });
130 |
131 | if (this.props.history.action === POP) {
132 | this.setState({
133 | routeAnimationType: this.state.children.props.animationType,
134 | });
135 | }
136 |
137 | this.animatedValue = new Animated.Value(0);
138 | this.animation = null;
139 | };
140 |
141 | componentWillReceiveProps(nextProps) {
142 | const { history } = nextProps;
143 | const { location } = this.props;
144 |
145 | if (nextProps.location.key === location.key || !!this.state.transition) {
146 | return;
147 | }
148 |
149 | let action = history.action
150 |
151 | if (action === REPLACE && this.props.replaceTransitionType) {
152 | action = this.props.replaceTransitionType
153 | }
154 |
155 | const [children, previousChildren] = this.getChildren(nextProps.location, location);
156 | const routeAnimationType =
157 | action === PUSH ? (children && children.props.animationType) : (previousChildren && previousChildren.props.animationType)
158 |
159 | this.setState({
160 | previousLocation: location,
161 | routeAnimationType,
162 | children,
163 | previousChildren,
164 | });
165 |
166 | if (
167 | this.isPanning ||
168 | (routeAnimationType === NONE || (nextProps.animationType === NONE && !routeAnimationType)) ||
169 | (action === POP && history.index < this.startingIndex) ||
170 | (children && previousChildren && children.key === previousChildren.key)
171 | ) {
172 | return;
173 | }
174 |
175 | if (action === PUSH || action === POP) {
176 | this.setState(
177 | {
178 | transition: action,
179 | },
180 | () => {
181 | // TODO: base slide direction on `I18nManager.isRTL`
182 | const dimension = this.getDimension();
183 |
184 | this.props.isAnimating(true);
185 |
186 | this.animation = Animated.timing(this.animatedValue, {
187 | duration: getDuration(routeAnimationType || nextProps.animationType, action),
188 | toValue: action === PUSH ? -dimension : dimension,
189 | easing: getEasing(routeAnimationType || nextProps.animationType),
190 | useNativeDriver: true,
191 | }).start(({ finished }) => {
192 | if (finished) {
193 | this.props.isAnimating(false);
194 |
195 | this.setState({
196 | previousLocation: {},
197 | transition: null,
198 | });
199 |
200 | if (action === POP) {
201 | this.setState({
202 | routeAnimationType: children.props.animationType,
203 | });
204 | }
205 |
206 | this.animatedValue = new Animated.Value(0);
207 | this.animation = null;
208 | }
209 | });
210 | }
211 | );
212 | }
213 | }
214 |
215 | componentWillUnmount() {
216 | this.animation && this.animation.stop();
217 | }
218 |
219 | getChildren = (currentLocation, previousLocation) => {
220 | const { children } = this.props;
221 |
222 | const currentChild = findFirstMatch(children, currentLocation);
223 |
224 | if (!previousLocation) {
225 | return [currentChild];
226 | }
227 |
228 | const previousChild = findFirstMatch(children, previousLocation);
229 |
230 | return [currentChild, previousChild];
231 | };
232 |
233 | getDimension = () => {
234 | return getDimension(
235 | this.state.routeAnimationType || this.props.animationType,
236 | this.props.width,
237 | this.props.height
238 | );
239 | };
240 |
241 | getRouteStyle = index => {
242 | const { animationType, width, height, stackViewStyle } = this.props;
243 | const { routeAnimationType, transition } = this.state;
244 | const { animatedValue, isPanning } = this;
245 | const transitionType = isPanning ? POP : transition;
246 |
247 | return [
248 | styles.stackView,
249 | stackViewStyle,
250 | getTransforms(
251 | width,
252 | height,
253 | animatedValue,
254 | routeAnimationType || animationType,
255 | transitionType,
256 | index
257 | ),
258 | ];
259 | };
260 |
261 | isFixed(element) {
262 | const { children, previousChildren } = this.state;
263 | if (!children.props[`${element}Component`]) return false; // current route has no headerComponent or footerComponent
264 | if (!previousChildren) return true; // inital app render
265 | return children.props[`${element}Component`] === previousChildren.props[`${element}Component`]; // both routes have same fixed headerComponent or footerComponent
266 | }
267 |
268 | render() {
269 | const { stackViewStyle } = this.props;
270 | const { children, previousChildren, transition } = this.state;
271 | const Header = children.props.headerComponent;
272 | const Footer = children.props.footerComponent;
273 | const PreviousHeader = previousChildren && previousChildren.props.headerComponent;
274 | const PreviousFooter = previousChildren && previousChildren.props.footerComponent;
275 |
276 | let routes = [];
277 | if (transition === PUSH) {
278 | previousChildren && routes.push(
279 |
280 | {(!this.isFixed("footer") && PreviousFooter) && }
281 | {previousChildren}
282 | {(!this.isFixed("header") && PreviousHeader) && }
283 |
284 | );
285 | children && routes.push(
286 |
287 | {(!this.isFixed("footer") && Footer) && }
288 | {children}
289 | {(!this.isFixed("header") && Header) && }
290 |
291 | );
292 | } else if (transition === POP || this.isPanning) {
293 | children && routes.push(
294 |
295 | {(!this.isFixed("footer") && Footer) && }
296 | {children}
297 | {(!this.isFixed("header") && Header) && }
298 |
299 | );
300 | previousChildren && routes.push(
301 |
302 | {(!this.isFixed("footer") && PreviousFooter) && }
303 | {previousChildren}
304 | {(!this.isFixed("header") && PreviousHeader) && }
305 |
306 | );
307 | } else {
308 | children && routes.push(
309 |
310 | {(!this.isFixed("footer") && Footer) && }
311 | {children}
312 | {(!this.isFixed("header") && Header) && }
313 |
314 | );
315 | }
316 |
317 | return (
318 |
319 | { this.isFixed("footer") && }
320 |
321 | {routes.map(route => route)}
322 |
323 | { this.isFixed("header") && }
324 |
325 | );
326 | }
327 | }
328 |
--------------------------------------------------------------------------------
/lib/animationTypes.js:
--------------------------------------------------------------------------------
1 | export const SLIDE_HORIZONTAL = 'slide-horizontal';
2 | export const SLIDE_VERTICAL = 'slide-vertical';
3 | export const FADE_VERTICAL = 'fade-vertical';
4 | export const FADE_HORIZONTAL = 'fade-horizontal';
5 | export const CUBE = 'cube';
6 | export const NONE = 'none';
7 |
--------------------------------------------------------------------------------
/lib/findFirstMatch.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { matchPath } from 'react-router-native';
3 |
4 | // See https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/Switch.js
5 | // for the reference implementation
6 | export default function findFirstMatch(children, location) {
7 | let match, child;
8 | React.Children.forEach(children, element => {
9 | if (!React.isValidElement(element)) return;
10 |
11 | const { path: pathProp, exact, strict, sensitive, from } = element.props;
12 | const path = pathProp || from;
13 |
14 | if (match == null) {
15 | child = element;
16 | match = path == null ? {} : matchPath(location.pathname, { path, exact, strict, sensitive });
17 | }
18 | });
19 |
20 | return match ? React.cloneElement(child, { location, computedMatch: match, key: child.key || location.key }) : null;
21 | }
22 |
--------------------------------------------------------------------------------
/lib/getDimension.js:
--------------------------------------------------------------------------------
1 | import {
2 | SLIDE_HORIZONTAL,
3 | SLIDE_VERTICAL,
4 | FADE_HORIZONTAL,
5 | FADE_VERTICAL,
6 | CUBE,
7 | NONE,
8 | } from './animationTypes';
9 |
10 | export default function getDimension(animationType, width, height) {
11 | switch (animationType) {
12 | case SLIDE_HORIZONTAL:
13 | case FADE_HORIZONTAL:
14 | case CUBE:
15 | return width;
16 | case SLIDE_VERTICAL:
17 | case FADE_VERTICAL:
18 | return height;
19 | case NONE:
20 | return 0;
21 | default:
22 | console.error('UNKNOWN ANIMATION TYPE: ', animationType);
23 | return 0;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lib/getDuration.js:
--------------------------------------------------------------------------------
1 | import { FADE_VERTICAL } from './animationTypes';
2 |
3 | export default function getTiming(animationType, transitionType) {
4 | switch (animationType) {
5 | case FADE_VERTICAL:
6 | if (transitionType === 'PUSH') {
7 | return 230;
8 | }
9 | return 350;
10 | default:
11 | return 500;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lib/getEasing.js:
--------------------------------------------------------------------------------
1 | import { Easing } from 'react-native';
2 | import { SLIDE_HORIZONTAL, SLIDE_VERTICAL, FADE_VERTICAL, CUBE } from './animationTypes';
3 |
4 | export default function getEasing(animationType) {
5 | switch (animationType) {
6 | case SLIDE_HORIZONTAL:
7 | case SLIDE_VERTICAL:
8 | return Easing.bezier(0.2833, 0.99, 0.31833, 0.99);
9 | case FADE_VERTICAL:
10 | return Easing.in(Easing.poly(4));
11 | case CUBE:
12 | default:
13 | return Easing.inOut(Easing.ease);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lib/getTransforms.js:
--------------------------------------------------------------------------------
1 | import { PUSH, POP } from './transitionTypes';
2 | import { SLIDE_HORIZONTAL, SLIDE_VERTICAL, FADE_VERTICAL, CUBE } from './animationTypes';
3 |
4 | export default function getTransforms(
5 | width,
6 | height,
7 | animation,
8 | animationType,
9 | transitionType,
10 | screenIndex
11 | ) {
12 | if (animationType === SLIDE_HORIZONTAL) {
13 | const baseStyle = {
14 | elevation: 1,
15 | transform: [{ translateX: animation }],
16 | };
17 |
18 | if (transitionType === PUSH && screenIndex === 1) {
19 | return {
20 | left: width,
21 | right: -width,
22 | ...baseStyle,
23 | };
24 | } else if (transitionType === POP && screenIndex === 1) {
25 | return baseStyle;
26 | }
27 |
28 | return null;
29 | }
30 |
31 | if (animationType === SLIDE_VERTICAL) {
32 | const baseStyle = {
33 | elevation: 1,
34 | transform: [{ translateY: animation }],
35 | };
36 | if (transitionType === PUSH && screenIndex === 1) {
37 | return {
38 | top: height,
39 | bottom: -height,
40 | ...baseStyle,
41 | };
42 | } else if (transitionType === POP && screenIndex === 1) {
43 | return baseStyle;
44 | }
45 |
46 | return null;
47 | }
48 |
49 | if (animationType === FADE_VERTICAL) {
50 | const inputRange = [-height, 0, height];
51 | const baseStyle = {
52 | transform: [
53 | {
54 | translateY: animation.interpolate({
55 | inputRange: [-height, 0, height],
56 | outputRange: [-(height / 3), 0, height / 3],
57 | }),
58 | },
59 | ],
60 | };
61 |
62 | if (transitionType === PUSH && screenIndex === 1) {
63 | return {
64 | top: height / 3,
65 | bottom: -height / 3,
66 | opacity: animation.interpolate({
67 | inputRange,
68 | outputRange: [1, 0, 1],
69 | }),
70 | ...baseStyle,
71 | };
72 | } else if (transitionType === POP && screenIndex === 1) {
73 | return {
74 | opacity: animation.interpolate({
75 | inputRange,
76 | outputRange: [0, 1, 0],
77 | }),
78 | ...baseStyle,
79 | };
80 | }
81 |
82 | return null;
83 | }
84 |
85 | if (animationType === CUBE) {
86 | const extraStyling = {};
87 | let screenPosition = 0;
88 |
89 | if (transitionType === PUSH && screenIndex === 1) {
90 | screenPosition = -width;
91 | extraStyling.elevation = 1;
92 | } else if (transitionType === POP && screenIndex === 0) {
93 | screenPosition = width;
94 | extraStyling.elevation = 1;
95 | }
96 |
97 | const translateX = animation.interpolate({
98 | inputRange: [screenPosition - width, screenPosition, screenPosition + width],
99 | outputRange: [-width / 2, 0, width / 2],
100 | });
101 |
102 | const rotateY = animation.interpolate({
103 | inputRange: [screenPosition - width, screenPosition, screenPosition + width],
104 | outputRange: ['-60deg', '0deg', '60deg'],
105 | });
106 |
107 | const translateXAfterRotate = animation.interpolate({
108 | inputRange: [
109 | screenPosition - width,
110 | screenPosition - width + 0.1,
111 | screenPosition,
112 | screenPosition + width - 0.1,
113 | screenPosition + width,
114 | ],
115 | outputRange: [-width, -width / 2.38, 0, width / 2.38, width],
116 | });
117 |
118 | return {
119 | transform: [
120 | { perspective: width },
121 | { translateX },
122 | { rotateY },
123 | { translateX: translateXAfterRotate },
124 | ],
125 | ...extraStyling,
126 | };
127 | }
128 |
129 | return null;
130 | }
131 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | export { default } from './Stack';
2 | export * from './animationTypes';
3 |
--------------------------------------------------------------------------------
/lib/styles.js:
--------------------------------------------------------------------------------
1 | import { Platform, StyleSheet } from 'react-native';
2 |
3 | const HEADER_HEIGHT = Platform.OS === 'ios' ? 44 : 56;
4 | const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : 0;
5 |
6 | export default StyleSheet.create({
7 | stackContainer: {
8 | flex: 1,
9 | position: 'absolute',
10 | top: 0,
11 | right: 0,
12 | bottom: 0,
13 | left: 0,
14 | },
15 | stackView: {
16 | position: 'absolute',
17 | flexDirection: 'column-reverse',
18 | left: 0,
19 | right: 0,
20 | bottom: 0,
21 | top: 0,
22 | backgroundColor: 'white',
23 | shadowColor: 'black',
24 | shadowOpacity: 0.2,
25 | shadowOffset: { width: 0, height: 0 },
26 | shadowRadius: 5,
27 | },
28 | transitionContainer: {
29 | flex: 1,
30 | },
31 | header: {
32 | flexDirection: 'row',
33 | alignItems: 'center',
34 | justifyContent: 'space-between',
35 | top: 0,
36 | left: 0,
37 | right: 0,
38 | height: HEADER_HEIGHT + STATUSBAR_HEIGHT,
39 | paddingTop: STATUSBAR_HEIGHT,
40 | backgroundColor: '#F7F7F7',
41 | borderBottomWidth: StyleSheet.hairlineWidth,
42 | borderBottomColor: 'rgba(0, 0, 0, .3)',
43 | },
44 | animatingHeader: {
45 | position: 'absolute',
46 | top: 0,
47 | elevation: 4,
48 | },
49 | left: {
50 | flex: 1,
51 | alignSelf: 'center',
52 | alignItems: 'flex-start',
53 | marginLeft: 10,
54 | },
55 | title: {
56 | flex: 2,
57 | alignItems: 'center',
58 | },
59 | right: {
60 | flex: 1,
61 | alignSelf: 'center',
62 | alignItems: 'flex-end',
63 | marginRight: 10,
64 | },
65 | });
66 |
--------------------------------------------------------------------------------
/lib/transitionTypes.js:
--------------------------------------------------------------------------------
1 | export const PUSH = 'PUSH';
2 | export const POP = 'POP';
3 | export const REPLACE = 'REPLACE';
4 |
--------------------------------------------------------------------------------
/media/cube-ios.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/cube-ios.gif
--------------------------------------------------------------------------------
/media/different-header.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/different-header.gif
--------------------------------------------------------------------------------
/media/fade-vertical-android.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/fade-vertical-android.gif
--------------------------------------------------------------------------------
/media/fixed-header.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/fixed-header.gif
--------------------------------------------------------------------------------
/media/no-header.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/no-header.gif
--------------------------------------------------------------------------------
/media/per-route-animation-type-ios.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/per-route-animation-type-ios.gif
--------------------------------------------------------------------------------
/media/simple-stack-ios.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/simple-stack-ios.gif
--------------------------------------------------------------------------------
/media/slide-vertical-ios.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/slide-vertical-ios.gif
--------------------------------------------------------------------------------
/media/usage-ios.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Traviskn/react-router-native-stack/cd671006b44a8609a1d8f6b18f3338d13b447a31/media/usage-ios.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-router-native-stack",
3 | "version": "0.0.16",
4 | "description": "A stack navigation component for react-router-native",
5 | "main": "lib/index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/Traviskn/react-router-native-stack.git"
12 | },
13 | "files": [
14 | "lib/"
15 | ],
16 | "keywords": [
17 | "react",
18 | "router",
19 | "navigation",
20 | "react-router",
21 | "react-native"
22 | ],
23 | "author": "Travis Nuttall",
24 | "license": "MIT",
25 | "bugs": {
26 | "url": "https://github.com/Traviskn/react-router-native-stack/issues"
27 | },
28 | "homepage": "https://github.com/Traviskn/react-router-native-stack#readme",
29 | "peerDependencies": {
30 | "prop-types": "^15.5.10",
31 | "react": ">=15",
32 | "react-native": ">=0.44",
33 | "react-router-native": ">=4.1.0"
34 | },
35 | "devDependencies": {
36 | "eslint": "^4.4.1",
37 | "eslint-config-expo": "^6.0.0-rc.3",
38 | "prettier": "^1.5.3"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------