-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMore_bak.js
101 lines (88 loc) · 2.67 KB
/
More_bak.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
import React, {Component} from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity, DeviceEventEmitter,
} from 'react-native';
import BaseComponent from "./BaseComponent";
import StorageOpt from "./StorageOpt";
const EVENT_NAME = "listener_register_login";
export default class More_bak extends BaseComponent {
static EVENT_NAME = "listener_register_login";
static navigationOptions = {
title: "更多"
};
constructor(props) {
super(props);
this.state={
username:""
}
}
componentWillMount() {
super.componentWillMount();
StorageOpt.loaddata("username", (result) => {
this.setState({
username: result
});
});
}
componentDidMount() {
this.listener = DeviceEventEmitter.addListener(EVENT_NAME, () => {
console.log("more listener");
StorageOpt.loaddata("username", (result) => {
this.setState({
username: result
});
});
});
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.listener) {
this.listener.remove();
}
}
_onNavigateDuanzi = () => {
this.props.navigation.navigate("Duanzi");
};
_onRegisterLogin = () => {
if (this.state.username === "") {
this.props.navigation.navigate("RegisterLogin");
}
};
_onNavigateCollect = () => {
if (this.state.username === "") {
this.props.navigation.navigate("RegisterLogin");
} else {
this.props.navigation.navigate("Collect");
}
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.button} onPress={this._onNavigateDuanzi}>
<Text style={{color:'white'}}>段 子</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this._onRegisterLogin}>
<Text style={{color:'white'}}>{this.state.username === "" ? "注册登录" : "已登录(" + this.state.username + ")"}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this._onNavigateCollect}>
<Text style={{color:'white'}}>我的收藏</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
button: {
alignItems: 'flex-start',
backgroundColor: 'gray',
padding: 10,
marginTop: 20
}
});