open links in InAppBrowser

This commit is contained in:
ammarahm-ed
2021-02-10 10:09:48 +05:00
parent e15b21457d
commit 76f7000157
6 changed files with 80 additions and 28 deletions

View File

@@ -32,6 +32,7 @@ import KeepAwake from '@sayem314/react-native-keep-awake';
import {timeConverter} from '../../utils/TimeUtils'; import {timeConverter} from '../../utils/TimeUtils';
import tiny from '../../views/Editor/tiny/tiny'; import tiny from '../../views/Editor/tiny/tiny';
import diff from '../../utils/differ'; import diff from '../../utils/differ';
import { openLinkInBrowser } from '../../utils/functions';
const {Value, timing} = Animated; const {Value, timing} = Animated;
@@ -130,8 +131,13 @@ const MergeEditor = () => {
}; };
const _onShouldStartLoadWithRequest = (request) => { const _onShouldStartLoadWithRequest = (request) => {
if (request.url.includes('https')) { if (request.url.includes('http')) {
Linking.openURL(request.url); openLinkInBrowser(request.url, colors)
.catch((e) => ToastEvent.show(e.message, 'error'))
.then((r) => {
console.log('closed');
});
return false; return false;
} else { } else {
return true; return true;

View File

@@ -114,6 +114,8 @@ export const UpdateDialog = () => {
'https://play.google.com/store/apps/details?id=com.streetwriters.notesnook'; 'https://play.google.com/store/apps/details?id=com.streetwriters.notesnook';
let url_ios = 'itms-apps://itunes.apple.com/app/id1544027013'; let url_ios = 'itms-apps://itunes.apple.com/app/id1544027013';
setVisible(false); setVisible(false);
await Linking.openURL( await Linking.openURL(
Platform.OS === 'android' ? url_android : url_ios, Platform.OS === 'android' ? url_android : url_ios,
); );

View File

@@ -4,6 +4,8 @@ import {Actions} from '../provider/Actions';
import {eSendEvent, ToastEvent} from '../services/EventManager'; import {eSendEvent, ToastEvent} from '../services/EventManager';
import {db} from './DB'; import {db} from './DB';
import {eClearEditor, eOnNewTopicAdded, refreshNotesPage} from './Events'; import {eClearEditor, eOnNewTopicAdded, refreshNotesPage} from './Events';
import {Linking} from 'react-native';
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
export const deleteItems = async (item) => { export const deleteItems = async (item) => {
if (item && item.id && history.selectedItemsList.length === 0) { if (item && item.id && history.selectedItemsList.length === 0) {
@@ -77,3 +79,34 @@ export const deleteItems = async (item) => {
updateEvent({type: Actions.COLORS}); updateEvent({type: Actions.COLORS});
updateEvent({type: Actions.SELECTION_MODE, enabled: false}); updateEvent({type: Actions.SELECTION_MODE, enabled: false});
}; };
export const openLinkInBrowser = async (link, colors) => {
try {
const url = link;
if (await InAppBrowser.isAvailable()) {
await InAppBrowser.open(url, {
// iOS Properties
dismissButtonStyle: 'cancel',
preferredBarTintColor: colors.accent,
preferredControlTintColor: 'white',
readerMode: false,
animated: true,
modalPresentationStyle: 'fullScreen',
modalTransitionStyle: 'coverVertical',
modalEnabled: true,
enableBarCollapsing: false,
// Android Properties
showTitle: true,
toolbarColor: colors.accent,
secondaryToolbarColor: 'black',
enableUrlBarHiding: true,
enableDefaultShare: true,
forceCloseOnRedirection: false,
});
} else Linking.openURL(url);
} catch (error) {
console.log(error.message);
}
}

View File

@@ -10,6 +10,7 @@ import {focusEditor, formatSelection, INPUT_MODE, properties} from './constants'
import LinkPreview from './linkpreview'; import LinkPreview from './linkpreview';
import tiny from '../tiny'; import tiny from '../tiny';
import { EditorWebView } from '../../Functions'; import { EditorWebView } from '../../Functions';
import { openLinkInBrowser } from '../../../../utils/functions';
let inputValue = null; let inputValue = null;
@@ -65,7 +66,11 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
}; };
const onPress = async () => { const onPress = async () => {
await Linking.openURL(value); openLinkInBrowser(value, colors)
.catch((e) => ToastEvent.show(e.message, 'error'))
.then((r) => {
console.log('closed');
});
}; };
const onBlur = async () => { const onBlur = async () => {

View File

@@ -38,7 +38,6 @@ const Tooltip = () => {
const show = (data) => { const show = (data) => {
properties.userBlur = true; properties.userBlur = true;
if (!data) { if (!data) {
console.log('hiding')
setVisible(false); setVisible(false);
editing.tooltip = null; editing.tooltip = null;
return; return;

View File

@@ -66,6 +66,7 @@ import {
eScrollEvent, eScrollEvent,
eUpdateSearchState, eUpdateSearchState,
} from '../../utils/Events'; } from '../../utils/Events';
import {openLinkInBrowser} from '../../utils/functions';
import {MMKV} from '../../utils/mmkv'; import {MMKV} from '../../utils/mmkv';
import {pv, SIZE} from '../../utils/SizeUtils'; import {pv, SIZE} from '../../utils/SizeUtils';
import Storage from '../../utils/storage'; import Storage from '../../utils/storage';
@@ -98,8 +99,6 @@ export const Settings = ({navigation}) => {
}); });
} }
eSendEvent(eUpdateSearchState, { eSendEvent(eUpdateSearchState, {
placeholder: '', placeholder: '',
data: [], data: [],
@@ -143,7 +142,11 @@ export const Settings = ({navigation}) => {
{ {
name: 'Privacy Policy', name: 'Privacy Policy',
func: async () => { func: async () => {
await Linking.openURL('https://www.notesnook.com/privacy.html'); openLinkInBrowser('https://www.notesnook.com/privacy.html', colors)
.catch((e) => ToastEvent.show(e.message, 'error'))
.then((r) => {
console.log('closed');
});
}, },
desc: 'Read our privacy policy', desc: 'Read our privacy policy',
}, },
@@ -180,7 +183,11 @@ export const Settings = ({navigation}) => {
noProgress: true, noProgress: true,
icon: 'discord', icon: 'discord',
action: async () => { action: async () => {
await Linking.openURL('https://discord.gg/zQBK97EE22'); openLinkInBrowser('https://discord.gg/zQBK97EE22', colors)
.catch((e) => ToastEvent.show(e.message, 'error'))
.then((r) => {
console.log('closed');
});
}, },
actionText: 'Join Now', actionText: 'Join Now',
}); });
@@ -190,7 +197,11 @@ export const Settings = ({navigation}) => {
{ {
name: 'About', name: 'About',
func: async () => { func: async () => {
await Linking.openURL('https://www.notesnook.com'); openLinkInBrowser('https://www.notesnook.com', colors)
.catch((e) => ToastEvent.show(e.message, 'error'))
.then((r) => {
console.log('closed');
});
}, },
desc: format(APP_VERSION), desc: format(APP_VERSION),
}, },
@@ -211,11 +222,7 @@ export const Settings = ({navigation}) => {
paddingHorizontal: 0, paddingHorizontal: 0,
}}> }}>
{!DDS.isLargeTablet() && ( {!DDS.isLargeTablet() && (
<Header <Header title="Settings" type="settings" messageCard={false} />
title="Settings"
type="settings"
messageCard={false}
/>
)} )}
<SettingsUserSection /> <SettingsUserSection />
<SettingsAppearanceSection /> <SettingsAppearanceSection />