Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit eae326c

Browse files
author
soliury
committed
add setting panel
1 parent 6243b38 commit eae326c

File tree

8 files changed

+243
-7
lines changed

8 files changed

+243
-7
lines changed

app/actions/UserActions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ exports.unLikeTopic = function (id) {
117117
id: id
118118
}
119119
}
120+
121+
122+
exports.logout = function () {
123+
UserService.storage.clearUser()
124+
return {
125+
type: types.LOGOUT
126+
}
127+
}

app/components/Setting.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
var React = require('react-native')
2+
var Modal = require('react-native-modal')
3+
var Button = require('react-native-button')
4+
var { Icon, } = require('react-native-icons')
5+
6+
7+
var window = require('../util/window')
8+
var { width, height } = window.get()
9+
10+
var {
11+
View,
12+
StyleSheet,
13+
ScrollView,
14+
Component,
15+
Text,
16+
StatusBarIOS,
17+
ActivityIndicatorIOS,
18+
TouchableOpacity
19+
} = React
20+
21+
22+
class Setting extends Component {
23+
constructor(props) {
24+
super(props)
25+
}
26+
27+
28+
onAboutPress() {
29+
30+
}
31+
32+
33+
onLogoutPress() {
34+
this.props.actions.logout()
35+
this.props.router.replaceWithHome()
36+
}
37+
38+
39+
onClearPress(){
40+
41+
}
42+
43+
44+
render() {
45+
return (
46+
<Modal
47+
style={modalStyles}
48+
//onPressBackdrop={() => this.props.closeModal()}
49+
hideCloseButton={true}
50+
backdropType='blur'
51+
backdropBlur='dark'
52+
isVisible={this.props.isModalOpen}
53+
onClose={() => this.props.closeModal()}>
54+
55+
<View style={styles.wrapper}>
56+
<View style={[styles.row,styles.header]}>
57+
<Icon
58+
name='ion|ios-gear'
59+
size={25}
60+
color='rgba(255,255,255,0.5)'
61+
style={styles.Icon}/>
62+
<Text style={styles.rowText}>
63+
设置
64+
</Text>
65+
</View>
66+
67+
68+
<TouchableOpacity onPress={this.onAboutPress.bind(this)}>
69+
<View style={[styles.row]}>
70+
<Icon
71+
name='ion|ios-eye'
72+
size={25}
73+
color='rgba(255,255,255,0.5)'
74+
style={styles.Icon}/>
75+
<Text style={styles.rowText}>
76+
关于
77+
</Text>
78+
</View>
79+
</TouchableOpacity>
80+
81+
<TouchableOpacity onPress={this.onClearPress.bind(this)}>
82+
<View style={[styles.row]}>
83+
<Icon
84+
name='ion|ios-trash'
85+
size={22}
86+
color='rgba(255,255,255,0.5)'
87+
style={styles.Icon}/>
88+
<Text style={styles.rowText}>
89+
清除缓存
90+
</Text>
91+
</View>
92+
</TouchableOpacity>
93+
94+
95+
<TouchableOpacity onPress={this.onLogoutPress.bind(this)}>
96+
<View style={[styles.row]}>
97+
<Icon
98+
name='ion|power'
99+
size={20}
100+
color='#E74C3C'
101+
style={styles.Icon}/>
102+
<Text style={[styles.rowText,styles.logoutText]}>
103+
退出
104+
</Text>
105+
</View>
106+
</TouchableOpacity>
107+
108+
</View>
109+
110+
111+
<TouchableOpacity onPress={() => this.props.closeModal()}>
112+
<Icon
113+
name='ion|ios-close-empty'
114+
size={34}
115+
color='rgba(255,255,255,0.9)'
116+
style={styles.closeIcon}/>
117+
</TouchableOpacity>
118+
</Modal>
119+
)
120+
}
121+
}
122+
123+
124+
var styles = StyleSheet.create({
125+
wrapper: {
126+
flexDirection: 'column',
127+
alignItems: 'center',
128+
justifyContent: 'center',
129+
backgroundColor: 'rgba(0,0,0,0.3)',
130+
borderRadius: 3,
131+
margin: 30,
132+
width: width - 30 * 2
133+
},
134+
row: {
135+
height: 40,
136+
flexDirection: 'row',
137+
justifyContent: 'flex-start',
138+
alignItems: 'center',
139+
borderRadius: 2,
140+
paddingLeft: 20,
141+
width: width - 30 * 2,
142+
backgroundColor: 'rgba(0,0,0,0.1)'
143+
},
144+
rowText: {
145+
paddingLeft: 20,
146+
color: 'rgba(255,255,255,0.7)'
147+
},
148+
logoutText: {
149+
color: '#E74C3C'
150+
},
151+
header: {
152+
backgroundColor: 'rgba(0,0,0,0.5)'
153+
},
154+
Icon: {
155+
height: 20,
156+
width: 20
157+
},
158+
closeIcon: {
159+
height: 30,
160+
width: 30,
161+
borderRadius: 30 / 2,
162+
borderColor: 'rgba(255,255,255,0.2)',
163+
borderWidth: 2
164+
}
165+
})
166+
167+
var modalStyles = StyleSheet.create({
168+
container: {
169+
position: 'absolute',
170+
top: 0,
171+
bottom: 0,
172+
left: 0,
173+
right: 0,
174+
backgroundColor: 'transparent',
175+
justifyContent: 'center',
176+
},
177+
backdrop: {
178+
position: 'absolute',
179+
top: 0,
180+
bottom: 0,
181+
left: 0,
182+
right: 0,
183+
backgroundColor: '#000000',
184+
opacity: 0.5,
185+
},
186+
modal: {
187+
flexDirection: 'column',
188+
alignItems: 'center',
189+
justifyContent: 'center'
190+
}
191+
})
192+
193+
194+
module.exports = Setting

