Skip to content

Commit 52f3ff0

Browse files
committed
@1.6.4 fix backOnSwipeRight
1 parent 12ba64f commit 52f3ff0

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

dist/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var Navigator = function (_React$Component) {
7171
startPage: startPage,
7272
mobileMode: mobileMode,
7373
swipeRight_x: 0,
74+
swipeRightStart_x: 0,
7475
props: []
7576
};
7677

@@ -330,7 +331,6 @@ var Navigator = function (_React$Component) {
330331
value: function render() {
331332
var _this4 = this;
332333

333-
// debugger
334334
var fthis = this;
335335
// window.navigation_controller = this;
336336
var nowPage = this.state.historyPages[this.state.historyPages.length - 1];
@@ -353,12 +353,18 @@ var Navigator = function (_React$Component) {
353353
return _react2.default.createElement(
354354
'div',
355355
{
356-
onTouchStart: function onTouchStart(e) {
357-
if (child.props.backOnSwipeRight) {
356+
// onTouchStart={(e) => {
357+
358+
359+
// }}
360+
361+
362+
onTouchMove: function onTouchMove(e) {
363+
if (child.props.backOnSwipeRight && !fthis.swipeRight) {
358364
if (e.touches[0].clientX < 0.20 * innerWidth) {
359365
fthis.touchBackPage = nowPage;
360366
fthis.swipeRight = true;
361-
fthis.setState({ swipeRight_x: e.touches[0].clientX });
367+
fthis.setState({ swipeRightStart_x: e.touches[0].clientX });
362368

363369
var goToPage = _this4.state.historyPages[_this4.state.historyPages.length - 2];
364370

@@ -368,10 +374,8 @@ var Navigator = function (_React$Component) {
368374
(0, _jquery2.default)('#' + goToPage).addClass('showPage overflow_Y_hidden');
369375
}
370376
}
371-
},
372-
onTouchMove: function onTouchMove(e) {
373377
if (fthis.swipeRight) {
374-
fthis.setState({ swipeRight_x: e.touches[0].clientX });
378+
fthis.setState({ swipeRight_x: e.touches[0].clientX - fthis.state.swipeRightStart_x <= 0 ? 1 : e.touches[0].clientX - fthis.state.swipeRightStart_x });
375379
}
376380
},
377381
onTouchEnd: function onTouchEnd(e) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react.cordova-navigation_controller",
3-
"version": "1.6.3",
3+
"version": "1.6.4",
44
"description": "Navigator for Cordova with React.js(react.cordova), This will help you to manage your pages history in the app and change pages with animation.",
55
"main": "dist/index.js",
66
"scripts": {

src/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default class Navigator extends React.Component {
5858
startPage: startPage,
5959
mobileMode: mobileMode,
6060
swipeRight_x: 0,
61+
swipeRightStart_x: 0,
6162
props: []
6263
}
6364

@@ -338,7 +339,7 @@ export default class Navigator extends React.Component {
338339
}
339340

340341
render() {
341-
// debugger
342+
342343
const fthis = this;
343344
// window.navigation_controller = this;
344345
const nowPage = this.state.historyPages[this.state.historyPages.length - 1];
@@ -361,12 +362,18 @@ export default class Navigator extends React.Component {
361362
return Array.isArray(this.props.children)
362363
? this.props.children.map(child => {
363364
return <div
364-
onTouchStart={(e) => {
365-
if (child.props.backOnSwipeRight) {
365+
// onTouchStart={(e) => {
366+
367+
368+
// }}
369+
370+
371+
onTouchMove={(e) => {
372+
if (child.props.backOnSwipeRight &&!fthis.swipeRight) {
366373
if (e.touches[0].clientX < (0.20 * innerWidth)) {
367374
fthis.touchBackPage = nowPage;
368375
fthis.swipeRight = true;
369-
fthis.setState({ swipeRight_x: e.touches[0].clientX });
376+
fthis.setState({ swipeRightStart_x: e.touches[0].clientX });
370377

371378
const goToPage = this.state.historyPages[this.state.historyPages.length - 2];
372379

@@ -377,10 +384,8 @@ export default class Navigator extends React.Component {
377384
}
378385

379386
}
380-
}}
381-
onTouchMove={(e) => {
382-
if (fthis.swipeRight) {
383-
fthis.setState({ swipeRight_x: e.touches[0].clientX });
387+
if (fthis.swipeRight) {
388+
fthis.setState({ swipeRight_x: (e.touches[0].clientX - fthis.state.swipeRightStart_x) <= 0 ? 1 : e.touches[0].clientX - fthis.state.swipeRightStart_x });
384389
}
385390
}}
386391
onTouchEnd={(e) => {

0 commit comments

Comments
 (0)