application-amicale/screens/SettingsScreen.js

63 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-06-25 22:20:24 +02:00
import React from 'react';
2019-06-28 11:35:15 +02:00
import {Container, Content, Left, ListItem, Right, Text, List, CheckBox, Button} from "native-base";
2019-06-25 22:20:24 +02:00
import CustomHeader from "../components/CustomHeader";
import ThemeManager from '../utils/ThemeManager';
import i18n from "i18n-js";
2019-06-28 11:35:15 +02:00
import {NavigationActions, StackActions} from "react-navigation";
import CustomMaterialIcon from "../components/CustomMaterialIcon";
2019-06-25 22:20:24 +02:00
const nightModeKey = 'nightMode';
export default class SettingsScreen extends React.Component {
state = {
nightMode: ThemeManager.getInstance().getNightMode(),
};
toggleNightMode() {
this.setState({nightMode: !this.state.nightMode});
ThemeManager.getInstance().setNightmode(!this.state.nightMode);
2019-06-28 11:35:15 +02:00
// Alert.alert(i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.restart'));
this.resetStack();
}
2019-06-25 22:20:24 +02:00
2019-06-28 11:35:15 +02:00
resetStack() {
const resetAction = StackActions.reset({
index: 0,
key: null,
actions: [NavigationActions.navigate({ routeName: 'Main' })],
});
this.props.navigation.dispatch(resetAction);
this.props.navigation.navigate('Settings');
2019-06-25 22:20:24 +02:00
}
render() {
const nav = this.props.navigation;
return (
<Container>
<CustomHeader navigation={nav} title={i18n.t('screens.settings')}/>
<Content>
<List>
<ListItem
button
onPress={() => this.toggleNightMode()}
>
<Left>
2019-06-28 11:35:15 +02:00
<CustomMaterialIcon icon={'theme-light-dark'} />
2019-06-25 22:20:24 +02:00
<Text>
{i18n.t('settingsScreen.nightMode')}
</Text>
</Left>
<Right style={{flex: 1}}>
<CheckBox checked={this.state.nightMode}
onPress={() => this.toggleNightMode()}/>
</Right>
</ListItem>
</List>
</Content>
</Container>
);
}
}