app/configs/Router.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class Router {
7676
sceneConfig: Navigator.SceneConfigs.FloatFromBottom
7777
})
7878
}
79+
80+
replaceWithHome(){
81+
this.navigator.popToTop()
82+
}
7983
}
8084

8185
module.exports = Router

app/constants/ActionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exports.CHECK_TOKEN_REQUREST = 'CHECK_TOKEN_REQUREST'
1313
exports.CHECK_TOKEN_FAILED = 'CHECK_TOKEN_FAILED'
1414
exports.LIKE_TOPIC = 'LIKE_TOPIC'
1515
exports.UN_LIKE_TOPIC = 'UN_LIKE_TOPIC'
16+
exports.LOGOUT='LOGOUT'
1617

1718

1819
exports.GET_UNREAD_MESSAGE_COUNT_SUCCESS = 'GET_UNREAD_MESSAGE_COUNT_SUCCESS'

app/containers/User.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var { Icon, } = require('react-native-icons')
99
var UserTopicPage = require('../components/UserTopicPage')
1010
var Return = require('../components/overlay/Return')
1111
var TabBar = require('../components/TabBar')
12+
var Setting = require('../components/Setting')
1213

1314

1415
var genColor = require('../util/genColor')
@@ -40,7 +41,8 @@ class User extends Component {
4041
this.state = {
4142
userInfo: null,
4243
wallColor: genColor(),
43-
didFocus: false
44+
didFocus: false,
45+
isSettingModalOpen: false
4446
}
4547
}
4648

@@ -69,6 +71,20 @@ class User extends Component {
6971
}
7072

7173

74+
onSettingModalClosePress() {
75+
this.setState({
76+
isSettingModalOpen: false
77+
})
78+
}
79+
80+
81+
onSettingIconPress() {
82+
this.setState({
83+
isSettingModalOpen: true
84+
})
85+
}
86+
87+
7288
_getUserInfo() {
7389
let userName = this.props.userName
7490

@@ -169,7 +185,9 @@ class User extends Component {
169185
)
170186

171187
let settingIcon = (
172-
<TouchableOpacity>
188+
<TouchableOpacity
189+
onPress={this.onSettingIconPress.bind(this)}
190+
>
173191
<Icon
174192
name='ion|ios-gear'
175193
size={34}
@@ -219,6 +237,14 @@ class User extends Component {
219237
{this._renderUserTopics(userInfo)}
220238

221239
<Return router={this.props.router}></Return>
240+
241+
242+
<Setting
243+
actions={this.props.actions}
244+
router={this.props.router}
245+
isModalOpen={this.state.isSettingModalOpen}
246+
closeModal={this.onSettingModalClosePress.bind(this)}
247+
></Setting>
222248
</View>
223249
)
224250
}

app/reducers/user.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,25 @@ module.exports = function (state, action) {
2626
case types.GET_USER:
2727
return action.user
2828

29+
2930
case types.FETCH_USER:
3031
return action.user
3132

33+
3234
case types.LIKE_TOPIC:
3335
return {
3436
...state,
3537
collect_topics: [action.topic].concat(state.collect_topics)
3638
}
3739

40+
3841
case types.UN_LIKE_TOPIC:
3942
return unLikeTopic(state, action.id)
4043

44+
45+
case types.LOGOUT:
46+
return null
47+
4148
default:
4249
return state
4350
}

iOS/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3131
* on the same Wi-Fi network.
3232
*/
3333

34-
jsCodeLocation = [NSURL URLWithString:@"http://192.168.31.142:8081/index.ios.bundle"];
34+
jsCodeLocation = [NSURL URLWithString:@"http://192.168.0.100:8081/index.ios.bundle"];
3535

3636
/**
3737
* OPTION 2

noder.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; };
1110
00E356F31AD99517003FC87E /* noderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* noderTests.m */; };
1211
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
1312
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
@@ -174,7 +173,6 @@
174173
/* End PBXContainerItemProxy section */
175174

176175
/* Begin PBXFileReference section */
177-
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = "<group>"; };
178176
00E356EE1AD99517003FC87E /* noderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = noderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
179177
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
180178
00E356F21AD99517003FC87E /* noderTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = noderTests.m; sourceTree = "<group>"; };
@@ -265,7 +263,6 @@
265263
13B07FAE1A68108700A75B9A /* noder */ = {
266264
isa = PBXGroup;
267265
children = (
268-
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
269266
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
270267
13B07FB01A68108700A75B9A /* AppDelegate.m */,
271268
13B07FB51A68108700A75B9A /* Images.xcassets */,
@@ -764,7 +761,6 @@
764761
9EC98E8D1B0DC2D6006A460D /* foundation-icons.ttf in Resources */,
765762
9EC98E8E1B0DC2D6006A460D /* ionicons.ttf in Resources */,
766763
9EC98E8F1B0DC2D6006A460D /* zocial-regular-webfont.ttf in Resources */,
767-
008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */,
768764
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
769765
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
770766
);

0 commit comments

Comments
 (0)