diff --git a/.eslintrc.js b/.eslintrc.js index bad3317bb..da5260e96 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,9 +2,17 @@ module.exports = { extends: 'airbnb', plugins: [ 'react', + 'jest' ], + env: { + "jest/globals": true + }, parser: 'babel-eslint', rules: { + "jest/no-disabled-tests": "warn", + "jest/no-focused-tests": "error", + "jest/no-identical-title": "error", + "jest/valid-expect": "error", 'react/forbid-prop-types': 0, 'no-console': 0, 'new-cap': 0, diff --git a/.travis.yml b/.travis.yml index ed5eb2182..c2c66f1e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ before_script: - if [ $TEST_SUITE = example-jest ]; then rm -rf Example/node_modules/react-native-router-flux/Example; fi - if [ $TEST_SUITE = example-jest ]; then cp -r src/ Example/node_modules/react-native-router-flux/src/; fi script: - - if [ $TEST_SUITE = eslint ]; then node node_modules/eslint/bin/eslint index.js src/ test/; fi + - if [ $TEST_SUITE = eslint ]; then node node_modules/.bin/eslint index.js src/ _tests__/; fi - if [ $TEST_SUITE = lib-test ]; then yarn test; fi - if [ $TEST_SUITE = example-jest ]; then cd Example && yarn run jest && cd ..; fi before_cache: diff --git a/Example/Example.js b/Example/Example.js index 06f92991a..1cd3f7ee8 100644 --- a/Example/Example.js +++ b/Example/Example.js @@ -50,17 +50,17 @@ class Example extends Component { render() { return ( - + navigation.state.key}/> - - - + + + - + - + diff --git a/Example/components/Launch.js b/Example/components/Launch.js index a8c8c7987..4fff6d872 100644 --- a/Example/components/Launch.js +++ b/Example/components/Launch.js @@ -16,6 +16,7 @@ const styles = StyleSheet.create({ class Launch extends React.Component { render(){ + console.log("Launch RENDER"); return ( Launch page diff --git a/Example/components/Login.js b/Example/components/Login.js index fa46b3fd4..cc805aba3 100644 --- a/Example/components/Login.js +++ b/Example/components/Login.js @@ -23,16 +23,24 @@ const styles = StyleSheet.create({ }); export default class extends React.Component { + componentDidMount() { + Actions.refresh({ + title: 'Login!', + rightTitle: 'rightTitle', + onRight: () => {}, + }); + } render() { const title = this.props.title || 'No Title'; const data = this.props.data || 'No Data'; + console.log("Login RENDER"); return ( Login page 1 Title: {title} Data: {data} - + ); diff --git a/Example/package.json b/Example/package.json index 35f00d7b9..6cfada5b8 100644 --- a/Example/package.json +++ b/Example/package.json @@ -8,13 +8,13 @@ }, "dependencies": { "autobind-decorator": "^1.4.1", - "mobx": "^3.1.16", + "mobx": "^3.2.1", "mobx-react": "^4.2.1", + "react": "16.0.0-alpha.6", + "react-native": "0.44.0", "react-native-button": "^2.0.0", - "react-navigation": "^1.0.0-beta.11", "react-native-router-flux": "^4.0.0-beta.7", - "react": "16.0.0-alpha.6", - "react-native": "0.44.0" + "react-navigation": "^1.0.0-beta.11" }, "devDependencies": { "babel-jest": "20.0.3", diff --git a/Example/yarn.lock b/Example/yarn.lock index 7066cceff..775dd83d5 100644 --- a/Example/yarn.lock +++ b/Example/yarn.lock @@ -61,6 +61,10 @@ ansi-regex@^2.0.0, ansi-regex@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" @@ -698,7 +702,7 @@ babel-plugin-transform-strict-mode@^6.24.1: babel-runtime "^6.22.0" babel-types "^6.24.1" -babel-polyfill@^6.20.0: +babel-polyfill@6.23.0, babel-polyfill@^6.20.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.23.0.tgz#8364ca62df8eafb830499f699177466c3b03499d" dependencies: @@ -1078,7 +1082,7 @@ center-align@^0.1.1: align-text "^0.1.3" lazy-cache "^1.0.3" -chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: +chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" dependencies: @@ -1102,6 +1106,12 @@ cli-cursor@^1.0.1: dependencies: restore-cursor "^1.0.1" +cli-cursor@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" + dependencies: + restore-cursor "^2.0.0" + cli-width@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a" @@ -1519,6 +1529,14 @@ extend@~3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444" +external-editor@^2.0.1: + version "2.0.4" + resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.0.4.tgz#1ed9199da9cbfe2ef2f7a31b2fde8b0d12368972" + dependencies: + iconv-lite "^0.4.17" + jschardet "^1.4.2" + tmp "^0.0.31" + extglob@^0.3.1: version "0.3.2" resolved "https://registry.yarnpkg.com/extglob/-/extglob-0.3.2.tgz#2e18ff3d2f49ab2765cec9023f011daa8d8349a1" @@ -1584,6 +1602,12 @@ figures@^1.3.5: escape-string-regexp "^1.0.5" object-assign "^4.1.0" +figures@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" + dependencies: + escape-string-regexp "^1.0.5" + filename-regex@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" @@ -1873,7 +1897,7 @@ iconv-lite@0.4.13: version "0.4.13" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2" -iconv-lite@~0.4.13: +iconv-lite@^0.4.17, iconv-lite@~0.4.13: version "0.4.18" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2" @@ -1900,6 +1924,24 @@ inherits@2, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" +inquirer@3.0.6: + version "3.0.6" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.0.6.tgz#e04aaa9d05b7a3cb9b0f407d04375f0447190347" + dependencies: + ansi-escapes "^1.1.0" + chalk "^1.0.0" + cli-cursor "^2.1.0" + cli-width "^2.0.0" + external-editor "^2.0.1" + figures "^2.0.0" + lodash "^4.3.0" + mute-stream "0.0.7" + run-async "^2.2.0" + rx "^4.1.0" + string-width "^2.0.0" + strip-ansi "^3.0.0" + through "^2.3.6" + inquirer@^0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-0.12.0.tgz#1ef2bfd63504df0bc75785fff8c2c41df12f077e" @@ -1978,6 +2020,10 @@ is-fullwidth-code-point@^1.0.0: dependencies: number-is-nan "^1.0.0" +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + is-glob@^2.0.0, is-glob@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863" @@ -2004,6 +2050,10 @@ is-primitive@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" +is-promise@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa" + is-stream@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -2357,6 +2407,10 @@ jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" +jschardet@^1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/jschardet/-/jschardet-1.4.2.tgz#2aa107f142af4121d145659d44f50830961e699a" + jsdom@^9.12.0: version "9.12.0" resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.12.0.tgz#e8c546fffcb06c00d4833ca84410fed7f8a097d4" @@ -2683,6 +2737,10 @@ mime@^1.3.4: version "1.3.6" resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0" +mimic-fn@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18" + min-document@^2.19.0: version "2.19.0" resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685" @@ -2699,7 +2757,7 @@ minimist@0.0.8, minimist@~0.0.1: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" -minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0: +minimist@1.2.0, minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" @@ -2715,9 +2773,9 @@ mobx-react@^4.2.1: dependencies: hoist-non-react-statics "^1.2.0" -mobx@^3.1.16: - version "3.1.16" - resolved "https://registry.yarnpkg.com/mobx/-/mobx-3.1.16.tgz#7ef06b6de7cba31d2ca872484d47ee36265d7768" +mobx@^3.1.16, mobx@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-3.2.1.tgz#6aeade0120cc3f78baa57195031630a0ae8f13cf" moment@2.x.x: version "2.18.1" @@ -2762,6 +2820,10 @@ mute-stream@0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" +mute-stream@0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -2774,6 +2836,13 @@ negotiator@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" +node-fetch@1.6.3: + version "1.6.3" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04" + dependencies: + encoding "^0.1.11" + is-stream "^1.0.1" + node-fetch@^1.0.1, node-fetch@^1.3.3: version "1.7.1" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5" @@ -2864,6 +2933,30 @@ onetime@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789" +onetime@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4" + dependencies: + mimic-fn "^1.0.0" + +opencollective@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/opencollective/-/opencollective-1.0.3.tgz#aee6372bc28144583690c3ca8daecfc120dd0ef1" + dependencies: + babel-polyfill "6.23.0" + chalk "1.1.3" + inquirer "3.0.6" + minimist "1.2.0" + node-fetch "1.6.3" + opn "4.0.2" + +opn@4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/opn/-/opn-4.0.2.tgz#7abc22e644dff63b0a96d5ab7f2790c0f01abc95" + dependencies: + object-assign "^4.0.1" + pinkie-promise "^2.0.0" + opn@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/opn/-/opn-3.0.3.tgz#b6d99e7399f78d65c3baaffef1fb288e9b85243a" @@ -2902,7 +2995,7 @@ os-locale@^1.4.0: dependencies: lcid "^1.0.0" -os-tmpdir@^1.0.0, os-tmpdir@^1.0.1: +os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -3140,12 +3233,14 @@ react-native-drawer-layout@1.3.2: dependencies: react-native-dismiss-keyboard "1.0.0" -react-native-router-flux@4.0.0-beta.3: - version "4.0.0-beta.3" - resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-4.0.0-beta.3.tgz#7153a13e44031fe1017a079f498a848543e335bd" +react-native-router-flux@^4.0.0-beta.7: + version "4.0.0-beta.7" + resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-4.0.0-beta.7.tgz#51d61dfe6b70df7da97bf96d38b8b13d7ba1c52d" dependencies: mobx "^3.1.16" mobx-react "^4.2.1" + opencollective "^1.0.3" + prop-types "^15.5.10" react-native-button "^2.0.0" react-navigation "^1.0.0-beta.11" @@ -3460,6 +3555,13 @@ restore-cursor@^1.0.1: exit-hook "^1.0.0" onetime "^1.0.0" +restore-cursor@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" + dependencies: + onetime "^2.0.0" + signal-exit "^3.0.2" + right-align@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef" @@ -3486,10 +3588,20 @@ run-async@^0.1.0: dependencies: once "^1.3.0" +run-async@^2.2.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0" + dependencies: + is-promise "^2.1.0" + rx-lite@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102" +rx@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782" + safe-buffer@^5.0.1, safe-buffer@~5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.0.tgz#fe4c8460397f9eaaaa58e73be46273408a45e223" @@ -3612,6 +3724,10 @@ shellwords@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.0.tgz#66afd47b6a12932d9071cbfd98a52e785cd0ba14" +signal-exit@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" + simple-plist@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/simple-plist/-/simple-plist-0.2.1.tgz#71766db352326928cf3a807242ba762322636723" @@ -3728,6 +3844,13 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" +string-width@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.0.tgz#030664561fc146c9423ec7d978fe2457437fe6d0" + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + string_decoder@~0.10.x: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" @@ -3748,6 +3871,12 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1: dependencies: ansi-regex "^2.0.0" +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + dependencies: + ansi-regex "^3.0.0" + strip-bom@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" @@ -3808,6 +3937,12 @@ time-stamp@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-1.1.0.tgz#764a5a11af50561921b133f3b44e618687e0f5c3" +tmp@^0.0.31: + version "0.0.31" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7" + dependencies: + os-tmpdir "~1.0.1" + tmpl@1.0.x: version "1.0.4" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" diff --git a/__tests__/scenes.test.js b/__tests__/scenes.test.js index 885bcdd29..912fa943d 100644 --- a/__tests__/scenes.test.js +++ b/__tests__/scenes.test.js @@ -1,6 +1,5 @@ import React from 'react'; -import {Text} from 'react-native'; -import {when} from 'mobx'; +import { Text } from 'react-native'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; @@ -8,29 +7,23 @@ import Router from '../src/Router'; import Scene from '../src/Scene'; import navigationStore from '../src/navigationStore'; -class B extends React.Component { - render(){ - return Hello world!; - } -} - - -const router = +const B = () => Hello world!; +const router = ( - - + + -; +); test('renders correctly', done => { renderer.create(router); - console.log("STATE:", JSON.stringify(navigationStore.state)); - navigationStore.c({data: 'abc'}); - navigationStore.refresh({data: 'abcde'}); - console.log("STATE:", JSON.stringify(navigationStore.state)); + console.log('STATE:', JSON.stringify(navigationStore.state)); + navigationStore.c({ data: 'abc' }); + navigationStore.refresh({ data: 'abcde' }); + console.log('STATE:', JSON.stringify(navigationStore.state)); navigationStore.pop(); - console.log("STATE:", JSON.stringify(navigationStore.state)); - navigationStore.refresh({a: 3}); - console.log("STATE:", JSON.stringify(navigationStore.state)); + console.log('STATE:', JSON.stringify(navigationStore.state)); + navigationStore.refresh({ a: 3 }); + console.log('STATE:', JSON.stringify(navigationStore.state)); done(); }); diff --git a/dist/Router.js b/dist/Router.js index 2ef76a60a..ec613b763 100644 --- a/dist/Router.js +++ b/dist/Router.js @@ -64,24 +64,27 @@ function createNavigationOptions(params){var title= -params.title,backButtonImage=params.backButtonImage,navTransparent=params.navTransparent,hideNavBar=params.hideNavBar,hideTabBar=params.hideTabBar,backTitle=params.backTitle,right=params.right,rightButton=params.rightButton,left=params.left,leftButton=params.leftButton,navigationBarStyle=params.navigationBarStyle,headerStyle=params.headerStyle,navBarButtonColor=params.navBarButtonColor,tabBarLabel=params.tabBarLabel,tabBarIcon=params.tabBarIcon,icon=params.icon,getTitle=params.getTitle,renderTitle=params.renderTitle,panHandlers=params.panHandlers,navigationBarTitleImage=params.navigationBarTitleImage,navigationBarTitleImageStyle=params.navigationBarTitleImageStyle,headerTitleStyle=params.headerTitleStyle,titleStyle=params.titleStyle,navBar=params.navBar,onRight=params.onRight,onLeft=params.onLeft,rightButtonImage=params.rightButtonImage,leftButtonImage=params.leftButtonImage,init=params.init,back=params.back,props=_objectWithoutProperties(params,['title','backButtonImage','navTransparent','hideNavBar','hideTabBar','backTitle','right','rightButton','left','leftButton','navigationBarStyle','headerStyle','navBarButtonColor','tabBarLabel','tabBarIcon','icon','getTitle','renderTitle','panHandlers','navigationBarTitleImage','navigationBarTitleImageStyle','headerTitleStyle','titleStyle','navBar','onRight','onLeft','rightButtonImage','leftButtonImage','init','back']); +params.title,backButtonImage=params.backButtonImage,navTransparent=params.navTransparent,hideNavBar=params.hideNavBar,hideTabBar=params.hideTabBar,backTitle=params.backTitle,right=params.right,rightButton=params.rightButton,left=params.left,leftButton=params.leftButton,navigationBarStyle=params.navigationBarStyle,headerStyle=params.headerStyle,navBarButtonColor=params.navBarButtonColor,tabBarLabel=params.tabBarLabel,tabBarIcon=params.tabBarIcon,icon=params.icon,getTitle=params.getTitle,renderTitle=params.renderTitle,panHandlers=params.panHandlers,navigationBarTitleImage=params.navigationBarTitleImage,navigationBarTitleImageStyle=params.navigationBarTitleImageStyle,component=params.component,rightTitle=params.rightTitle,leftTitle=params.leftTitle,leftButtonTextStyle=params.leftButtonTextStyle,rightButtonTextStyle=params.rightButtonTextStyle,backButtonTextStyle=params.backButtonTextStyle,headerTitleStyle=params.headerTitleStyle,titleStyle=params.titleStyle,navBar=params.navBar,onRight=params.onRight,onLeft=params.onLeft,rightButtonImage=params.rightButtonImage,leftButtonImage=params.leftButtonImage,init=params.init,back=params.back,props=_objectWithoutProperties(params,['title','backButtonImage','navTransparent','hideNavBar','hideTabBar','backTitle','right','rightButton','left','leftButton','navigationBarStyle','headerStyle','navBarButtonColor','tabBarLabel','tabBarIcon','icon','getTitle','renderTitle','panHandlers','navigationBarTitleImage','navigationBarTitleImageStyle','component','rightTitle','leftTitle','leftButtonTextStyle','rightButtonTextStyle','backButtonTextStyle','headerTitleStyle','titleStyle','navBar','onRight','onLeft','rightButtonImage','leftButtonImage','init','back']); var NavBar=navBar; +if(component&&component.navigationOptions){ +return component.navigationOptions; +} return function(_ref2){var navigation=_ref2.navigation,screenProps=_ref2.screenProps; var navigationParams=navigation.state.params||{}; var res=_extends({}, props,{ headerTintColor:navBarButtonColor, headerTitleStyle:headerTitleStyle||titleStyle, -title:getValue(navigationParams.title||title||getTitle,_extends({navigation:navigation},navigationParams,screenProps)), -headerBackTitle:getValue(navigationParams.backTitle||backTitle,_extends({navigation:navigation},navigationParams,screenProps)), +title:getValue(navigationParams.title||title||getTitle,_extends({navigation:navigation},params,navigationParams,screenProps)), +headerBackTitle:getValue(navigationParams.backTitle||backTitle,_extends({navigation:navigation},params,navigationParams,screenProps)), headerRight:getValue(navigationParams.right||right||rightButton||params.renderRightButton,_extends({navigation:navigation},navigationParams,screenProps)), -headerLeft:getValue(navigationParams.left||left||leftButton||params.renderLeftButton,_extends({navigation:navigation},navigationParams,screenProps)), -headerTitle:getValue(navigationParams.renderTitle||renderTitle||params.renderTitle,_extends({navigation:navigation},navigationParams,screenProps)), -headerStyle:getValue(navigationParams.headerStyle||headerStyle||navigationBarStyle,_extends({navigation:navigation},navigationParams,screenProps)), +headerLeft:getValue(navigationParams.left||left||leftButton||params.renderLeftButton,_extends({navigation:navigation},params,navigationParams,screenProps)), +headerTitle:getValue(navigationParams.renderTitle||renderTitle||params.renderTitle,_extends({navigation:navigation},params,navigationParams,screenProps)), +headerStyle:getValue(navigationParams.headerStyle||headerStyle||navigationBarStyle,_extends({navigation:navigation},params,navigationParams,screenProps)), headerBackImage:navigationParams.backButtonImage||backButtonImage}); if(NavBar){ -res.header=function(data){return _react2.default.createElement(NavBar,_extends({navigation:navigation},data,params,{__source:{fileName:_jsxFileName,lineNumber:84}}));}; +res.header=function(data){return _react2.default.createElement(NavBar,_extends({navigation:navigation},data,params,{__source:{fileName:_jsxFileName,lineNumber:87}}));}; } if(panHandlers===null){ @@ -89,7 +92,7 @@ res.gesturesEnabled=false; } if(navigationBarTitleImage){ -res.headerTitle=_react2.default.createElement(_reactNative.Image,{source:navigationBarTitleImage,style:navigationBarTitleImageStyle,__source:{fileName:_jsxFileName,lineNumber:92}}); +res.headerTitle=_react2.default.createElement(_reactNative.Image,{source:navigationBarTitleImage,style:navigationBarTitleImageStyle,__source:{fileName:_jsxFileName,lineNumber:95}}); } if(tabBarLabel){ @@ -100,14 +103,17 @@ if(tabBarIcon||icon){ res.tabBarIcon=tabBarIcon||icon; } -if(rightButtonImage||onRight){ +if(rightButtonImage||rightTitle||params.renderRightButton||onRight||navigationParams.onRight|| +navigationParams.rightTitle||navigationParams.rightButtonImage){ res.headerRight=getValue(navigationParams.right||right||rightButton||params.renderRightButton,_extends({}, navigationParams,screenProps))||(0,_NavBar.renderRightButton)(_extends({},params,navigationParams)); } -if(leftButtonImage||onLeft||backButtonImage){ -res.headerLeft=getValue(navigationParams.left||left||leftButton||params.renderLeftButton,_extends({},navigationParams,screenProps))|| -(0,_NavBar.renderLeftButton)(_extends({},params,navigationParams))||(init?null:(0,_NavBar.renderBackButton)(_extends({},params,navigationParams))); +if(leftButtonImage||backButtonImage||backTitle||leftTitle||params.renderLeftButton||leftButtonTextStyle|| +backButtonTextStyle||onLeft||navigationParams.leftTitle||navigationParams.onLeft||navigationParams.leftButtonImage|| +navigationParams.backButtonImage||navigationParams.backTitle){ +res.headerLeft=getValue(navigationParams.left||left||leftButton||params.renderLeftButton,_extends({},params,navigationParams,screenProps))|| +(0,_NavBar.renderLeftButton)(_extends({},params,navigationParams))||(init?null:(0,_NavBar.renderBackButton)(_extends({},params,navigationParams,screenProps))); } if(back){ @@ -132,14 +138,16 @@ function createWrapper(Component){ if(!Component){ return null; } -return(0,_native.observer)(function(_ref3){var navigation=_ref3.navigation,props=_objectWithoutProperties(_ref3,['navigation']);return _react2.default.createElement(Component,_extends({},props,{navigation:navigation},navigation.state.params,{name:navigation.state.routeName,__source:{fileName:_jsxFileName,lineNumber:135}}));}); +return(0,_native.observer)(function(_ref3){var navigation=_ref3.navigation,props=_objectWithoutProperties(_ref3,['navigation']); +return _react2.default.createElement(Component,_extends({},props,{navigation:navigation},navigation.state.params,{name:navigation.state.routeName,__source:{fileName:_jsxFileName,lineNumber:142}})); +}); } var App=(0,_native.observer)(function(props){ var AppNavigator=props.navigator; return( -_react2.default.createElement(AppNavigator,{navigation:(0,_reactNavigation.addNavigationHelpers)({dispatch:_navigationStore2.default.dispatch,state:_navigationStore2.default.state}),__source:{fileName:_jsxFileName,lineNumber:142}})); +_react2.default.createElement(AppNavigator,{navigation:(0,_reactNavigation.addNavigationHelpers)({dispatch:_navigationStore2.default.dispatch,state:_navigationStore2.default.state}),__source:{fileName:_jsxFileName,lineNumber:150}})); }); @@ -170,23 +178,26 @@ var children=!Array.isArray(parentProps.children)?[parentProps.children]:[].conc if(!drawer&&!tabs){ children.push.apply(children,_toConsumableArray(clones)); } -var initialRouteName=void 0; -var initialRouteParams=void 0;var _loop=function _loop( -child){ -(0,_Util.assert)(child.key,'key should be defined for '+child); -var key=child.key; -var init=key===children[0].key; -(0,_Util.assert)(reservedKeys.indexOf(key)===-1,'Scene name cannot be reserved word: '+child.key);var _child$props= -child.props,component=_child$props.component,_child$props$type=_child$props.type,type=_child$props$type===undefined?'push':_child$props$type,onEnter=_child$props.onEnter,onExit=_child$props.onExit,on=_child$props.on,failure=_child$props.failure,success=_child$props.success,props=_objectWithoutProperties(_child$props,['component','type','onEnter','onExit','on','failure','success']); + +for(var _iterator2=children,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[typeof Symbol==='function'?Symbol.iterator:'@@iterator']();;){var _ref5;if(_isArray2){if(_i2>=_iterator2.length)break;_ref5=_iterator2[_i2++];}else{_i2=_iterator2.next();if(_i2.done)break;_ref5=_i2.value;}var child=_ref5; if(child.props.clone){ if(clones.indexOf(child)===-1){ clones.push(child); } } +} +var initialRouteName=void 0; +var initialRouteParams=void 0;var _loop=function _loop( +_child){ +(0,_Util.assert)(_child.key,'key should be defined for '+_child); +var key=_child.key; +var init=key===children[0].key; +(0,_Util.assert)(reservedKeys.indexOf(key)===-1,'Scene name cannot be reserved word: '+_child.key);var _child$props= +_child.props,component=_child$props.component,_child$props$type=_child$props.type,type=_child$props$type===undefined?'push':_child$props$type,onEnter=_child$props.onEnter,onExit=_child$props.onExit,on=_child$props.on,failure=_child$props.failure,success=_child$props.success,props=_objectWithoutProperties(_child$props,['component','type','onEnter','onExit','on','failure','success']); if(!_navigationStore2.default.states[key]){ _navigationStore2.default.states[key]={}; } -for(var _iterator3=Object.keys(props),_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[typeof Symbol==='function'?Symbol.iterator:'@@iterator']();;){var _ref6;if(_isArray3){if(_i3>=_iterator3.length)break;_ref6=_iterator3[_i3++];}else{_i3=_iterator3.next();if(_i3.done)break;_ref6=_i3.value;}var transition=_ref6; +for(var _iterator4=Object.keys(props),_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[typeof Symbol==='function'?Symbol.iterator:'@@iterator']();;){var _ref7;if(_isArray4){if(_i4>=_iterator4.length)break;_ref7=_iterator4[_i4++];}else{_i4=_iterator4.next();if(_i4.done)break;_ref7=_i4.value;}var transition=_ref7; if(reservedKeys.indexOf(transition)===-1&&transition[props]instanceof Function){ _navigationStore2.default.states[key][transition]=props[transition]; } @@ -200,15 +211,14 @@ _navigationStore2.default.states[key].failure=failure instanceof Function?failur } var screen={ -screen:createWrapper(component)||processScene(child,commonProps,clones)||lightbox&&_reactNative.View, -navigationOptions:createNavigationOptions(_extends({},commonProps,child.props,{init:init}))}; +screen:createWrapper(component)||processScene(_child,commonProps,clones)||lightbox&&_reactNative.View, +navigationOptions:createNavigationOptions(_extends({},commonProps,component,_child.props,{init:init,component:component}))}; var wrapNavBar=drawer||tabs||wrap; - if(component&&wrapNavBar){ -res[key]={screen:processScene({key:key,props:{children:{key:'_'+key,props:child.props}}},commonProps,clones)}; +res[key]={screen:processScene({key:key,props:{children:{key:'_'+key,props:_child.props}}},commonProps,clones)}; }else{ res[key]=screen; } @@ -229,10 +239,10 @@ _navigationStore2.default[key+_Util.OnExit]=onExit; } order.push(key); -if(child.props.initial||!initialRouteName){ +if(_child.props.initial||!initialRouteName){ initialRouteName=key; initialRouteParams=_extends({},commonProps,props); -}};for(var _iterator2=children,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[typeof Symbol==='function'?Symbol.iterator:'@@iterator']();;){var _ref5;if(_isArray2){if(_i2>=_iterator2.length)break;_ref5=_iterator2[_i2++];}else{_i2=_iterator2.next();if(_i2.done)break;_ref5=_i2.value;}var child=_ref5;_loop(child); +}};for(var _iterator3=children,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[typeof Symbol==='function'?Symbol.iterator:'@@iterator']();;){var _ref6;if(_isArray3){if(_i3>=_iterator3.length)break;_ref6=_iterator3[_i3++];}else{_i3=_iterator3.next();if(_i3.done)break;_ref6=_i3.value;}var _child=_ref6;_loop(_child); } var mode=modal?'modal':'card'; if(lightbox){ @@ -249,13 +259,13 @@ return navigator(res,_extends({lazy:lazy,initialRouteName:initialRouteName,initi return(0,_reactNavigation.StackNavigator)(res,_extends({mode:mode,initialRouteParams:initialRouteParams,initialRouteName:initialRouteName},parentProps,{navigationOptions:createNavigationOptions(parentProps)})); } -var Router=function Router(_ref7){var createReducer=_ref7.createReducer,props=_objectWithoutProperties(_ref7,['createReducer']); +var Router=function Router(_ref8){var createReducer=_ref8.createReducer,props=_objectWithoutProperties(_ref8,['createReducer']); var scene=props.children; var AppNavigator=processScene(scene,props); _navigationStore2.default.router=AppNavigator.router; _navigationStore2.default.reducer=createReducer&&createReducer(props); -return _react2.default.createElement(App,{navigator:AppNavigator,__source:{fileName:_jsxFileName,lineNumber:258}}); +return _react2.default.createElement(App,{navigator:AppNavigator,__source:{fileName:_jsxFileName,lineNumber:268}}); }; Router.propTypes={ createReducer:_propTypes2.default.func, diff --git a/dist/navigationStore.js b/dist/navigationStore.js index 2f47eb153..ed298e225 100644 --- a/dist/navigationStore.js +++ b/dist/navigationStore.js @@ -63,8 +63,12 @@ NavigationStore=(_class=function(){_createClass(NavigationStore,[{key:'state',ge + + { -return(0,_mobx.toJS)(this._state); +var scene=this.currentScene; +var params=this.currentParams; +return this._state; }},{key:'router',set:function set( router){ @@ -75,7 +79,7 @@ this.dispatch(_reactNavigation.NavigationActions.init()); return this._router; }}]); -function NavigationStore(){var _this=this;_classCallCheck(this,NavigationStore);this._router=null;this.states={};this.reducer=null;_initDefineProp(this,'_state',_descriptor,this);_initDefineProp(this,'currentScene',_descriptor2,this);_initDefineProp(this,'prevScene',_descriptor3,this);this. +function NavigationStore(){var _this=this;_classCallCheck(this,NavigationStore);this._router=null;this.states={};this.reducer=null;_initDefineProp(this,'currentScene',_descriptor,this);_initDefineProp(this,'prevScene',_descriptor2,this);_initDefineProp(this,'currentParams',_descriptor3,this);this. @@ -128,6 +132,7 @@ nextState=function(state,cmd){return _this.reducer?_this.reducer(state,cmd):_thi dispatch=function(cmd){ _this.setState(_this.nextState(_this.state,cmd)); + };_initDefineProp(this,'setState',_descriptor4,this);this. @@ -140,6 +145,8 @@ _this.setState(_this.nextState(_this.state,cmd)); + + run=function(){for(var _len=arguments.length,params=Array(_len>3?_len-3:0),_key=3;_key<_len;_key++){params[_key-3]=arguments[_key];}var type=arguments.length>0&&arguments[0]!==undefined?arguments[0]:ActionConst.PUSH;var routeName=arguments[1];var actions=arguments[2]; var res={}; for(var _iterator=params,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol==='function'?typeof Symbol==='function'?Symbol.iterator:'@@iterator':'@@iterator']();;){var _ref;if(_isArray){if(_i>=_iterator.length)break;_ref=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref=_i.value;}var param=_ref; @@ -171,6 +178,8 @@ _this.setState(newState); };this. push=function(routeName){for(var _len2=arguments.length,params=Array(_len2>1?_len2-1:0),_key2=1;_key2<_len2;_key2++){params[_key2-1]=arguments[_key2];} + + _this.run.apply(_this,[ActionConst.PUSH,routeName,null].concat(params)); };this. @@ -222,7 +231,7 @@ _this.run(ActionConst.REPLACE,routeName,[_reactNavigation.NavigationActions.navi routeName:routeName, params:res})]); -};var defaultSuccess=function defaultSuccess(){};var defaultFailure=function defaultFailure(){};(0,_mobx.autorunAsync)(function _callee(){var handler,res,_handler,success,failure,params,_res;return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;if(_this.prevScene&&_this.currentScene!==_this.prevScene){handler=_this[_this.prevScene+_Util.OnExit];if(handler){try{res=handler();if(res instanceof Promise){res.then(defaultSuccess,defaultFailure);}}catch(e){console.error('Error during onExit handler:',e);}}}if(!(_this.currentScene&&_this.currentScene!==_this.prevScene&&_this.states[_this.currentScene])){_context.next=20;break;}_handler=_this[_this.currentScene+_Util.OnEnter];success=_this.states[_this.currentScene].success||defaultSuccess;failure=_this.states[_this.currentScene].failure||defaultFailure;if(!_handler){_context.next=20;break;}_context.prev=7;params=_this.currentState().params;console.log('RUN onEnter handler for state=',_this.currentScene,' params='+JSON.stringify(params));_context.next=12;return regeneratorRuntime.awrap(_handler(params));case 12:_res=_context.sent;if(_res){console.log('SUCCESS',_res);success(_res);}else{console.log('FAILURE NULL RES');failure();}_context.next=20;break;case 16:_context.prev=16;_context.t0=_context['catch'](7);console.log('FAILURE EXCEPTION',_context.t0);failure(_context.t0);case 20:_context.next=25;break;case 22:_context.prev=22;_context.t1=_context['catch'](0);console.error('Error handling:'+_context.t1);case 25:case'end':return _context.stop();}}},null,_this,[[0,22],[7,16]]);});}return NavigationStore;}(),(_descriptor=_applyDecoratedDescriptor(_class.prototype,'_state',[_mobx.observable],{enumerable:true,initializer:null}),_descriptor2=_applyDecoratedDescriptor(_class.prototype,'currentScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor3=_applyDecoratedDescriptor(_class.prototype,'prevScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_applyDecoratedDescriptor(_class.prototype,'state',[_mobx.computed],Object.getOwnPropertyDescriptor(_class.prototype,'state'),_class.prototype),_descriptor4=_applyDecoratedDescriptor(_class.prototype,'setState',[_mobx.action],{enumerable:true,initializer:function initializer(){var _this2=this;return function(newState){if(!newState||_this2.currentState(newState).routeName===_this2.currentScene){return;}_this2._state=newState;_this2.prevScene=_this2.currentScene;_this2.currentScene=_this2.currentState(_this2._state).routeName;};}})),_class);exports.default= +};var defaultSuccess=function defaultSuccess(){};var defaultFailure=function defaultFailure(){};(0,_mobx.autorunAsync)(function _callee(){var handler,res,_handler,success,failure,params,_res;return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;if(_this.prevScene&&_this.currentScene!==_this.prevScene){handler=_this[_this.prevScene+_Util.OnExit];if(handler){try{res=handler();if(res instanceof Promise){res.then(defaultSuccess,defaultFailure);}}catch(e){console.error('Error during onExit handler:',e);}}}if(!(_this.currentScene&&_this.currentScene!==_this.prevScene&&_this.states[_this.currentScene])){_context.next=20;break;}_handler=_this[_this.currentScene+_Util.OnEnter];success=_this.states[_this.currentScene].success||defaultSuccess;failure=_this.states[_this.currentScene].failure||defaultFailure;if(!_handler){_context.next=20;break;}_context.prev=7;params=_this.currentState().params;console.log('RUN onEnter handler for state=',_this.currentScene,' params='+JSON.stringify(params));_context.next=12;return regeneratorRuntime.awrap(_handler(params));case 12:_res=_context.sent;if(_res){console.log('SUCCESS',_res);success(_res);}else{console.log('FAILURE NULL RES');failure();}_context.next=20;break;case 16:_context.prev=16;_context.t0=_context['catch'](7);console.log('FAILURE EXCEPTION',_context.t0);failure(_context.t0);case 20:_context.next=25;break;case 22:_context.prev=22;_context.t1=_context['catch'](0);console.error('Error handling:'+_context.t1);case 25:case'end':return _context.stop();}}},null,_this,[[0,22],[7,16]]);});}return NavigationStore;}(),(_descriptor=_applyDecoratedDescriptor(_class.prototype,'currentScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor2=_applyDecoratedDescriptor(_class.prototype,'prevScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor3=_applyDecoratedDescriptor(_class.prototype,'currentParams',[_mobx.observable],{enumerable:true,initializer:null}),_descriptor4=_applyDecoratedDescriptor(_class.prototype,'setState',[_mobx.action],{enumerable:true,initializer:function initializer(){var _this2=this;return function(newState){if(!newState){return;}_this2._state=newState;_this2.prevScene=_this2.currentScene;var state=_this2.currentState(_this2._state);_this2.currentScene=state.routeName;_this2.currentParams=state.params;};}})),_class);exports.default= diff --git a/package.json b/package.json index 242caa034..9f5eb9fca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-router-flux", - "version": "4.0.0-beta.7", + "version": "4.0.0-beta.8", "description": "React Native Router using Flux architecture", "repository": { "type": "git", @@ -9,7 +9,7 @@ "main": "dist/index.js", "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", - "postinstall": "opencollective postinstall", + "postinstall": "./node_modules/.bin/opencollective postinstall", "build": "babel src -d dist --presets react-native-stage-0/decorator-support", "test": "jest" }, @@ -19,13 +19,15 @@ "opencollective": "^1.0.3", "prop-types": "^15.5.10", "react-native-button": "^2.0.0", + "react-native-router-flux": "4.0.0-beta.7", "react-navigation": "^1.0.0-beta.11" }, "devDependencies": { "babel-jest": "20.0.3", "babel-preset-react-native": "2.0.0", "babel-preset-react-native-stage-0": "^1.0.1", - "eslint": "^3.0.0", + "eslint": "^3.2.0", + "eslint-plugin-jest": "^20.0.3", "jest": "20.0.4", "prettier-eslint": "^6.4.2", "prettier-eslint-cli": "^4.1.1", diff --git a/src/Router.js b/src/Router.js index ee93dd503..c18c462c9 100644 --- a/src/Router.js +++ b/src/Router.js @@ -63,21 +63,24 @@ function createTabBarOptions({ tabBarStyle, activeTintColor, inactiveTintColor, function createNavigationOptions(params) { const { title, backButtonImage, navTransparent, hideNavBar, hideTabBar, backTitle, right, rightButton, left, leftButton, navigationBarStyle, headerStyle, navBarButtonColor, tabBarLabel, tabBarIcon, icon, getTitle, renderTitle, panHandlers, - navigationBarTitleImage, navigationBarTitleImageStyle, - headerTitleStyle, titleStyle, navBar, onRight, onLeft, rightButtonImage, leftButtonImage, init, back, ...props } = params; + navigationBarTitleImage, navigationBarTitleImageStyle, component, rightTitle, leftTitle, leftButtonTextStyle, rightButtonTextStyle, + backButtonTextStyle, headerTitleStyle, titleStyle, navBar, onRight, onLeft, rightButtonImage, leftButtonImage, init, back, ...props } = params; const NavBar = navBar; + if (component && component.navigationOptions) { + return component.navigationOptions; + } return ({ navigation, screenProps }) => { const navigationParams = navigation.state.params || {}; const res = { ...props, headerTintColor: navBarButtonColor, headerTitleStyle: headerTitleStyle || titleStyle, - title: getValue((navigationParams.title) || title || getTitle, { navigation, ...navigationParams, ...screenProps }), - headerBackTitle: getValue((navigationParams.backTitle) || backTitle, { navigation, ...navigationParams, ...screenProps }), + title: getValue((navigationParams.title) || title || getTitle, { navigation, ...params, ...navigationParams, ...screenProps }), + headerBackTitle: getValue((navigationParams.backTitle) || backTitle, { navigation, ...params, ...navigationParams, ...screenProps }), headerRight: getValue((navigationParams.right) || right || rightButton || params.renderRightButton, { navigation, ...navigationParams, ...screenProps }), - headerLeft: getValue((navigationParams.left) || left || leftButton || params.renderLeftButton, { navigation, ...navigationParams, ...screenProps }), - headerTitle: getValue((navigationParams.renderTitle) || renderTitle || params.renderTitle, { navigation, ...navigationParams, ...screenProps }), - headerStyle: getValue((navigationParams.headerStyle || headerStyle || navigationBarStyle), { navigation, ...navigationParams, ...screenProps }), + headerLeft: getValue((navigationParams.left) || left || leftButton || params.renderLeftButton, { navigation, ...params, ...navigationParams, ...screenProps }), + headerTitle: getValue((navigationParams.renderTitle) || renderTitle || params.renderTitle, { navigation, ...params, ...navigationParams, ...screenProps }), + headerStyle: getValue((navigationParams.headerStyle || headerStyle || navigationBarStyle), { navigation, ...params, ...navigationParams, ...screenProps }), headerBackImage: navigationParams.backButtonImage || backButtonImage, }; if (NavBar) { @@ -100,14 +103,17 @@ function createNavigationOptions(params) { res.tabBarIcon = tabBarIcon || icon; } - if (rightButtonImage || onRight) { - res.headerRight = getValue((navigationParams.right) || right || rightButton || params.renderRightButton, + if (rightButtonImage || rightTitle || params.renderRightButton || onRight || navigationParams.onRight + || navigationParams.rightTitle || navigationParams.rightButtonImage) { + res.headerRight = getValue(navigationParams.right || right || rightButton || params.renderRightButton, { ...navigationParams, ...screenProps }) || renderRightButton({ ...params, ...navigationParams }); } - if (leftButtonImage || onLeft || backButtonImage) { - res.headerLeft = getValue((navigationParams.left) || left || leftButton || params.renderLeftButton, { ...navigationParams, ...screenProps }) - || renderLeftButton({ ...params, ...navigationParams }) || (init ? null : renderBackButton({ ...params, ...navigationParams })); + if (leftButtonImage || backButtonImage || backTitle || leftTitle || params.renderLeftButton || leftButtonTextStyle + || backButtonTextStyle || onLeft || navigationParams.leftTitle || navigationParams.onLeft || navigationParams.leftButtonImage + || navigationParams.backButtonImage || navigationParams.backTitle) { + res.headerLeft = getValue(navigationParams.left || left || leftButton || params.renderLeftButton, { ...params, ...navigationParams, ...screenProps }) + || renderLeftButton({ ...params, ...navigationParams }) || (init ? null : renderBackButton({ ...params, ...navigationParams, ...screenProps })); } if (back) { @@ -132,7 +138,9 @@ function createWrapper(Component) { if (!Component) { return null; } - return observer(({ navigation, ...props }) => ); + return observer(({ navigation, ...props }) => { + return + }); } @@ -170,6 +178,14 @@ function processScene(scene: Scene, inheritProps = {}, clones = []) { if (!drawer && !tabs) { children.push(...clones); } + // add all clones + for (const child of children) { + if (child.props.clone) { + if (clones.indexOf(child) === -1) { + clones.push(child); + } + } + } let initialRouteName; let initialRouteParams; for (const child of children) { @@ -178,11 +194,6 @@ function processScene(scene: Scene, inheritProps = {}, clones = []) { const init = key === children[0].key; assert(reservedKeys.indexOf(key) === -1, `Scene name cannot be reserved word: ${child.key}`); const { component, type = 'push', onEnter, onExit, on, failure, success, ...props } = child.props; - if (child.props.clone) { - if (clones.indexOf(child) === -1) { - clones.push(child); - } - } if (!navigationStore.states[key]) { navigationStore.states[key] = {}; } @@ -201,12 +212,11 @@ function processScene(scene: Scene, inheritProps = {}, clones = []) { // console.log(`KEY ${key} DRAWER ${drawer} TABS ${tabs} WRAP ${wrap}`, JSON.stringify(commonProps)); const screen = { screen: createWrapper(component) || processScene(child, commonProps, clones) || (lightbox && View), - navigationOptions: createNavigationOptions({ ...commonProps, ...child.props, init }), + navigationOptions: createNavigationOptions({ ...commonProps, ...component, ...child.props, init, component }), }; // wrap component inside own navbar for tabs/drawer parent controllers const wrapNavBar = drawer || tabs || wrap; - // console.log("SCENE:", key, wrapNavBar); if (component && wrapNavBar) { res[key] = { screen: processScene({ key, props: { children: { key: `_${key}`, props: child.props } } }, commonProps, clones) }; } else { diff --git a/src/navigationStore.js b/src/navigationStore.js index f2686c7ed..533aba367 100644 --- a/src/navigationStore.js +++ b/src/navigationStore.js @@ -60,11 +60,15 @@ class NavigationStore { _router = null; states = {}; reducer = null; - @observable _state; + _state; @observable currentScene = ''; @observable prevScene = ''; - @computed get state() { - return toJS(this._state); + @observable currentParams; + + get state() { + const scene = this.currentScene; + const params = this.currentParams; + return this._state; } set router(router) { @@ -128,16 +132,19 @@ class NavigationStore { dispatch = (cmd) => { this.setState(this.nextState(this.state, cmd)); + }; @action setState = (newState) => { - // don't allow duplicated scenes or null state - if (!newState || this.currentState(newState).routeName === this.currentScene) { + // don't allow null state + if (!newState) { return; } this._state = newState; this.prevScene = this.currentScene; - this.currentScene = this.currentState(this._state).routeName; + const state = this.currentState(this._state); + this.currentScene = state.routeName; + this.currentParams = state.params; }; run = (type = ActionConst.PUSH, routeName, actions, ...params) => { @@ -171,6 +178,8 @@ class NavigationStore { }; push = (routeName, ...params) => { + // NOTE: chokes on clones + // console.log("PARAMS:", JSON.stringify(params)); this.run(ActionConst.PUSH, routeName, null, ...params); }; diff --git a/yarn.lock b/yarn.lock index 96155663e..a45ccecc1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1619,7 +1619,11 @@ escope@^3.6.0: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint@^3.0.0, eslint@^3.19.0: +eslint-plugin-jest@^20.0.3: + version "20.0.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-20.0.3.tgz#ec15eba6ac0ab44a67ebf6e02672ca9d7e7cba29" + +eslint@^3.19.0, eslint@^3.2.0: version "3.19.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.19.0.tgz#c8fc6201c7f40dd08941b87c085767386a679acc" dependencies: @@ -3651,6 +3655,17 @@ react-native-drawer-layout@1.3.2: dependencies: react-native-dismiss-keyboard "1.0.0" +react-native-router-flux@4.0.0-beta.7: + version "4.0.0-beta.7" + resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-4.0.0-beta.7.tgz#51d61dfe6b70df7da97bf96d38b8b13d7ba1c52d" + dependencies: + mobx "^3.1.16" + mobx-react "^4.2.1" + opencollective "^1.0.3" + prop-types "^15.5.10" + react-native-button "^2.0.0" + react-navigation "^1.0.0-beta.11" + react-native-tab-view@^0.0.65: version "0.0.65" resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-0.0.65.tgz#b685ea3081ff7c96486cd997361026c407302c59"