diff --git a/app/stacks/InsideStack.tsx b/app/stacks/InsideStack.tsx index aef07c76f..b9be48e52 100644 --- a/app/stacks/InsideStack.tsx +++ b/app/stacks/InsideStack.tsx @@ -175,7 +175,7 @@ const SettingsStackNavigator = () => { options={E2EEncryptionSecurityView.navigationOptions} /> - + { options={props => SettingsView.navigationOptions!({ ...props, isMasterDetail: true })} /> - + void; diff --git a/app/views/ThemeView.tsx b/app/views/ThemeView.tsx index e5cc3e2c1..c59d54bf4 100644 --- a/app/views/ThemeView.tsx +++ b/app/views/ThemeView.tsx @@ -1,8 +1,8 @@ -import React from 'react'; -import { StackNavigationOptions } from '@react-navigation/stack'; +import React, { useLayoutEffect } from 'react'; +import { SettingsStackParamList } from '../stacks/types'; import I18n from '../i18n'; -import { TSupportedThemes, withTheme } from '../theme'; +import { useTheme } from '../theme'; import StatusBar from '../containers/StatusBar'; import * as List from '../containers/List'; import { supportSystemTheme } from '../utils/deviceInfo'; @@ -11,6 +11,7 @@ import UserPreferences from '../lib/methods/userPreferences'; import { events, logEvent } from '../utils/log'; import { IThemePreference, TThemeMode, TDarkLevel } from '../definitions/ITheme'; import { THEME_PREFERENCES_KEY, themes } from '../lib/constants'; +import { IBaseScreen } from '../definitions'; const THEME_GROUP = 'THEME_GROUP'; const DARK_GROUP = 'DARK_GROUP'; @@ -57,21 +58,20 @@ interface ITheme { group: string; } -interface IThemeViewProps { - theme: TSupportedThemes; - themePreferences: IThemePreference; - setTheme(newTheme?: IThemePreference): void; -} +type IThemeViewProps = IBaseScreen; -class ThemeView extends React.Component { - static navigationOptions = (): StackNavigationOptions => ({ - title: I18n.t('Theme') - }); +const ThemeView = ({ navigation }: IThemeViewProps): React.ReactElement => { + const { theme, themePreferences, setTheme } = useTheme(); - isSelected = (item: ITheme) => { - const { themePreferences } = this.props; + useLayoutEffect(() => { + navigation.setOptions({ + title: I18n.t('Theme') + }); + }, [navigation]); + + const isSelected = (item: ITheme) => { const { group } = item; - const { darkLevel, currentTheme } = themePreferences; + const { darkLevel, currentTheme } = themePreferences as IThemePreference; if (group === THEME_GROUP) { return item.value === currentTheme; } @@ -80,9 +80,8 @@ class ThemeView extends React.Component { } }; - onClick = (item: ITheme) => { - const { themePreferences } = this.props; - const { darkLevel, currentTheme } = themePreferences; + const onClick = (item: ITheme) => { + const { darkLevel, currentTheme } = themePreferences as IThemePreference; const { value, group } = item; let changes: Partial = {}; if (group === THEME_GROUP && currentTheme !== value) { @@ -93,53 +92,49 @@ class ThemeView extends React.Component { logEvent(events.THEME_SET_DARK_LEVEL, { dark_level: value }); changes = { darkLevel: value as TDarkLevel }; } - this.setTheme(changes); + _setTheme(changes); }; - setTheme = (theme: Partial) => { - const { setTheme, themePreferences } = this.props; - const newTheme = { ...themePreferences, ...theme }; - setTheme(newTheme); - UserPreferences.setMap(THEME_PREFERENCES_KEY, newTheme); + const _setTheme = (theme: Partial) => { + const newTheme: IThemePreference = { ...(themePreferences as IThemePreference), ...theme }; + if (setTheme) { + setTheme(newTheme); + UserPreferences.setMap(THEME_PREFERENCES_KEY, newTheme); + } }; - renderIcon = () => { - const { theme } = this.props; - return ; - }; + const renderIcon = () => ; - renderItem = ({ item }: { item: ITheme }) => { + const renderItem = ({ item }: { item: ITheme }) => { const { label, value } = item; return ( <> this.onClick(item)} + onPress={() => onClick(item)} testID={`theme-view-${value}`} - right={() => (this.isSelected(item) ? this.renderIcon() : null)} + right={() => (isSelected(item) ? renderIcon() : null)} /> ); }; - render() { - return ( - - - - - - <>{themeGroup.map(item => this.renderItem({ item }))} - - - - <>{darkGroup.map(item => this.renderItem({ item }))} - - - - ); - } -} + return ( + + + + + + <>{themeGroup.map(item => renderItem({ item }))} + + + + <>{darkGroup.map(item => renderItem({ item }))} + + + + ); +}; -export default withTheme(ThemeView); +export default ThemeView;