39 Commits

Author SHA1 Message Date
Ashoat Tevosyan
d1c434b54c Update to react-native@0.49 and flow-bin@0.53 (#2845)
* Update root package to react-native@0.49 and flow-bin@0.53

* Update NavigationPlayground package to react-native@0.49 and flow-bin@0.53

* Update ReduxExample package to react-native@0.49 and flow-bin@0.53

* flow-typed update (code-gen)

* Find-and-replace old types with new types

- `React.Element<*>` as the result of a render function is now `React.Node`
- `ReactClass<T>` as the type of a Component is now `React.ComponentType<typeof T>`
- `extends React.Component<DP, P, S>` is now `extends React.Component<P, S>`
- `React.Children<*>` as the type of a children prop is now `React.ChildrenArray<*>`
- Refs are now typed with `React.Ref`

There are also several tiny typo fixes in here.

* Avoid assuming state is NavigationRoute in addNavigationHelpers

For the root, top-level Navigator, the state is a simple `NavigationState` (with no route info) and we still use `addNavigationHelpers` for it. We can't assume `navigation.state.key` is accessible for this type, so we need to do runtime checks here.

* Fix type of NavigationScreenConfig

`navigationOptions` was incorrectly typed

* Give createNavigationContainer's State a type parameter

We want to be able to specifically type this guy so we can use specific NavigationState for things like the Drawer views without having to do runtime assertions about the state type

* Fix typing of NavigationAction

First of all, `NavigationAction` was being used as two different types, so I had to create the new `PossiblyDeprecatedNavigationAction` and add it as a type parameter everywhere. Second of all, generics and implied types were being used far more than they need to be, and they're hard to work with because Flow doesn't really explain things well when they go wrong.

* Make sure children scenes of CardStack have NavigationProp typed with NavigationRoute

CardStack's `NavigationScreenProp` is typed with `NavigationState`, but the children need `NavigationRoute`. Flow gets confused by the spread operator, even if the individual property is replaced later, so we need to explicitly list each property individually (just `dispatch`, actually).

* Allow prevTransitionProps parameter to be nullable

* Allow prevTransitionProps parameter to be nullable

* Narrow down a couple type parameters

* Move NavigationStateRoute cast to within Component.router check in createConfigGetter

* Update withCachedChildNavigation so it's typed correctly with React.ComponentType

* Add a $FlowFixMe for displayName

`React.StatelessFunctionalComponent` is missing `displayName` before Flow 0.54.0

See de37062ea2

* Make TouchableItem's onPress prop optional

`HeaderBackButton` can pass in an undefined onPress, and the React Native `Touchable*` components allow it too

* Simplify withCachedChildNavigation and get rid of generics

The generics don't help us here and they make the types more confusing

* Redefine NavigationComponent as direct intersection

The new type is technically identical to the old type, but Flow is confused by the old type...

* Save router to local var before checking createConfigGetter

Flow seems to think Component.router can change after the check

* Fix DrawerSidebar's navigation prop's type

In order for us to be able to generate a childNavigationProp, the original navigation prop has to have a NavigationState state.

* Colocate action.key check with action.type check in getStateForAction

For some reason, Flow thinks `action` can change sometime after `action.type` is checked. As a result, it's not properly concluding that `action.key` should exist. To avoid this, we pull `action.key` out immediately after doing the `action.type` check.

* Use bounded polymorphism to pass down all props in withCachedChildNavigation

Also makes sure the injected props are specified first in the union

Also removes an unused `eslint-disable-line` in `getScreenForRouteName`

* Make TabRouter's getComponentForState return NavigationComponent

`NavigationScreenComponent` is a subtype of `NavigationComponent`, but it's not clear that `getComponentForState` always returns a `NavigationScreenComponent`, as `getScreenForRouteName` returns `NavigationComponent`

* Define NavigationComponent's props using NavigationNavigatorProps

Right now the types ask Flow to infer the types of `NavigationComponent`'s props. (`NavigationComponent` is the union of `NavigationNavigator` and NavigationScreenComponent.) Instead, we type the props as subtypes of `NavigationNavigatorProps`, so we can properly access those props without type errors. We used bounded polymorphism in `createNavigationContainer` and `createNavigator` to pass down these props. We also explicitly type the action in `createNavigationContainer` so we can properly pass in a `NavigationInitAction` to the dispatch function.

* Parameterize NavigationTabRouterConfig

`NavigationTabRouterConfig` doesn't always take `NavigationTabScreenOptions`; sometimes, it takes `NavigationDrawerScreenOptions`.

* Make all NavigationOptions Exact types

We're seeing weird behavior when these are merged together. By making them Exact types, we make types don't get mangled when they're unioned.

https://flow.org/en/docs/types/unions/#toc-disjoint-unions-with-exact-types

* Silence errors in tests

These errors are unavoidable since we can't type the precise shape of a particular `NavigationState`.

* Include NavigationSetParamsAction in NavigationTabAction

`TabNavigator`'s `getStateForAction` definitely takes `NavigationSetParamsAction`.

* Explicitly list router as void in NavigationScreenComponent

This is so Flow knows that if a `NavigationComponent` has a `router` property, then it is definitely a `NavigationNavigator`.

* Fix website app navigator's type

* Fix createDocPage type in App

In an earlier commit I attempted to fix the types here, but I incorrectly read it as returning a navigator when it just returns a screen. For some reason the error didn't immediately show up.

* Fix NavigationComponent types

Five changes:
1. No longer parameterizing the props of `NavigationComponent`; directly specifying as `NavigationNavigatorProps`
2. Specify the two distinct kinds of route types (leaf and state) directly in `NavigationComponent`
3. Have `SceneView` directly take `NavigationComponent` and allow inferring of `NavigationSceneProp` type
4. Have `CardStack` directly take `NavigationComponent` as well

* Allow Flow to infer `NavigationAction` type in `createNavigator`

* Silence Flow in router code that handles navigator sub-routes

There's no way for us to tell Flow that routes that correspond to navigators should be `NavigationStateRoute`s

* Allow DrawerSidebar to take a null contentComponent

The way `DrawerNavigator` is set up, it's possible to pass in a null `contentComponent` in the config.

If somebody want to do this, we'll just make the `DrawerSidebar` not appear altogether. This is simpler than splitting the types so there's a possibly-unspecified one for the user input, but a definitely-specified one in `DrawerSidebar`.

* Specify missing screenProps prop in DrawerView

* Thread full NavigationStateRoute in to DrawerSidebar

This requiring making `withCachedChildNavigation` use bounded polymorphism to thread the `NavigationStateRoute` through instead of downgrading it to a `NavigationState`

* Make NavigationStateProp's state prop covariant

This means that `NavigationStateProp<NavigationStateRoute>` will be a subtype of `NavigationStateProp<NavigationRoute>` and `NavigationStateProp<NavigationState>`

* Silence Flow's complaints about a route not being a NavigationStateRoute

As mentioned in previous commits and in the comment, there is no way to type a specific navigation state shape, so we have to cast it and silence Flow's complaints.

* Get rid of style prop in CardStack

It looks like at some point, it was possible to specify a `style` prop that got passed all the way down to `Header`, the `TransitionConfig`'s `screenInterpolator`, and `Transitioner`. Doesn't look like we're using it anywhere, and there's a todo saying to remove it, and it's causing a type error.

* Infer type of options instead of using a subtype of {}

I think this has to do with {} allowing for unsealed objects. I'm not 100% sure, but this fixes 4/6 of the remaining errors!

* Fix two type errors in NavigationPlayground

One was just requiring an outdated type (`React.Children` instead of `React.ChildrenArray`), and the other was getting confused regarding types because of a spread operator.

* Use a covariant property to simplify withCachedChildNavigation's InputProps

This doesn't reduce any errors, but it's a bit simpler and cleaner.

* Silence last two Flow errors regarding withCachedChildNavigation injecting childNavigationProps

These are the only two errors I haven't been able to figure out at all. If I had more time I'd try and figure out the simplest case and report it to the Flow team, but I've been working on this for a week already and have to move on.

The issue at hand is that `withCachedChildNavigation` injects `childNavigationProps`, but Flow doesn't see this and thinks it needs to be specified by the view component. We're using the HOC pattern suggested by the Flow docs, and I've tried several other patterns to no avail.

* Use stock react-native instead of Expo's in NavigationPlayground

Expo's causes Flow errors, and apparently this is normal practice because the person who switched us to Expo did this too.

* Silence react-native-gesture-handler Flow errors in NavigationPlayground

Expo requires this package, but it causes Flow errors.

* Fix index check in DrawerSidebar

Silly me, falling for the typical "0 is falsey" problem...

* Rework deprecated action tests

In an earlier commit I moved the `NavigationActions.mapDeprecatedActionAndWarn` out from `getStateForAction` and into `createNavigationContainer`'s `dispatch` function. The tests need to be reworked to support this, as they were previously calling `getStateForAction` directly. I don't imagine any users are calling `getStateForAction` directly.

* Re-record two snapshots

The changes in these snapshots are by design and don't affect anything.

* Infer type of options in NavigationScreenConfig

The issue is that sometimes we include options for different navigators in a single blob.

* Infer types of action and options in createNavigationContainer

Particulary helps with Options. Makes the types more specific and gets rid of an error that only shows up when using the library

* Don't use generics for NavigationState in createNavigationContainer

There's no particular reason for having those generics there, since there's no way we'd be able to get Flow to understand the exact shape of particular navigation states anyways. This fixes a bug when integrating this version of the project into my repo.

* Move ReduxExample to react-native@0.49.3 instead of custom Expo version
2017-10-31 09:41:17 -05:00
Spencer Carli
a8556b0df2 Improve StatusBar/Header Behavior (#2669)
* Track orientation change

* Add tests for withOrientation

* Better variable naming
2017-09-29 16:11:30 -05:00
Ashoat Tevosyan
b759d3136e Fix Flow types (and update RN version) (#2619)
* Fix .flowconfig to stop ignoring modules and properly include React Native libraries

Currently, there are numerous ignored libraries that are hiding type errors. Actually, they're causing type errors too. This sort of thing only patches over actual problems, so we have to revert them to get a config we can build upon.

* Update react-native/flow-bin dependencies

We want to have Flow types working with the latest packages.

* Update flow-typed libraries (auto-generated)

* Fix typing of navigation prop used by withNavigation HOC

The current typing is clearly a typo, as it is circular. `NavigationScreenProp` should be used to type the navigation prop

* Fix typing of easing function

What's funny is that I fixed this before in d71ed75133b97e33a8a683eda334b3005107d379. @skevy reintroduced the mistyped function in 9436d03fe8fface09001a5a40ce0aa8a01ad9e7e, which didn't trigger any Flow errors because .flowconfig was ignoring the entire react-native package

* Correct typing of View and Text style prop

The current code thinks it can import these, but this isn't true, and was being hidden because the .flowconfig ignored the whole react-native package. There's no easy to type Text and View at the current moment, as far as I can tell. Importing the highly generic `StyleObj` seems like the best bet, and is what I have being using in my projects.

* Import NavigationScreenComponent using full path

* Updating yarn.lock files

* Get rid of library overrides in flow-typed/react-native.js and flow/react-navigation.js

* Add @flow to src/react-navigation.js and make last three params to createNavigator optional

* Make screenProps and navigationOptions optional in NavigationNavigatorProps

* yarn run format

* Readd react-navigation/node_modules ignore to NavigationPlayground's .flowconfig

Realized this line I removed in the first commit is necessary when using npm link/yarn link, which is what the CircleCI build does

* Make all DrawerViewConfig's params optional

Some of these params are marked as optional because they have defaults. However, the only place `DrawerViewConfig` is used is as the input the function that then applies the defaults

* Make all props in NavigationNavigatorProps optional

`NavigationNavigatorProps` is used to type the props of the component that is output by the `StackNavigator`, `TabNavigator`, etc. component factories. This component does not need to have any props specified.

* Make second param to `DrawerNavigator` factory optional

`DrawerNavigator`, just like `TabNavigator` and `StackNavigator`, can be called with just a single argument (ie. omitting the config)

* Upgrade to RN 0.48.4 to address https://github.com/facebook/react-native/issues/15810
2017-09-25 11:29:34 -05:00
Sakamoto, Kazunori
98cb493449 Employ pre-commit hook for formatting code. (#2597)
This change comes thanks to @plasticine's great idea (https://github.com/react-community/react-navigation/pull/2581#issuecomment-329661371).
- Add husky and lint-staged to use pre-commit hook.
- Automate formatting JavaScript code using ESLint and Prettier before committing changes.
2017-09-15 17:17:09 -05:00
Spencer Carli
ba3fb1a7ee Fix Website Build (#2526)
* Update .eslintrc to allow compile.

* Resolve .web.js extension

* Look for __DEV__ on global

Fixes ReferenceError when not in the React Native environment.

* Replace __DEV__ at compile time via babel

* Don't try to lint a website build
2017-09-06 16:08:08 -05:00
Spencer Carli
0c62701ddc Revert changes to yarn.lock (#2545)
* Rollback changes to yarn.lock

* Update react-native-tab-view in yarn.lock
2017-09-06 13:22:08 -05:00
Manu Bamba
c815626020 Fixed issue with tab navigation (#2527) 2017-09-06 11:42:48 -05:00
Kevin Cooper
19babadf38 Fix the NavigationPlayground example! (#2170)
* [Playground] Commit auto-changes to package.json, yarn.lock

* [Playground] Rerun create-react-native-app

Preserving rn-cli.js and transformer.js

Still not quite working.

* [Playground] Fix the Expo loading issue by removing projectRoots

Now it looks in the right place to find its resources, including 'entryPoint'.

* [Playground] Add postinstall script to clean up files Yarn copies in

Yarn copies them when installing locally, causing lots of @providesModule collisions.

* Update the Contributors guide to explain how to use the example app

And recommend Yarn by default

* [Playground] Remove now-obsolete rn-cli.config.js

* [Playground] Upgrade expo and other dependencies

* [Playground] Don't delete .git just in case
2017-09-06 10:36:20 -05:00
Adam Miskiewicz
dd3290aa59
Remove generating prop-types from Flow 2017-07-19 13:11:56 -07:00
Adam Miskiewicz
2f0241d774
Update dependencies 2017-07-19 13:04:04 -07:00
Adam Miskiewicz
681e1c6e31
Update depenencies, update Prettier 2017-07-19 12:59:40 -07:00
Adam Miskiewicz
9436d03fe8
Update to RN 0.45, fix/improve flow coverage 2017-07-19 12:59:39 -07:00
Jacob Lauritzen
3abbb950e8 Update drawer layout polyfill to 1.3.1 (#1716) 2017-05-29 13:05:43 +05:30
Satyajit Sahoo
a3f7930c58 Upgrade React Native Tab View to v0.0.66 (#1713) 2017-05-28 19:55:49 -07:00
Adam Miskiewicz
1cd16bcf4a
Convert NavigationPlayground project to a CRNA project 2017-05-15 18:57:22 -07:00
Adam Miskiewicz
96a1c1fddf Add codecov.io support 2017-05-14 21:28:38 -07:00
Adam Miskiewicz
1ae3798137 Upgrade to React Native 0.44 + Flow 0.42 2017-05-14 21:28:38 -07:00
Adam Miskiewicz
f3a958dca1 Update/Fix Prettier + Eslint config for codebase
Run Prettier/Eslint on entire codebase, fix issues
2017-05-14 14:18:09 -07:00
Satyajit Sahoo
d4b4697f33 Update react-native-tab-view. Fixes #1248, #1163 (#1327) 2017-05-10 13:34:06 +02:00
Satyajit Sahoo
0cd3eaa97a BREAKING: Update React Native TabView (#1218) 2017-04-25 21:47:29 +02:00
Mike Grabowski
bbe9caff06 Fix eslint issues and turn on prettier by default (#1195)
* Automatically generate prop-types from Flow

* Remove propTypes usage

* Fix flow

* Modify some eslint settings

* Fix flowtype

* Lint tweaks

* use prop-types pkg

* Run prettier

* Fix flow

* Fix few lint issues

* Make eslint pass

* Run lint on tests

* Fix flow

* Fixes

* Alphabetical

* Trailing comma: ES5 for website compat, also fix config/paths

* Apply eslint --fix only to src now

* Fix missing transitionconfig

* Update TypeDefinition.js

* New stuff

* Unstage website and examples

* reformat code

* Update circle.yml
2017-04-24 17:31:22 +05:30
Joe McKie
2bbfc03cd0 Bump dependency versions to reflect current RN 2017-04-18 15:04:47 +02:00
Joe McKie
633d4819ec Update flow-react-proptypes to ^1.2.0 (#1084) 2017-04-18 11:27:34 +02:00
Mike Grabowski
7165efce02 Upgrade babel-plugin-flow-prop-types (#1045)
* Fix build

* Latest version fixes Header

* Fix propTypes from react-native leaking to web context

* Update todo notice
2017-04-14 17:38:52 +05:30
Mike Grabowski
e2f5e7fd49 Automatically generate prop-types from Flow (#1033)
* Automatically generate prop-types from Flow

* Remove propTypes usage

* Fix flow

* Modify some eslint settings

* Fix flowtype

* Lint tweaks

* use prop-types pkg
2017-04-13 15:19:30 -07:00
Daniel Schmidt
8c9a626401 bump react-native-drawer-layout-polyfill (#882)
includes access to the accessabilityView options and
a fix for #871 (adjusted zIndex)
2017-04-01 20:40:41 +05:30
Adam Miskiewicz
619a06c8cd
Update dependencies 2017-03-15 16:02:49 -07:00
Satyajit Sahoo
ecef7771e6 Update react-native-tab-view. Fixes #476 (#641) 2017-03-10 09:34:43 -08:00
Daniel Schmidt
af787e56fe move from react-native-drawer-layout to react-native-drawer-layout-polyfill
This enables us to use the native DrawerLayoutAndroid on android devices
2017-03-07 19:12:21 +05:30
Satyajit Sahoo
d6b5b28811 Update react-native-tab-view (#366)
Fixes #209
2017-02-17 08:28:10 -08:00
Adam Miskiewicz
7967fb81d2
Update yarn.lock to include react 15.4.2 2017-02-15 18:56:55 -08:00
Satyajit Sahoo
a7b1243053 Fix flow (#305)
* Fix Flow and Android build

* Enable flow on CI

* Fix and suppress flow errors
2017-02-13 08:26:30 -08:00
Satyajit Sahoo
1eabc0636b Updated react-native-tab-view
This fixes a bug where React Native Tab View was trying to keep state in sync, but state was updating at a slower speed.
2017-02-09 01:31:22 +05:30
Jakub Stasiak
aead8ff9fb Add withNavigation HOC (#137) 2017-02-06 18:58:04 +05:30
Satyajit Sahoo
7ebca1a494 Regenerate yarn.lock 2017-02-06 04:46:31 +05:30
Ferran Negre
d0582d205d Set up Jest to be able to test RN UI components (#96) 2017-01-31 08:43:24 +05:30
Satyajit Sahoo
56e12d6651 Update react-native-tab-view. Fixes #63 2017-01-28 23:34:02 +05:30
Satyajit Sahoo
eb16d0a8fe Update react-native-tab-view
Fixed scrollview's style so it doesn't need layout 6ef48ed529

Fixes #50
2017-01-28 16:03:52 +05:30
Adam Miskiewicz
c37ad8a0a9 Initial public release of React Navigation 2017-01-26 11:53:33 -08:00