Chore: evaluate `DefaultBrowserView` (#4105)

This commit is contained in:
Gerzon Z 2022-05-03 12:12:43 -04:00 committed by GitHub
parent 784b016736
commit 0dc34f1eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 16 deletions

View File

@ -2,8 +2,10 @@ import React from 'react';
import { StackNavigationOptions } from '@react-navigation/stack'; import { StackNavigationOptions } from '@react-navigation/stack';
import { FlatList, Linking } from 'react-native'; import { FlatList, Linking } from 'react-native';
import { SettingsStackParamList } from '../stacks/types';
import { IBaseScreen } from '../definitions';
import I18n from '../i18n'; import I18n from '../i18n';
import { TSupportedThemes, withTheme } from '../theme'; import { withTheme } from '../theme';
import { themes } from '../lib/constants'; import { themes } from '../lib/constants';
import StatusBar from '../containers/StatusBar'; import StatusBar from '../containers/StatusBar';
import * as List from '../containers/List'; import * as List from '../containers/List';
@ -47,17 +49,13 @@ const BROWSERS: IBrowsersValues[] = [
]; ];
interface IDefaultBrowserViewState { interface IDefaultBrowserViewState {
browser: any; browser: string | null;
supported: any[]; supported: IBrowsersValues[];
} }
interface IDefaultBrowserViewProps { type IDefaultBrowserViewProps = IBaseScreen<SettingsStackParamList, 'DefaultBrowserView'>;
theme: TSupportedThemes;
}
class DefaultBrowserView extends React.Component<IDefaultBrowserViewProps, IDefaultBrowserViewState> { class DefaultBrowserView extends React.Component<IDefaultBrowserViewProps, IDefaultBrowserViewState> {
private mounted?: boolean;
static navigationOptions = (): StackNavigationOptions => ({ static navigationOptions = (): StackNavigationOptions => ({
title: I18n.t('Default_browser') title: I18n.t('Default_browser')
}); });
@ -74,7 +72,6 @@ class DefaultBrowserView extends React.Component<IDefaultBrowserViewProps, IDefa
} }
componentDidMount() { componentDidMount() {
this.mounted = true;
const browser = UserPreferences.getString(DEFAULT_BROWSER_KEY); const browser = UserPreferences.getString(DEFAULT_BROWSER_KEY);
this.setState({ browser }); this.setState({ browser });
} }
@ -84,13 +81,7 @@ class DefaultBrowserView extends React.Component<IDefaultBrowserViewProps, IDefa
const { value } = browser; const { value } = browser;
Linking.canOpenURL(value).then(installed => { Linking.canOpenURL(value).then(installed => {
if (installed) { if (installed) {
if (this.mounted) { this.setState(({ supported }) => ({ supported: [...supported, browser] }));
this.setState(({ supported }) => ({ supported: [...supported, browser] }));
} else {
const { supported } = this.state;
// @ts-ignore
this.state.supported = [...supported, browser];
}
} }
}); });
}); });