Browse Source

Update to work w/o redux integration.

Herby Vojčík 5 years ago
parent
commit
168e586225
3 changed files with 100 additions and 115 deletions
  1. 32 42
      index.js
  2. 67 70
      package-lock.json
  3. 1 3
      package.json

+ 32 - 42
index.js

@@ -1,62 +1,52 @@
 "use strict";
 
 import React, {Component} from 'react';
-import {
-    createReactNavigationReduxMiddleware,
-    createReduxBoundAddListener,
-    createNavigationReducer
-} from 'react-navigation-redux-helpers';
-import {connect} from 'react-redux';
-
-export const navigatorPieces = (BareNavigator, name = "root") => {
-    const middleware = createReactNavigationReduxMiddleware(name, x => x);
-    const addListener = createReduxBoundAddListener(name);
-    const reducer = createNavigationReducer(BareNavigator);
+
+import {NavigationActions, StackActions} from 'react-navigation';
+
+export default BareNavigator => {
+    let navigator, state;
+    const refNavigator = me => navigator = me;
+    const refState = (prevState, newState) => state = newState;
 
     class Navigator extends Component {
         render () {
-            const {dispatch, navigationState} = this.props;
             return <BareNavigator
-                navigation={{dispatch, state: navigationState, addListener}}
+                ref={refNavigator}
+                onNavigationStateChange={refState}
             />;
         }
     }
 
-    return {Navigator, reducer, middleware};
-};
+    const {navigate, back} = NavigationActions;
+    const {reset} = StackActions;
 
-export const connectNavigator = selectorFn => connect(state => ({navigationState: selectorFn(state)}));
+    const topOfNavigationStack = () => state.routes[state.routes.length - 1] || {};
+    const isRoute = expected => ({routeName}) => routeName === expected;
+    const isTopRoute = expected => isRoute(expected)(topOfNavigationStack());
 
-import {NavigationActions, StackActions} from 'react-navigation';
+    const navigationHelpers = {
+        topOfNavigationStack,
 
-const {navigate, back} = NavigationActions;
-const {reset} = StackActions;
+        navigate: (...args) => navigator.dispatch(navigate(...args)),
+        back: (...args) => navigator.dispatch(back(...args)),
+        reset: (...args) => navigator.dispatch(reset(...args)),
 
-export const backButtonHandler = ({dispatch, getState}) => {
-    if (getState().index === 0) return false;
-    dispatch(back());
-    return true;
-};
-
-const topOfNavigationStack = ({routes}) => routes[routes.length - 1] || {};
-const isRoute = expected => ({routeName}) => routeName === expected;
-const isTopRoute = expected => state => isRoute(expected)(topOfNavigationStack(state));
+        resetRoutes: routeNames => navigator.dispatch(reset({
+            actions: routeNames.map(routeName => navigate({routeName})),
+            index: routeNames.length - 1
+        })),
 
-export const navigationHelpers = {
-    topOfNavigationStack,
+        isRoute,
 
-    resetRoutes: routeNames => reset({
-        actions: routeNames.map(routeName => navigate({routeName})),
-        index: routeNames.length - 1
-    }),
+        isTopRoute,
 
-    isRoute,
+        goBackFrom: routeName => {
+            if (isTopRoute(routeName)) {
+                navigator.dispatch(back());
+            }
+        },
+    };
 
-    isTopRoute,
-
-    goBackFrom: routeName => ({dispatch, getState}) => {
-        if (isTopRoute(routeName)(getState())) {
-            dispatch(back());
-        }
-    },
+    return {Navigator, navigationHelpers};
 };

+ 67 - 70
package-lock.json

@@ -20,14 +20,19 @@
       "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY="
     },
     "create-react-context": {
-      "version": "0.2.2",
-      "resolved": "https://registry.npmjs.org/create-react-context/-/create-react-context-0.2.2.tgz",
-      "integrity": "sha512-KkpaLARMhsTsgp0d2NA/R94F/eDLbhXERdIq3LvX2biCAXcDvHYoOqHfWCHf1+OLj+HKBotLG3KqaOOf+C1C+A==",
+      "version": "0.2.3",
+      "resolved": "https://registry.npmjs.org/create-react-context/-/create-react-context-0.2.3.tgz",
+      "integrity": "sha512-CQBmD0+QGgTaxDL3OX1IDXYqjkp2It4RIbcb99jS6AEg27Ga+a9G3JtK6SIu0HBwPLZlmwt9F7UwWA4Bn92Rag==",
       "requires": {
         "fbjs": "0.8.16",
         "gud": "1.0.0"
       }
     },
