Chore: Migrate DefaultBrowserView to Typescript (#3488)

Co-authored-by: AlexAlexandre <alexalexandrejr@gmail.com>
This commit is contained in:
Reinaldo Neto 2021-11-17 16:55:22 -03:00 committed by GitHub
parent 2b3542d4ae
commit ccd1b6596e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import { StackNavigationOptions } from '@react-navigation/stack';
import { FlatList, Linking } from 'react-native'; import { FlatList, Linking } from 'react-native';
import I18n from '../i18n'; import I18n from '../i18n';
@ -13,7 +13,14 @@ import SafeAreaView from '../containers/SafeAreaView';
import UserPreferences from '../lib/userPreferences'; import UserPreferences from '../lib/userPreferences';
import { events, logEvent } from '../utils/log'; import { events, logEvent } from '../utils/log';
const DEFAULT_BROWSERS = [ type TValue = 'inApp' | 'systemDefault:' | 'googlechrome:' | 'firefox:' | 'brave:';
interface IBrowsersValues {
title: string;
value: TValue;
}
const DEFAULT_BROWSERS: IBrowsersValues[] = [
{ {
title: 'In_app', title: 'In_app',
value: 'inApp' value: 'inApp'
@ -24,7 +31,7 @@ const DEFAULT_BROWSERS = [
} }
]; ];
const BROWSERS = [ const BROWSERS: IBrowsersValues[] = [
{ {
title: 'Chrome', title: 'Chrome',
value: 'googlechrome:' value: 'googlechrome:'
@ -39,16 +46,23 @@ const BROWSERS = [
} }
]; ];
class DefaultBrowserView extends React.Component { interface IDefaultBrowserViewState {
static navigationOptions = () => ({ browser: any;
supported: any[];
}
interface IDefaultBrowserViewProps {
theme: string;
}
class DefaultBrowserView extends React.Component<IDefaultBrowserViewProps, IDefaultBrowserViewState> {
private mounted?: boolean;
static navigationOptions = (): StackNavigationOptions => ({
title: I18n.t('Default_browser') title: I18n.t('Default_browser')
}); });
static propTypes = { constructor(props: IDefaultBrowserViewProps) {
theme: PropTypes.string
};
constructor(props) {
super(props); super(props);
this.state = { this.state = {
browser: null, browser: null,
@ -74,6 +88,7 @@ class DefaultBrowserView extends React.Component {
this.setState(({ supported }) => ({ supported: [...supported, browser] })); this.setState(({ supported }) => ({ supported: [...supported, browser] }));
} else { } else {
const { supported } = this.state; const { supported } = this.state;
// @ts-ignore
this.state.supported = [...supported, browser]; this.state.supported = [...supported, browser];
} }
} }
@ -81,7 +96,7 @@ class DefaultBrowserView extends React.Component {
}); });
}; };
isSelected = value => { isSelected = (value: TValue) => {
const { browser } = this.state; const { browser } = this.state;
if (!browser && value === 'systemDefault:') { if (!browser && value === 'systemDefault:') {
return true; return true;
@ -89,7 +104,7 @@ class DefaultBrowserView extends React.Component {
return browser === value; return browser === value;
}; };
changeDefaultBrowser = async newBrowser => { changeDefaultBrowser = async (newBrowser: TValue) => {
logEvent(events.DB_CHANGE_DEFAULT_BROWSER, { browser: newBrowser }); logEvent(events.DB_CHANGE_DEFAULT_BROWSER, { browser: newBrowser });
try { try {
const browser = newBrowser !== 'systemDefault:' ? newBrowser : null; const browser = newBrowser !== 'systemDefault:' ? newBrowser : null;
@ -105,7 +120,7 @@ class DefaultBrowserView extends React.Component {
return <List.Icon name='check' color={themes[theme].tintColor} />; return <List.Icon name='check' color={themes[theme].tintColor} />;
}; };
renderItem = ({ item }) => { renderItem = ({ item }: { item: IBrowsersValues }) => {
const { title, value } = item; const { title, value } = item;
return ( return (
<List.Item <List.Item