SettingsScreen.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, {Component} from 'react';
  2. import Toast from '@remobile/react-native-toast';
  3. import ListItem from '../views/ListItem';
  4. import CommonTitleBar from '../views/CommonTitleBar';
  5. import StorageUtil from '../utils/StorageUtil';
  6. import {NavigationActions} from 'react-navigation';
  7. import {Dimensions, Image, StyleSheet, View} from 'react-native';
  8. const {width} = Dimensions.get('window');
  9. const soundImages = [
  10. require('../../images/ad2.png'),
  11. require('../../images/ad3.png'),
  12. require('../../images/ad4.png')
  13. ]
  14. export default class SettingsScreen extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. contactId: '',
  19. sendMsg: '',
  20. soundImage: soundImages[0]
  21. };
  22. this.soundImageIndex = 0;
  23. }
  24. render() {
  25. return (
  26. <View style={styles.container}>
  27. <CommonTitleBar nav={this.props.navigation} title={"设置"}/>
  28. <View style={styles.container}>
  29. <View style={{width: width, height: 20}}/>
  30. <ListItem icon={require('../../images/ic_settings.png')} text={"注销"} handleClick={() => {
  31. this.logout()
  32. }}/>
  33. <Image source={this.state.soundImage} style={styles.soundImage}/>
  34. </View>
  35. </View>
  36. );
  37. }
  38. componentDidMount() {
  39. this.interval = setInterval(() => {
  40. this.setState({soundImage: soundImages[(++this.soundImageIndex) % 3]}, () => {
  41. console.log(this.soundImageIndex);
  42. });
  43. }, 600);
  44. }
  45. componentWillUnmount() {
  46. this.interval && clearInterval(this.interval);
  47. }
  48. logout() {
  49. StorageUtil.set('hasLogin', {'hasLogin': false});
  50. Toast.showShortCenter('注销成功');
  51. const resetAction = NavigationActions.reset({
  52. index: 0,
  53. actions: [
  54. NavigationActions.navigate({routeName: 'Splash'})
  55. ]
  56. });
  57. this.props.navigation.dispatch(resetAction);
  58. }
  59. }
  60. const styles = StyleSheet.create({
  61. container: {
  62. flex: 1,
  63. flexDirection: 'column'
  64. },
  65. input: {
  66. width: width,
  67. },
  68. soundImage: {
  69. width: 30,
  70. height: 30
  71. }
  72. });