fix external link opening crash

This commit is contained in:
feruz 2020-09-25 12:51:23 +03:00
parent eab9a017c6
commit 869e2a738b
2 changed files with 45 additions and 30 deletions
src/components/postElements/body/view

View File

@ -1,4 +1,4 @@
import React, { Fragment, useState, useRef } from 'react';
import React, { Fragment, useState, useEffect, useRef } from 'react';
import { Dimensions, Linking, Modal, PermissionsAndroid, Platform } from 'react-native';
import { useIntl } from 'react-intl';
import CameraRoll from '@react-native-community/cameraroll';
@ -50,6 +50,12 @@ const CommentBody = ({
const actionImage = useRef(null);
const actionLink = useRef(null);
useEffect(() => {
if (selectedLink) {
actionLink.current.show();
}
}, [selectedLink]);
const _showLowComment = () => {
setRevealComment(true);
};
@ -83,7 +89,6 @@ const CommentBody = ({
case '_external':
case 'markdown-external-link':
setSelectedLink(href);
actionLink.current.show();
break;
case 'longpress':
handleOnLongPress();
@ -149,19 +154,22 @@ const CommentBody = ({
const handleLinkPress = (ind) => {
if (ind === 1) {
//open link
Linking.canOpenURL(selectedLink).then((supported) => {
if (supported) {
Linking.openURL(selectedLink);
} else {
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.failed_to_open',
}),
),
);
}
});
console.log('selectedLink', selectedLink);
if (selectedLink) {
Linking.canOpenURL(selectedLink).then((supported) => {
if (supported) {
Linking.openURL(selectedLink);
} else {
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.failed_to_open',
}),
),
);
}
});
}
}
if (ind === 0) {
//copy to clipboard

View File

@ -1,4 +1,4 @@
import React, { Fragment, useState, useRef } from 'react';
import React, { Fragment, useState, useEffect, useRef } from 'react';
import { Dimensions, Linking, Modal, PermissionsAndroid, Platform } from 'react-native';
import CameraRoll from '@react-native-community/cameraroll';
import { withNavigation } from 'react-navigation';
@ -41,6 +41,12 @@ const PostBody = ({
const actionImage = useRef(null);
const actionLink = useRef(null);
useEffect(() => {
if (selectedLink) {
actionLink.current.show();
}
}, [selectedLink]);
const _handleOnLinkPress = (event) => {
if ((!event && !get(event, 'nativeEvent.data'), false)) {
return;
@ -71,7 +77,6 @@ const PostBody = ({
case '_external':
case 'markdown-external-link':
setSelectedLink(href);
actionLink.current.show();
//_handleBrowserLink(href);
break;
case 'markdown-author-link':
@ -135,19 +140,21 @@ const PostBody = ({
const handleLinkPress = (ind) => {
if (ind === 1) {
//open link
Linking.canOpenURL(selectedLink).then((supported) => {
if (supported) {
Linking.openURL(selectedLink);
} else {
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.failed_to_open',
}),
),
);
}
});
if (selectedLink) {
Linking.canOpenURL(selectedLink).then((supported) => {
if (supported) {
Linking.openURL(selectedLink);
} else {
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.failed_to_open',
}),
),
);
}
});
}
}
if (ind === 0) {
//copy to clipboard