-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Chore: Hooks app/views/DefaultBrowserView #4424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac88cad
Chore: Hooks app/views/DefaultBrowserView
reinaldonetof 90e2209
fix type
reinaldonetof 6b2715f
minor tweak
reinaldonetof 5f2e7bc
item on new file
reinaldonetof dd1a915
Merge branch 'develop' into chore.hooks-defaultbrowserview
reinaldonetof 7b1f4f0
minor tweaks
reinaldonetof 7b299dc
minor tweak
reinaldonetof d0b28d4
Merge branch 'develop' into chore.hooks-defaultbrowserview
reinaldonetof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import React from 'react'; | ||
|
|
||
| import I18n from '../../i18n'; | ||
| import { useTheme } from '../../theme'; | ||
| import * as List from '../../containers/List'; | ||
| import { IBrowsersValues, TValue } from '.'; | ||
|
|
||
| interface IRenderItem extends IBrowsersValues { | ||
| browser: string | null; | ||
| changeDefaultBrowser: (newBrowser: TValue) => void; | ||
| } | ||
|
|
||
| const Item = ({ title, value, browser, changeDefaultBrowser }: IRenderItem) => { | ||
| const { colors } = useTheme(); | ||
|
|
||
| let isSelected = false; | ||
| if (!browser && value === 'systemDefault:') { | ||
| isSelected = true; | ||
| } else { | ||
| isSelected = browser === value; | ||
| } | ||
|
|
||
| return ( | ||
| <List.Item | ||
| title={I18n.t(title, { defaultValue: title })} | ||
| onPress={() => changeDefaultBrowser(value)} | ||
| testID={`default-browser-view-${title}`} | ||
| right={() => (isSelected ? <List.Icon name='check' color={colors.tintColor} /> : null)} | ||
| translateTitle={false} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default Item; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import React, { useCallback, useEffect, useLayoutEffect, useState } from 'react'; | ||
| import { FlatList, Linking } from 'react-native'; | ||
| import { useNavigation } from '@react-navigation/native'; | ||
|
|
||
| import I18n from '../../i18n'; | ||
| import StatusBar from '../../containers/StatusBar'; | ||
| import * as List from '../../containers/List'; | ||
| import { DEFAULT_BROWSER_KEY } from '../../lib/methods/helpers/openLink'; | ||
| import { isIOS } from '../../lib/methods/helpers'; | ||
| import SafeAreaView from '../../containers/SafeAreaView'; | ||
| import UserPreferences from '../../lib/methods/userPreferences'; | ||
| import { events, logEvent } from '../../lib/methods/helpers/log'; | ||
| import Item from './Item'; | ||
|
|
||
| export type TValue = 'inApp' | 'systemDefault:' | 'googlechrome:' | 'firefox:' | 'brave:'; | ||
|
|
||
| export interface IBrowsersValues { | ||
| title: string; | ||
| value: TValue; | ||
| } | ||
|
|
||
| const DEFAULT_BROWSERS: IBrowsersValues[] = [ | ||
| { | ||
| title: 'In_app', | ||
| value: 'inApp' | ||
| }, | ||
| { | ||
| title: isIOS ? 'Safari' : 'Browser', | ||
| value: 'systemDefault:' | ||
| } | ||
| ]; | ||
|
|
||
| const BROWSERS: IBrowsersValues[] = [ | ||
| { | ||
| title: 'Chrome', | ||
| value: 'googlechrome:' | ||
| }, | ||
| { | ||
| title: 'Firefox', | ||
| value: 'firefox:' | ||
| }, | ||
| { | ||
| title: 'Brave', | ||
| value: 'brave:' | ||
| } | ||
| ]; | ||
|
|
||
| const DefaultBrowserView = () => { | ||
| const [browser, setBrowser] = useState<string | null>(null); | ||
| const [supported, setSupported] = useState<IBrowsersValues[]>([]); | ||
|
|
||
| const navigation = useNavigation(); | ||
|
|
||
| useLayoutEffect(() => { | ||
| navigation.setOptions({ | ||
| title: I18n.t('Close_Chat') | ||
| }); | ||
| }, [navigation]); | ||
|
|
||
| useEffect(() => { | ||
| const getBrowser = UserPreferences.getString(DEFAULT_BROWSER_KEY); | ||
| setBrowser(getBrowser); | ||
|
|
||
| if (isIOS) { | ||
| BROWSERS.forEach(browser => { | ||
| const { value } = browser; | ||
| Linking.canOpenURL(value).then(installed => { | ||
| if (installed) { | ||
| setSupported(supported => [...supported, browser]); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| }, []); | ||
|
|
||
| const changeDefaultBrowser = useCallback((newBrowser: TValue) => { | ||
| logEvent(events.DB_CHANGE_DEFAULT_BROWSER, { browser: newBrowser }); | ||
| try { | ||
| const browser = newBrowser || 'systemDefault:'; | ||
| UserPreferences.setString(DEFAULT_BROWSER_KEY, browser); | ||
| setBrowser(browser); | ||
| } catch { | ||
| logEvent(events.DB_CHANGE_DEFAULT_BROWSER_F); | ||
| } | ||
| }, []); | ||
|
|
||
| return ( | ||
| <SafeAreaView testID='default-browser-view'> | ||
| <StatusBar /> | ||
| <FlatList | ||
| data={DEFAULT_BROWSERS.concat(supported)} | ||
| keyExtractor={item => item.value} | ||
| contentContainerStyle={List.styles.contentContainerStyleFlatList} | ||
| renderItem={({ item }) => ( | ||
| <Item browser={browser} changeDefaultBrowser={changeDefaultBrowser} title={item.title} value={item.value} /> | ||
| )} | ||
| ListHeaderComponent={ | ||
| <> | ||
| <List.Header title='Choose_where_you_want_links_be_opened' /> | ||
| <List.Separator /> | ||
| </> | ||
| } | ||
| ListFooterComponent={List.Separator} | ||
| ItemSeparatorComponent={List.Separator} | ||
| /> | ||
| </SafeAreaView> | ||
| ); | ||
| }; | ||
|
|
||
| export default DefaultBrowserView; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.