-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwipeNavigationPage.js
149 lines (146 loc) · 5.74 KB
/
SwipeNavigationPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import React, { Component } from 'react';
import { View, TouchableOpacity, Text} from 'react-native';
import Swiper from 'react-native-swiper';
import ArrowPage from './ArrowPage';
import ExplorePage from './ExplorePage';
import Icon from 'react-native-vector-icons/Feather';
import { scale } from 'react-native-size-matters';
import { decorate, observable, toJS, autorun, computed, reaction } from 'mobx';
import { observer, inject } from 'mobx-react';
import { onSnapshot } from 'mobx-state-tree';
import PlaceInfoIcon from 'react-native-vector-icons/SimpleLineIcons';
import PlaceIcon from 'react-native-vector-icons/MaterialIcons';
import SwipeNavigationPageModel from './SwipeNavigationPageModel';
import * as Animatable from 'react-native-animatable';
import ArrowPageModel from './ArrowPageModel';
class SwipeNavigationPage extends Component {
static values = {
iconSize: 25
}
static navigationOptions = ({ navigation }) => {
const { state } = navigation;
const title = state.params ? `${state.params.title}` : 'Arrow';
return {
title,
headerRight: SwipeNavigationPage.headerRight(title, navigation),
};
};
static headerRight(title, navigation) {
const { iconSize } = SwipeNavigationPage.values;
return title === 'Arrow' ? (
<View
style={{
alignItems: 'center',
justifyContent: 'space-evenly',
width: scale(100),
height: '100%',
flexDirection: 'row',
paddingRight: scale(6),
}}
>
{this.renderPlaceInfoButton(navigation, iconSize)}
<TouchableOpacity
onPress={() => {
navigation.navigate('Settings');
}}
>
<Icon
name={'settings'}
size={iconSize}
style={{ width: iconSize, height: iconSize }}
/>
</TouchableOpacity>
</View>
)
:
null;
}
static renderPlaceButton(navigation, iconSize) {
const shouldRender = ArrowPageModel.getInstance().isShowingDirection;
return shouldRender ? (
<TouchableOpacity
onPress={() => {
navigation.navigate('Place');
}}
>
<PlaceIcon
name={'place'}
size={iconSize}
style={{ width: iconSize, height: iconSize }}
/>
</TouchableOpacity>
) : (
<View style={{ width: iconSize, height: iconSize }} /> // render empty on the area so that settings button don't replaces itself
);
}
static renderPlaceInfoButton(navigation, iconSize) {
const shouldRender = SwipeNavigationPageModel.getInstance().showPlaceInfoButton;
return shouldRender ? (
<Animatable.View ref={(ref) => SwipeNavigationPage.animateAndDisappear(ref)} >
<TouchableOpacity
onPress={() => {
navigation.navigate('Place');
}}
>
<PlaceInfoIcon
name={'info'}
size={iconSize}
style={{ width: iconSize, height: iconSize }}
/>
</TouchableOpacity>
</Animatable.View>
)
:
SwipeNavigationPage.renderPlaceButton(navigation, iconSize);
}
static avoidCancel = [];
static animateAndDisappear(ref) {
if (ref) {
const avoidCancel = SwipeNavigationPage.avoidCancel;
avoidCancel.push(ref);
ref.flash(2000).then((fulfilled) => {
console.log('fulfilled: ' + JSON.stringify(fulfilled));
});
ref.bounceIn(3000).then(() => {
setTimeout(() => {
const index = avoidCancel.indexOf(ref);
avoidCancel.splice(index, 1);
if (avoidCancel.length === 0) { // cancel with time only when it has not already been cancelled by long hold on new item
SwipeNavigationPageModel.getInstance().showPlaceInfoButton = false;
}
}, 1500);
});
}
}
render() {
return (
<Swiper
loop={false}
// showsPagination={false}
index={1}
onIndexChanged={(index) => {
if (index === 0) {
// this.changeTitle('Explore');
this.props.swipeNavigationPageModel.title = 'Explore';
} else {
// this.changeTitle('Arrow');
this.props.swipeNavigationPageModel.title = 'Arrow';
}
}}
keyboardDismissMode={'none'} //
keyboardShouldPersistTaps={'handled'}
scrollEnabled={this.props.swipeNavigationPageModel.scrollEnabled}
>
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }} >
<Text>left</Text>
</View>
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }} >
<Text>right</Text>
</View>
</Swiper>
);
}
}
// <ExplorePage />
// <ArrowPage navigation={this.props.navigation} />
export default inject('swipeNavigationPageModel', 'arrowPageModel')(observer(SwipeNavigationPage));