Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

open links in InAppBrowser

ammarahm-ed76f700015732
diff --git a/apps/mobile/src/components/MergeEditor/index.js b/apps/mobile/src/components/MergeEditor/index.js
index 07fc79127..30193ad7b 100644
--- a/apps/mobile/src/components/MergeEditor/index.js
+++ b/apps/mobile/src/components/MergeEditor/index.js
@@ -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;
diff --git a/apps/mobile/src/components/UpdateDialog/index.js b/apps/mobile/src/components/UpdateDialog/index.js
index 9b53de6e7..4ca41855e 100644
--- a/apps/mobile/src/components/UpdateDialog/index.js
+++ b/apps/mobile/src/components/UpdateDialog/index.js
@@ -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,
);
diff --git a/apps/mobile/src/utils/functions.js b/apps/mobile/src/utils/functions.js
index 15feba3f0..c36f772d5 100644
--- a/apps/mobile/src/utils/functions.js
+++ b/apps/mobile/src/utils/functions.js
@@ -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);
+ }
+}
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
index 6f1a6abc2..af65602ab 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
@@ -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 () => {
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js b/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js
index d37b029c7..9eff6b6be 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/tooltip.js
@@ -38,7 +38,6 @@ const Tooltip = () => {
const show = (data) => {
properties.userBlur = true;
if (!data) {
- console.log('hiding')
setVisible(false);
editing.tooltip = null;
return;
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 8727aa5c5..23d9a4ac8 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -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,32 +222,28 @@ export const Settings = ({navigation}) => {
paddingHorizontal: 0,
}}>
{!DDS.isLargeTablet() && (
- <Header
- title="Settings"
- type="settings"
- messageCard={false}
- />
+ <Header title="Settings" type="settings" messageCard={false} />
)}
<SettingsUserSection />
<SettingsAppearanceSection />
- <>
- <SettingsPrivacyAndSecurity />
- <SettingsBackupAndRestore />
+ <>
+ <SettingsPrivacyAndSecurity />
+ <SettingsBackupAndRestore />
- <SectionHeader title="Other" />
+ <SectionHeader title="Other" />
- {otherItems.map((item) => (
- <CustomButton
- key={item.name}
- title={item.name}
- tagline={item.desc}
- onPress={item.func}
- />
- ))}
+ {otherItems.map((item) => (
+ <CustomButton
+ key={item.name}
+ title={item.name}
+ tagline={item.desc}
+ onPress={item.func}
+ />
+ ))}
- <AccoutLogoutSection />
- </>
+ <AccoutLogoutSection />
+ </>
<View
style={{