Skip to content

Commit f551f49

Browse files
committed
v2
1 parent 5e0d00b commit f551f49

20 files changed

+2325
-720
lines changed

README.md

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,60 @@ options = { animatioPageIn:"fadeInRight" // have defult
6666
## use with react-router
6767
```
6868
import React from "react";
69-
7069
import Navigator from "react.cordova-navigation_controller";
7170
72-
import { BrowserRouter as Router, Route, useParams } from "react-router-dom";
71+
//import all pages
72+
import Home from "../pages/index";
73+
import Page2 from "../pages/page2";
74+
75+
// #Hooks
76+
import {
77+
BrowserRouter,
78+
HashRouter,
79+
Route,
80+
useParams,
81+
} from "react-router-dom";
82+
import { createBrowserHistory } from "history";
83+
84+
// ## use history
85+
const history = createBrowserHistory();
86+
87+
const useRouter = (props) => {
88+
let Router = BrowserRouter;
89+
if (window.cordova.platformId !== "browser") Router = HashRouter;
7390
74-
export default function Root() {
7591
return (
76-
<Router>
92+
<Router
93+
history={history}
94+
>
7795
<Route path={["/:key", "/"]}>
78-
<App />
96+
<UseNavigator {...props} />
7997
</Route>
8098
</Router>
8199
);
82-
}
100+
};
83101
84-
const App = (props) => {
85-
const { key } = useParams();
102+
const UseNavigator = (props) => {
103+
// # init navigator ref
104+
let navigatorRef = undefined;
86105
106+
const { key } = useParams();
107+
// let query = useQuery();
87108
return (
88-
<Navigator routerKey={key} changeRoute={false}>
89-
<HomePage key="home" levelPage={0} />
90-
91-
<Page2 key="page2" levelPage={1} />
92-
</Navigator>
109+
<div>
110+
<Navigator
111+
routeKey={key}
112+
changeRoute={false}
113+
>
114+
<Home key="home" levelPage={0}/>
115+
<Page2 key="page2" levelPage={1}/>
116+
</Navigator>
117+
</div>
93118
);
94119
};
120+
121+
export default useRouter;
122+
95123
```
96124

97125

@@ -113,7 +141,7 @@ const App = (props) => {
113141
<tr>
114142
<td>onRef</td>
115143
<td></td>
116-
<td>required</td>
144+
<td></td>
117145
<td>-</td>
118146
<td> onRef={ref => (this.navigatorRef = ref)} </td>
119147
</tr>
@@ -148,7 +176,7 @@ const App = (props) => {
148176
<tr>
149177
<td>key</td>
150178
<td>string</td>
151-
<td>required</td>
179+
<td>optional</td>
152180
<td>-</td>
153181
<td></td>
154182
</tr>

dist/constructor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";

dist/hooks/changePage.js

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8+
9+
var changePage = function changePage(goToPage, options) {
10+
var fthis = undefined;
11+
try {
12+
if (goToPage && undefined.props.children.filter(function (x) {
13+
return x.key === goToPage;
14+
}).length === 0) {
15+
if (fthis.props.errorPageKey) {
16+
goToPage = fthis.props.errorPageKey;
17+
} else {
18+
goToPage = undefined.state.homePageKey;
19+
}
20+
console.error("goToPage ", goToPage, " undefined");
21+
fthis.onError("page undefined");
22+
}
23+
24+
//סיום האפליקציה, סגור
25+
if (undefined.state.historyPages.length === 1 && goToPage === undefined) {
26+
console.log('"window.navigator.app.exitApp()"');
27+
// fthis.showSwalLater ?
28+
// fthis.myChildrens.swal.runSwal(true) :
29+
if (undefined.props.beforExit) if (!undefined.props.beforExit()) return;
30+
window.navigator.app.exitApp();
31+
return;
32+
}
33+
34+
if (goToPage === undefined) {
35+
console.error("navigator error: changePage function need goToPage parameter.");
36+
return;
37+
}
38+
39+
if (fthis.listLevelPages[goToPage] === undefined) {
40+
console.error("navigator error, at changePage. goToPage parameter not found in the pages list.");
41+
return;
42+
}
43+
44+
undefined.props.children.filter(function (child) {
45+
return (typeof child === "undefined" ? "undefined" : _typeof(child)) === "object";
46+
}).forEach(function (child) {
47+
if (child.props.kill) {
48+
fthis.historyPages = fthis.historyPages.filter(function (x) {
49+
return x !== child.key;
50+
});
51+
}
52+
});
53+
54+
undefined.setState({ historyPages: undefined.historyPages });
55+
56+
var fromPage = "" + undefined.historyPages[undefined.historyPages.length - 1] + "";
57+
58+
var aniTime = 250;
59+
60+
if (undefined.props.children.filter(function (x) {
61+
return x.key === goToPage;
62+
})[0].props.animationTimeInMS) {
63+
aniTime = undefined.props.children.filter(function (x) {
64+
return x.key === goToPage;
65+
})[0].props.animationTimeInMS;
66+
} else {
67+
if (undefined.props.animationTimeInMS) aniTime = undefined.props.animationTimeInMS;
68+
}
69+
70+
options = options === undefined ? [] : options;
71+
72+
var _options = options,
73+
_options$props = _options.props,
74+
props = _options$props === undefined ? null : _options$props,
75+
_options$animationIn = _options.animationIn,
76+
animationIn = _options$animationIn === undefined ? undefined.componentTransitionIn[goToPage] ? undefined.componentTransitionIn[goToPage] : null : _options$animationIn,
77+
_options$timeAnimatio = _options.timeAnimationInMS,
78+
timeAnimationInMS = _options$timeAnimatio === undefined ? aniTime : _options$timeAnimatio,
79+
_options$animationOut = _options.animationOut,
80+
animationOut = _options$animationOut === undefined ? undefined.swipeRight ? "slideOutRight" : undefined.componentTransitionOut[fromPage] ? undefined.componentTransitionOut[fromPage] : null : _options$animationOut,
81+
_options$callbackFun = _options.callbackFun,
82+
callbackFun = _options$callbackFun === undefined ? null : _options$callbackFun;
83+
84+
85+
if (props !== null) {
86+
// let oldProps = this.state.props;
87+
var newProps = [];
88+
newProps[goToPage] = props;
89+
undefined.setState({ props: newProps });
90+
} else {}
91+
92+
if (!undefined.busy) {
93+
// const fthis = this;
94+
95+
//--animation time defult
96+
var timeAnimation = timeAnimationInMS; //param.timeAnimationInMS !== undefined && param.timeAnimationInMS !== null ? param.timeAnimationInMS :
97+
// 250; //ms
98+
99+
if (goToPage !== fromPage) {
100+
//---ניהול חזרות----//
101+
undefined.busy = true;
102+
103+
///שמור היסטוריה
104+
var new_historyPages = undefined.state.historyPages.slice();
105+
106+
if (undefined.listLevelPages[goToPage] <= undefined.listLevelPages[fromPage]) {
107+
//חוזרים אחורה, מחק את כל הדפים שהרמה שלהם גבוהה משלי.
108+
//new_historyPages.splice(new_historyPages.length - 1, 1);
109+
new_historyPages = new_historyPages.filter(function (x) {
110+
return undefined.listLevelPages[x] < undefined.listLevelPages[goToPage];
111+
});
112+
}
113+
new_historyPages.push(goToPage);
114+
//שמירת שינויים בהיסטוריה
115+
undefined.setState({ historyPages: new_historyPages });
116+
117+
if (undefined.state.changeRoute) {
118+
window.location.href = window.location.href.substr(0, window.location.href.lastIndexOf("/") + 1) + "#" + (goToPage !== undefined.state.homePageKey ? goToPage : "");
119+
}
120+
121+
//----navigator and animation----///
122+
123+
if (undefined.listLevelPages[goToPage] > undefined.listLevelPages[fromPage]) {
124+
//--נכנסים דף פנימה Up--//
125+
undefined.funAnimationIn1(goToPage, fromPage);
126+
127+
if (undefined.listLevelPages[goToPage] === 1) {
128+
//Up from level 0 to level 1
129+
console.log("goToPage: ", goToPage);
130+
// debugger
131+
$("#" + goToPage).css("animation", (animationIn !== null && animationIn !== undefined ? animationIn : "slideInRight") + " " + timeAnimation + "ms");
132+
} else {
133+
//else if (this.listLevelPages[goToPage] === 2) {
134+
//Up from level 1 to level 2
135+
$("#" + goToPage).css("animation", (animationIn !== null && animationIn !== undefined ? animationIn : "zoomIn") + " " + timeAnimation + "ms");
136+
}
137+
} else {
138+
//--חזרה בדפים Down--//
139+
undefined.funAnimationOut1(goToPage, fromPage);
140+
if (undefined.listLevelPages[fromPage] === 1) {
141+
//Down from level 1 to level 0
142+
$("#" + fromPage).css("animation", (animationOut !== null && animationOut !== undefined ? animationOut : "slideOutRight") + " " + timeAnimation + "ms");
143+
} else {
144+
//else if (this.listLevelPages[goToPage] === 1) {
145+
//Down from level 2 to level 1
146+
$("#" + fromPage).css("animation", (animationOut !== null && animationOut !== undefined ? animationOut : "zoomOut") + " " + timeAnimation + "ms");
147+
}
148+
}
149+
// //עיצוב כפתור חזרה
150+
// if (goToPage === "home") {
151+
// $('#navigatorBack').css('display', "none");
152+
// } else {
153+
// $('#navigatorBack').css('display', "flex");
154+
// }
155+
156+
if (callbackFun !== undefined && callbackFun !== null) callbackFun();
157+
}
158+
}
159+
} catch (error) {
160+
console.error(error);
161+
debugger;
162+
return;
163+
fthis.onError(error);
164+
}
165+
};
166+
167+
exports.default = changePage;

0 commit comments

Comments
 (0)