-
-
Notifications
You must be signed in to change notification settings - Fork 671
Expand file tree
/
Copy pathSettingsScreen.js
More file actions
100 lines (94 loc) · 3.2 KB
/
Copy pathSettingsScreen.js
File metadata and controls
100 lines (94 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* @flow strict-local */
import React, { useCallback } from 'react';
import type { Node } from 'react';
import type { RouteProp } from '../react-navigation';
import type { AppNavigationProp } from '../nav/AppNavigator';
import { useGlobalSelector, useDispatch } from '../react-redux';
import { getGlobalSettings } from '../selectors';
import NestedNavRow from '../common/NestedNavRow';
import InputRowRadioButtons from '../common/InputRowRadioButtons';
import SwitchRow from '../common/SwitchRow';
import Screen from '../common/Screen';
import {
IconDiagnostics,
IconNotifications,
IconLanguage,
IconMoreHorizontal,
} from '../common/Icons';
import { setGlobalSettings } from '../actions';
import { shouldUseInAppBrowser } from '../utils/openLink';
type Props = $ReadOnly<{|
navigation: AppNavigationProp<'settings'>,
route: RouteProp<'settings', void>,
|}>;
export default function SettingsScreen(props: Props): Node {
const theme = useGlobalSelector(state => getGlobalSettings(state).theme);
const browser = useGlobalSelector(state => getGlobalSettings(state).browser);
const markMessagesReadOnScroll = useGlobalSelector(
state => getGlobalSettings(state).markMessagesReadOnScroll,
);
const dispatch = useDispatch();
const { navigation } = props;
const handleThemeChange = useCallback(() => {
dispatch(setGlobalSettings({ theme: theme === 'default' ? 'dark' : 'default' }));
}, [theme, dispatch]);
return (
<Screen title="Settings">
<SwitchRow label="Dark theme" value={theme === 'dark'} onValueChange={handleThemeChange} />
<SwitchRow
label="Open links with in-app browser"
value={shouldUseInAppBrowser(browser)}
onValueChange={value => {
dispatch(setGlobalSettings({ browser: value ? 'embedded' : 'external' }));
}}
/>
<InputRowRadioButtons
navigation={navigation}
label="Mark messages as read on scroll"
description="When scrolling through messages, should they automatically be marked as read?"
valueKey={markMessagesReadOnScroll}
items={[
{ key: 'always', title: 'Always' },
{ key: 'never', title: 'Never' },
{
key: 'conversation-views-only',
title: 'Only in conversation views',
subtitle:
'Messages will be automatically marked as read only when viewing a single topic or private message conversation.',
},
]}
onValueChange={value => {
dispatch(setGlobalSettings({ markMessagesReadOnScroll: value }));
}}
/>
<NestedNavRow
Icon={IconNotifications}
label="Notifications"
onPress={() => {
navigation.push('notifications');
}}
/>
<NestedNavRow
Icon={IconLanguage}
label="Language"
onPress={() => {
navigation.push('language');
}}
/>
<NestedNavRow
Icon={IconDiagnostics}
label="Diagnostics"
onPress={() => {
navigation.push('diagnostics');
}}
/>
<NestedNavRow
Icon={IconMoreHorizontal}
label="Legal"
onPress={() => {
navigation.push('legal');
}}
/>
</Screen>
);
}