BlueWallet/screen/settings/GeneralSettings.js

97 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-03-29 04:06:45 +02:00
import React, { useEffect, useState } from 'react';
import { ScrollView, Platform, TouchableWithoutFeedback, TouchableOpacity, StyleSheet } from 'react-native';
2020-09-22 03:53:28 +02:00
import { BlueLoading, BlueTextHooks, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard } from '../../BlueComponents';
2020-03-29 04:06:45 +02:00
import { AppStorage } from '../../class';
2020-07-15 19:32:59 +02:00
import { useNavigation, useTheme } from '@react-navigation/native';
2020-03-29 04:06:45 +02:00
import HandoffSettings from '../../class/handoff';
2020-07-20 15:38:46 +02:00
import loc from '../../loc';
const BlueApp: AppStorage = require('../../BlueApp');
2020-03-29 04:06:45 +02:00
const styles = StyleSheet.create({
root: {
flex: 1,
},
});
2020-03-29 04:06:45 +02:00
const GeneralSettings = () => {
const [isLoading, setIsLoading] = useState(true);
const [isAdancedModeEnabled, setIsAdancedModeEnabled] = useState(false);
const [isHandoffUseEnabled, setIsHandoffUseEnabled] = useState(false);
2020-03-29 18:46:22 +02:00
const { navigate } = useNavigation();
2020-07-15 19:32:59 +02:00
const { colors } = useTheme();
2020-03-29 04:06:45 +02:00
const onAdvancedModeSwitch = async value => {
await BlueApp.setIsAdancedModeEnabled(value);
setIsAdancedModeEnabled(value);
};
const onHandOffEnabledSwitch = async value => {
await HandoffSettings.setHandoffUseEnabled(value);
setIsHandoffUseEnabled(value);
};
useEffect(() => {
(async () => {
setIsAdancedModeEnabled(await BlueApp.isAdancedModeEnabled());
setIsHandoffUseEnabled(await HandoffSettings.isHandoffUseEnabled());
setIsLoading(false);
})();
});
2020-07-15 19:32:59 +02:00
const stylesWithThemeHook = {
root: {
...styles.root,
backgroundColor: colors.background,
},
scroll: {
...styles.scroll,
backgroundColor: colors.background,
},
scrollBody: {
...styles.scrollBody,
backgroundColor: colors.background,
},
};
2020-03-29 04:06:45 +02:00
return isLoading ? (
<BlueLoading />
) : (
2020-07-15 19:32:59 +02:00
<ScrollView style={stylesWithThemeHook.scroll}>
{BlueApp.getWallets().length > 1 && (
<>
2020-09-22 03:53:28 +02:00
<BlueListItem component={TouchableOpacity} onPress={() => navigate('DefaultView')} title={loc.settings.default_title} chevron />
2020-07-15 19:32:59 +02:00
</>
)}
{Platform.OS === 'ios' ? (
<>
2020-09-22 03:53:28 +02:00
<BlueListItem
2020-07-15 19:32:59 +02:00
hideChevron
2020-07-20 15:38:46 +02:00
title={loc.settings.general_continuity}
2020-07-15 19:32:59 +02:00
Component={TouchableWithoutFeedback}
switch={{ onValueChange: onHandOffEnabledSwitch, value: isHandoffUseEnabled }}
/>
<BlueCard>
2020-07-20 15:38:46 +02:00
<BlueTextHooks>{loc.settings.general_continuity_e}</BlueTextHooks>
2020-07-15 19:32:59 +02:00
</BlueCard>
<BlueSpacing20 />
</>
) : null}
2020-09-22 03:53:28 +02:00
<BlueListItem
2020-07-15 19:32:59 +02:00
Component={TouchableWithoutFeedback}
2020-07-20 15:38:46 +02:00
title={loc.settings.general_adv_mode}
2020-07-15 19:32:59 +02:00
switch={{ onValueChange: onAdvancedModeSwitch, value: isAdancedModeEnabled }}
/>
<BlueCard>
2020-07-20 15:38:46 +02:00
<BlueTextHooks>{loc.settings.general_adv_mode_e}</BlueTextHooks>
2020-07-15 19:32:59 +02:00
</BlueCard>
<BlueSpacing20 />
</ScrollView>
2020-03-29 04:06:45 +02:00
);
};
GeneralSettings.navigationOptions = () => ({
...BlueNavigationStyle(),
2020-07-20 15:38:46 +02:00
title: loc.settings.general,
2020-03-29 04:06:45 +02:00
});
export default GeneralSettings;