import React, {Component} from 'react'; import { StyleSheet, Text, View, Switch, Alert, Linking, TouchableOpacity, DeviceEventEmitter } from 'react-native'; import {Navigation} from 'react-native-navigation'; import Ionicons from 'react-native-vector-icons/Ionicons'; import Api from '../util/api'; import Token from '../util/token'; import Color from '../style/color'; export default class SettingPage extends Component { constructor(props) { super(props); this.state = { hasPassword: false, hasUpdateNews: false, settings: {} } } static options(passProps) { return { topBar: { title: { text: '设置' } } }; } componentDidMount() { this.refreshPasswordState(); this.passwordListener = DeviceEventEmitter.addListener('passwordUpdated', this.refreshPasswordState.bind(this)); } componentWillUnmount() { this.passwordListener.remove(); } refreshPasswordState() { Token.getLoginPassword() .then((pwd) => this.setState({ hasPassword: pwd != null && pwd.length > 0 })); }; changePassword = () => { let titleText = ''; if(!this.state.hasPassword) { titleText = '设置启动密码'; } else { titleText = '取消启动密码'; } Navigation.push(this.props.componentId, { component: { name: 'Password', options: { topBar: { title: { text: titleText } }, bottomTabs: { visible: false, // hide bottom tab for android drawBehind: true, animate: true } }, passProps: { type: 'setting', operation: !this.state.hasPassword ? 'setnew' : 'cancel' } } }); }; changePush = (val) => { // } jumpTo(pageName) { Navigation.push(this.props.componentId, { component: { name: pageName, options: { bottomTabs: { visible: false, // hide bottom tab for android drawBehind: true, animate: true } } } }); } logout() { Alert.alert('提示','确认退出登录?',[ {text: '退出', style: 'destructive', onPress: () => { Api.logout(); Navigation.setRoot({ root: { stack: { children: [{ component: { name: 'Timepill', options: { topBar: { visible: false, // hide top bar for android drawBehind: true, animate: true } } } }] } } }); }}, {text: '取消', onPress: () => {}} ]); } render() { return ( this.jumpTo('UserInfoEdit')}> 修改个人信息 启动密码 提醒推送 { Api.IS_IOS ? ( Linking.openURL("https://itunes.apple.com/us/app/jiao-nang-ri-ji/id1142102323?l=zh&ls=1&mt=8")} > 去 App Store 评价 ) : null } this.jumpTo('Feedback')}> 意见反馈 this.jumpTo('About')}> 关于 { this.state.hasUpdateNews ? ( 1 ) : null } 退出登录 ); } } const localStyle = StyleSheet.create({ wrap: { flex: 1, backgroundColor: '#EFEFF4' }, group: { marginTop: 30, backgroundColor: 'white', borderTopWidth: StyleSheet.hairlineWidth, borderBottomWidth: StyleSheet.hairlineWidth, borderColor: '#c8c7cc' }, item: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 15, height: 45 }, title: { fontSize: 16, color: '#222', flex: 1 }, line: { marginLeft: 15, borderBottomWidth: StyleSheet.hairlineWidth, borderColor: '#c8c7cc' }, arrow: { paddingTop: 1, color: Color.inactiveText }, button: { flex: 1, textAlign: 'center', color: '#d9534f', fontSize: 16 }, badge: { backgroundColor: 'red', paddingHorizontal:8, paddingVertical: 2, borderRadius: 12, marginRight: 10 }, badgeText: { color: 'white', fontSize: 12, fontFamily: 'Arial' } });