fixed comment image/link clicks and long press 1.5s

This commit is contained in:
feruz 2020-02-11 14:22:11 +02:00
parent 945d669abd
commit 2a7a1021fd
3 changed files with 26 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import React, { Fragment, useState, useRef } from 'react';
import { View, TouchableWithoutFeedback } from 'react-native';
import { View } from 'react-native';
import ActionSheet from 'react-native-actionsheet';
import { useIntl } from 'react-intl';
import get from 'lodash/get';
@ -50,7 +50,7 @@ const CommentView = ({
};
return (
<TouchableWithoutFeedback onLongPress={handleOnLongPress} delayLongPress={2000}>
<Fragment>
<View style={styles.commentContainer}>
<PostHeaderDescription
key={comment.permlink}
@ -67,6 +67,7 @@ const CommentView = ({
commentDepth={comment.depth}
reputation={comment.author_reputation}
handleOnUserPress={handleOnUserPress}
handleOnLongPress={handleOnLongPress}
body={comment.body}
created={comment.created}
key={`key-${comment.permlink}`}
@ -176,7 +177,7 @@ const CommentView = ({
)}
</View>
</View>
</TouchableWithoutFeedback>
</Fragment>
);
};

View File

@ -34,6 +34,7 @@ const CommentBody = ({
textSelectable = true,
handleOnUserPress,
handleOnPostPress,
handleOnLongPress,
created,
commentDepth,
reputation,
@ -84,6 +85,9 @@ const CommentBody = ({
setSelectedLink(href);
actionLink.current.show();
break;
case 'longpress':
handleOnLongPress();
break;
case 'markdown-author-link':
if (!handleOnUserPress) {
__handleOnUserPress(author);

View File

@ -118,6 +118,8 @@ true;
`;
const customCommentScript = `
var longpress = 1500;
var delay;
var images = document.getElementsByTagName("IMG");
var imageUrls = [];
for (var k = 0; k < images.length; k++) {
@ -138,6 +140,22 @@ for (var i = 0; i < images.length; i++) {
images[i].setAttribute("onclick", message);
}
}
document.addEventListener('mousedown', function(event) {
delay = setTimeout(check, longpress);
function check() {
var result = {
type: 'longpress',
};
window.ReactNativeWebView.postMessage(JSON.stringify(result));
return true;
}
}, true);
document.addEventListener('mouseup', function (e) {
clearTimeout(delay);
});
document.addEventListener('mouseout', function (e) {
clearTimeout(delay);
});
document.addEventListener('click', function(event) {
var el = event.target;
while (el.tagName !== 'A') {