BlueWallet/screen/settings/GeneralSettings.js

97 lines
3 KiB
JavaScript
Raw Normal View History

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