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 tiny from '../../views/Editor/tiny/tiny';
import diff from '../../utils/differ';
import { openLinkInBrowser } from '../../utils/functions';
const {Value, timing} = Animated;
@@ -130,8 +131,13 @@ const MergeEditor = () => {
};
const _onShouldStartLoadWithRequest = (request) => {
if (request.url.includes('https')) {
Linking.openURL(request.url);
if (request.url.includes('http')) {
openLinkInBrowser(request.url, colors)
.catch((e) => ToastEvent.show(e.message, 'error'))
.then((r) => {
console.log('closed');
});
return false;
} else {
return true;

View File

@@ -114,6 +114,8 @@ export const UpdateDialog = () => {
'https://play.google.com/store/apps/details?id=com.streetwriters.notesnook';
let url_ios = 'itms-apps://itunes.apple.com/app/id1544027013';
setVisible(false);
await Linking.openURL(
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 {db} from './DB';
import {eClearEditor, eOnNewTopicAdded, refreshNotesPage} from './Events';
import {Linking} from 'react-native';
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
export const deleteItems = async (item) => {
if (item && item.id && history.selectedItemsList.length === 0) {
@@ -77,3 +79,34 @@ export const deleteItems = async (item) => {
updateEvent({type: Actions.COLORS});
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 tiny from '../tiny';
import { EditorWebView } from '../../Functions';
import { openLinkInBrowser } from '../../../../utils/functions';
let inputValue = null;
@@ -65,7 +66,11 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
};
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 () => {

View File

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

View File

@@ -66,6 +66,7 @@ import {
eScrollEvent,
eUpdateSearchState,
} from '../../utils/Events';
import {openLinkInBrowser} from '../../utils/functions';
import {MMKV} from '../../utils/mmkv';
import {pv, SIZE} from '../../utils/SizeUtils';
import Storage from '../../utils/storage';
@@ -98,8 +99,6 @@ export const Settings = ({navigation}) => {
});
}
eSendEvent(eUpdateSearchState, {
placeholder: '',
data: [],
@@ -143,7 +142,11 @@ export const Settings = ({navigation}) => {
{
name: 'Privacy Policy',
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',
},
@@ -180,7 +183,11 @@ export const Settings = ({navigation}) => {
noProgress: true,
icon: 'discord',
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',
});
@@ -190,7 +197,11 @@ export const Settings = ({navigation}) => {
{
name: 'About',
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),
},
@@ -211,11 +222,7 @@ export const Settings = ({navigation}) => {
paddingHorizontal: 0,
}}>
{!DDS.isLargeTablet() && (
<Header
title="Settings"
type="settings"
messageCard={false}
/>
<Header title="Settings" type="settings" messageCard={false} />
)}
<SettingsUserSection />
<SettingsAppearanceSection />