diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 97ea7abc..775ef63d 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -23,35 +23,47 @@ Install dependencies (requires [yarn](https://yarnpkg.com/en/docs/install):
yarn
```
-## Unit tests
+## Automated tests
+
+To run flow:
+
+```
+npm run flow
+```
To run the unit tests:
```
-npm test
+npm run jest
```
…in watch mode:
```
-npm run test:watch
+npm run jest:watch
+```
+
+To run all automated tests:
+
+```
+npm test
```
## Visual tests
-Run the interactive storybook:
+To run the interactive storybook:
```
npm run docs:start
```
-Run generate a static build of the storybook:
+To generate a static build of the storybook:
```
npm run docs:build
```
-Run the performance benchmarks in a browser (opening `./performance/index.html`):
+To run the performance benchmarks in a browser (opening `./benchmarks/index.html`):
```
npm run benchmarks
@@ -59,7 +71,7 @@ npm run benchmarks
## Compile and build
-Compile the source code to `dist`:
+To compile the source code to `dist`:
```
npm run compile
@@ -73,7 +85,7 @@ npm run build
### Pre-commit
-Before creating a commit run:
+To format and lint code before commit:
```
npm run precommit
diff --git a/package.json b/package.json
index 0192c3fd..41b4d1ed 100644
--- a/package.json
+++ b/package.json
@@ -18,19 +18,25 @@
"flow": "flow",
"fmt": "find benchmarks docs src -name '*.js' | grep -v -E '(node_modules|dist)' | xargs npm run fmt:cmd",
"fmt:cmd": "prettier --print-width=100 --single-quote --write",
+ "jest": "jest",
+ "jest:watch": "npm run test -- --watch",
"lint": "npm run lint:cmd -- benchmarks docs src",
"lint:cmd": "eslint --fix --ignore-path .gitignore",
"precommit": "lint-staged",
"release": "npm run lint && npm run test && npm run compile && npm run build && npm publish",
- "test": "jest",
- "test:watch": "npm run test -- --watch"
+ "test": "flow && jest"
},
"babel": {
"presets": [
"react-native"
],
"plugins": [
- [ "transform-react-remove-prop-types", { "mode": "wrap" } ]
+ [
+ "transform-react-remove-prop-types",
+ {
+ "mode": "wrap"
+ }
+ ]
]
},
"jest": {
@@ -77,7 +83,7 @@
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-react": "^6.10.3",
"file-loader": "^0.11.1",
- "flow-bin": "^0.46.0",
+ "flow-bin": "^0.47.0",
"jest": "^19.0.2",
"lint-staged": "^3.4.2",
"node-libs-browser": "^0.5.3",
diff --git a/src/apis/AppRegistry/AppContainer.js b/src/apis/AppRegistry/AppContainer.js
new file mode 100644
index 00000000..bc55ac49
--- /dev/null
+++ b/src/apis/AppRegistry/AppContainer.js
@@ -0,0 +1,65 @@
+/**
+ * @flow
+ */
+
+import StyleSheet from '../StyleSheet';
+import View from '../../components/View';
+import { any, node } from 'prop-types';
+import React, { Component } from 'react';
+
+type Context = {
+ rootTag: any
+};
+
+type Props = {
+ children?: React.Children,
+ rootTag: any
+};
+
+type State = {
+ mainKey: number
+};
+
+class AppContainer extends Component {
+ props: Props;
+ state: State = { mainKey: 1 };
+
+ static childContextTypes = {
+ rootTag: any
+ };
+
+ static propTypes = {
+ children: node,
+ rootTag: any.isRequired
+ };
+
+ getChildContext(): Context {
+ return {
+ rootTag: this.props.rootTag
+ };
+ }
+
+ render() {
+ return (
+
+
+
+ );
+ }
+}
+
+const styles = StyleSheet.create({
+ /**
+ * Ensure that the application covers the whole screen.
+ */
+ appContainer: {
+ flex: 1
+ }
+});
+
+module.exports = AppContainer;
diff --git a/src/apis/AppRegistry/ReactNativeApp.js b/src/apis/AppRegistry/ReactNativeApp.js
deleted file mode 100644
index 765ef97b..00000000
--- a/src/apis/AppRegistry/ReactNativeApp.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * @flow
- */
-
-import StyleSheet from '../StyleSheet';
-import View from '../../components/View';
-import { any, object } from 'prop-types';
-import React, { Component } from 'react';
-
-class ReactNativeApp extends Component {
- static propTypes = {
- initialProps: object,
- rootComponent: any.isRequired,
- rootTag: any
- };
-
- render() {
- const { initialProps, rootComponent: RootComponent, rootTag } = this.props;
-
- return (
-
-
-
- );
- }
-}
-
-const styles = StyleSheet.create({
- /**
- * Ensure that the application covers the whole screen.
- */
- appContainer: {
- position: 'absolute',
- left: 0,
- top: 0,
- right: 0,
- bottom: 0
- }
-});
-
-module.exports = ReactNativeApp;
diff --git a/src/apis/AppRegistry/__tests__/__snapshots__/renderApplication-test.js.snap b/src/apis/AppRegistry/__tests__/__snapshots__/renderApplication-test.js.snap
index 8ae91ad2..f1e9a9a0 100644
--- a/src/apis/AppRegistry/__tests__/__snapshots__/renderApplication-test.js.snap
+++ b/src/apis/AppRegistry/__tests__/__snapshots__/renderApplication-test.js.snap
@@ -1,6 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`apis/AppRegistry/renderApplication getApplication 1`] = `
+
+
+
+`;
+
+exports[`apis/AppRegistry/renderApplication getApplication 2`] = `
""
`;
diff --git a/src/apis/AppRegistry/__tests__/renderApplication-test.js b/src/apis/AppRegistry/__tests__/renderApplication-test.js
index 2a5f49ab..186d8512 100644
--- a/src/apis/AppRegistry/__tests__/renderApplication-test.js
+++ b/src/apis/AppRegistry/__tests__/renderApplication-test.js
@@ -3,13 +3,13 @@
import { getApplication } from '../renderApplication';
import React from 'react';
-const component = () =>
;
+const RootComponent = () => ;
describe('apis/AppRegistry/renderApplication', () => {
test('getApplication', () => {
- const { element, stylesheet } = getApplication(component, {});
+ const { element, stylesheet } = getApplication(RootComponent, {});
- expect(element).toBeTruthy();
+ expect(element).toMatchSnapshot();
expect(stylesheet).toMatchSnapshot();
});
});
diff --git a/src/apis/AppRegistry/index.js b/src/apis/AppRegistry/index.js
index 712aaa83..9ab20754 100644
--- a/src/apis/AppRegistry/index.js
+++ b/src/apis/AppRegistry/index.js
@@ -6,7 +6,6 @@
* @flow
*/
-import { Component } from 'react';
import invariant from 'fbjs/lib/invariant';
import { unmountComponentAtNode } from 'react-dom';
import renderApplication, { getApplication } from './renderApplication';
@@ -14,9 +13,9 @@ import renderApplication, { getApplication } from './renderApplication';
const emptyObject = {};
const runnables = {};
-type ComponentProvider = () => Component;
+export type ComponentProvider = () => ReactClass;
-type AppConfig = {
+export type AppConfig = {
appKey: string,
component?: ComponentProvider,
run?: Function
diff --git a/src/apis/AppRegistry/renderApplication.js b/src/apis/AppRegistry/renderApplication.js
index 9db39c21..f5f257ac 100644
--- a/src/apis/AppRegistry/renderApplication.js
+++ b/src/apis/AppRegistry/renderApplication.js
@@ -8,25 +8,31 @@
import invariant from 'fbjs/lib/invariant';
import { render } from 'react-dom';
-import ReactNativeApp from './ReactNativeApp';
+import AppContainer from './AppContainer';
import StyleSheet from '../../apis/StyleSheet';
-import React, { Component } from 'react';
+import React from 'react';
export default function renderApplication(
- RootComponent: Component,
+ RootComponent: ReactClass