+    "decode-uri-component": {
+      "version": "0.2.0",
+      "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
+      "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU="
+    },
     "encoding": {
       "version": "0.1.12",
       "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
@@ -68,14 +73,6 @@
         "safer-buffer": "2.1.2"
       }
     },
-    "invariant": {
-      "version": "2.2.4",
-      "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
-      "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==",
-      "requires": {
-        "loose-envify": "1.3.1"
-      }
-    },
     "is-stream": {
       "version": "1.1.0",
       "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
@@ -100,16 +97,6 @@
       "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
       "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls="
     },
-    "lodash": {
-      "version": "4.17.10",
-      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
-      "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
-    },
-    "lodash-es": {
-      "version": "4.17.10",
-      "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.10.tgz",
-      "integrity": "sha512-iesFYPmxYYGTcmQK0sL8bX3TGHyM6b2qREaB4kamHfQyfPJP0xgoGxp19nsH16nsfquLdiyKyX3mQkfiSGV8Rg=="
-    },
     "loose-envify": {
       "version": "1.3.1",
       "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
@@ -158,6 +145,15 @@
         "object-assign": "4.1.1"
       }
     },
+    "query-string": {
+      "version": "6.1.0",
+      "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.1.0.tgz",
+      "integrity": "sha512-pNB/Gr8SA8ff8KpUFM36o/WFAlthgaThka5bV19AD9PNTH20Pwq5Zxodif2YyHwrctp6SkL4GqlOot0qR/wGaw==",
+      "requires": {
+        "decode-uri-component": "0.2.0",
+        "strict-uri-encode": "2.0.0"
+      }
+    },
     "react-lifecycles-compat": {
       "version": "3.0.4",
       "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",
@@ -185,94 +181,90 @@
       }
     },
     "react-native-safe-area-view": {
-      "version": "0.7.0",
-      "resolved": "https://registry.npmjs.org/react-native-safe-area-view/-/react-native-safe-area-view-0.7.0.tgz",
-      "integrity": "sha512-SjLdW/Th0WVMhyngH4O6yC21S+O4U4AAG3QxBr7fZ2ftgjXSpKbDHAhEpxBdFwei6HsnsC2h9oYMtPpaW9nfGg==",
+      "version": "0.9.0",
+      "resolved": "https://registry.npmjs.org/react-native-safe-area-view/-/react-native-safe-area-view-0.9.0.tgz",
+      "integrity": "sha512-y792ScHMzvgwquxL869S9CER4dwiFu/TuCiXdy0xBtygmScMK4eWonnUT65LvOrsSSdr8o6XEK1mbI51h6ozvQ==",
       "requires": {
         "hoist-non-react-statics": "2.5.0"
       }
     },
     "react-native-tab-view": {
-      "version": "0.0.74",
-      "resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-0.0.74.tgz",
-      "integrity": "sha512-aCrLugxt5LqdSk0pHqu/nDGZMIM3NvxVcXb464coY7ecWgem6IxQ8riO3QXPJhXZ7HaayfofBJF9w4uIWt/AoQ==",
+      "version": "0.0.77",
+      "resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-0.0.77.tgz",
+      "integrity": "sha512-9vjD4Ly1Zlum1Y4g23ODpi/F3gYIUIsKWrsZO/Oh5cuX1eiB1DRVn11nY1z+j/hsQfhfyW6nDlmySyDvYQvYCA==",
       "requires": {
         "prop-types": "15.6.1"
       }
     },
     "react-navigation": {
-      "version": "2.0.1",
-      "resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-2.0.1.tgz",
-      "integrity": "sha512-J3AC+Lq3puxs9sEePopiKt/Hrxz8MBGDaLnq8G5Vx9s7xM0ILWtciudeT3+5hhMwxcGtpnmV86CTnaIjvCBYvQ==",
+      "version": "2.12.1",
+      "resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-2.12.1.tgz",
+      "integrity": "sha512-C+do+STPvvd/5LbaDhrZyf1P8tCeffttdlHyIRe1NgGg8Nj93FZHWOThi2hnmEZ75kXsS/JGxox4DDPqYVAxeQ==",
       "requires": {
         "clamp": "1.0.1",
-        "create-react-context": "0.2.2",
+        "create-react-context": "0.2.3",
         "hoist-non-react-statics": "2.5.0",
         "path-to-regexp": "1.7.0",
-        "prop-types": "15.6.1",
+        "query-string": "6.1.0",
         "react-lifecycles-compat": "3.0.4",
-        "react-native-drawer-layout-polyfill": "1.3.2",
-        "react-native-safe-area-view": "0.7.0",
-        "react-navigation-deprecated-tab-navigator": "1.2.0",
-        "react-navigation-tabs": "0.2.0"
+        "react-native-safe-area-view": "0.9.0",
+        "react-navigation-deprecated-tab-navigator": "1.3.0",
+        "react-navigation-drawer": "0.5.0",
+        "react-navigation-stack": "0.2.3",
+        "react-navigation-tabs": "0.6.0"
       }
     },
     "react-navigation-deprecated-tab-navigator": {
-      "version": "1.2.0",
-      "resolved": "https://registry.npmjs.org/react-navigation-deprecated-tab-navigator/-/react-navigation-deprecated-tab-navigator-1.2.0.tgz",
-      "integrity": "sha512-fAZ5W8gyMfEAOV1b+JYq9TenIGeouwaAw1LiPhJzcKmXAV0t3kNLLDvlRXSpzJw74fv9vO6g5SMDet89p9ALNw==",
+      "version": "1.3.0",
+      "resolved": "https://registry.npmjs.org/react-navigation-deprecated-tab-navigator/-/react-navigation-deprecated-tab-navigator-1.3.0.tgz",
+      "integrity": "sha512-Cm+qYOPFWbvvcuv0YYX0ioYwLGgw7XAqdhAfpo3sIr3trxRW8871ePmfFOPezjQtz4v6ItjZt6LPgtBAVZoroQ==",
       "requires": {
-        "react-native-tab-view": "0.0.74"
+        "react-native-tab-view": "0.0.77"
       }
     },
-    "react-navigation-redux-helpers": {
-      "version": "1.0.6",
-      "resolved": "https://registry.npmjs.org/react-navigation-redux-helpers/-/react-navigation-redux-helpers-1.0.6.tgz",
-      "integrity": "sha512-k4HHS/N//+z0h7HjlxIax88B6Sn24LTOWh0/oGc9LuTVK+lhdN5F23KHusjPHTUjny/O6jZlXBmkVpNPNE0anw==",
+    "react-navigation-drawer": {
+      "version": "0.5.0",
+      "resolved": "https://registry.npmjs.org/react-navigation-drawer/-/react-navigation-drawer-0.5.0.tgz",
+      "integrity": "sha512-F1y593uC6pqBMGH+Omz75oNODEbxB/s0EGO8QtYwu1NmOOEUuuLA+c14zm+pgMsI4HlDabiHxPkWqsgGz25xVQ==",
       "requires": {
-        "invariant": "2.2.4"
+        "react-native-drawer-layout-polyfill": "1.3.2"
       }
     },
+    "react-navigation-stack": {
+      "version": "0.2.3",
+      "resolved": "https://registry.npmjs.org/react-navigation-stack/-/react-navigation-stack-0.2.3.tgz",
+      "integrity": "sha512-xjVqiI/ztcQt45jxQ3vfO8Lr+9bVq+0J/lRhMdZCvCDwiyOVuB64wx7qPNJW16pnBBLiI5h6H7uhWE3rAT0r/w=="
+    },
     "react-navigation-tabs": {
-      "version": "0.2.0",
-      "resolved": "https://registry.npmjs.org/react-navigation-tabs/-/react-navigation-tabs-0.2.0.tgz",
-      "integrity": "sha512-dM7IJYKfMdMScgAIhBin2fOH7AbNGOcwO/BH3TFGQSDouM+nngJCsnAr1Gz/DharSil/njq7QKd6yTazS96mEw==",
+      "version": "0.6.0",
+      "resolved": "https://registry.npmjs.org/react-navigation-tabs/-/react-navigation-tabs-0.6.0.tgz",
+      "integrity": "sha512-Ax1rujJ51R1Jrz7b5bHUAIgsYC1VrFws+d3hxlPy5dXG84iJdV5dnDFRvdQMDDfDZc+NDx2a223lAYsc3p2+XA==",
       "requires": {
         "hoist-non-react-statics": "2.5.0",
         "prop-types": "15.6.1",
-        "react-lifecycles-compat": "1.1.4",
+        "react-lifecycles-compat": "3.0.4",
         "react-native-safe-area-view": "0.7.0",
-        "react-native-tab-view": "0.0.77"
+        "react-native-tab-view": "1.0.2"
       },
       "dependencies": {
-        "react-lifecycles-compat": {
-          "version": "1.1.4",
-          "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-1.1.4.tgz",
-          "integrity": "sha512-g3pdexIqkn+CVvSpYIoyON8zUbF9kgfhp672gyz7wQ7PQyXVmJtah+GDYqpHpOrdwex3F77iv+alq79iux9HZw=="
+        "react-native-safe-area-view": {
+          "version": "0.7.0",
+          "resolved": "https://registry.npmjs.org/react-native-safe-area-view/-/react-native-safe-area-view-0.7.0.tgz",
+          "integrity": "sha512-SjLdW/Th0WVMhyngH4O6yC21S+O4U4AAG3QxBr7fZ2ftgjXSpKbDHAhEpxBdFwei6HsnsC2h9oYMtPpaW9nfGg==",
+          "requires": {
+            "hoist-non-react-statics": "2.5.0"
+          }
         },
         "react-native-tab-view": {
-          "version": "0.0.77",
-          "resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-0.0.77.tgz",
-          "integrity": "sha512-9vjD4Ly1Zlum1Y4g23ODpi/F3gYIUIsKWrsZO/Oh5cuX1eiB1DRVn11nY1z+j/hsQfhfyW6nDlmySyDvYQvYCA==",
+          "version": "1.0.2",
+          "resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-1.0.2.tgz",
+          "integrity": "sha512-x8I43V1X7/AyMnIwnqJGMU54LqQRlV6vJ9irbls9asA/axdHIdxagPIV6Jx1ttFe/bPKhFwXL+lRYdYxGyUlWg==",
           "requires": {
             "prop-types": "15.6.1"
           }
         }
       }
     },
-    "react-redux": {
-      "version": "5.0.7",
-      "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-5.0.7.tgz",
-      "integrity": "sha512-5VI8EV5hdgNgyjfmWzBbdrqUkrVRKlyTKk1sGH3jzM2M2Mhj/seQgPXaz6gVAj2lz/nz688AdTqMO18Lr24Zhg==",
-      "requires": {
-        "hoist-non-react-statics": "2.5.0",
-        "invariant": "2.2.4",
-        "lodash": "4.17.10",
-        "lodash-es": "4.17.10",
-        "loose-envify": "1.3.1",
-        "prop-types": "15.6.1"
-      }
-    },
     "safer-buffer": {
       "version": "2.1.2",
       "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
@@ -283,6 +275,11 @@
       "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
       "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
     },
+    "strict-uri-encode": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz",
+      "integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY="
+    },
     "ua-parser-js": {
       "version": "0.7.18",
       "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz",

+ 1 - 3
package.json

@@ -18,8 +18,6 @@
   "author": "Herby Vojčík <herby@mailbox.sk>",
   "license": "MIT",
   "dependencies": {
-    "react-navigation": "^2.0.1",
-    "react-navigation-redux-helpers": "^1.0.6",
-    "react-redux": "^5.0.7"
+    "react-navigation": "^2.12.1"
   }
 }