From 818ff8451bcb162374e834c9869ffb1f1ea61c76 Mon Sep 17 00:00:00 2001 From: feruz Date: Tue, 11 Feb 2020 14:22:11 +0200 Subject: [PATCH] fixed comment image/link clicks and long press 1.5s --- src/components/comment/view/commentView.js | 7 ++++--- .../postElements/body/view/commentBodyView.js | 4 ++++ .../postElements/body/view/config.js | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/components/comment/view/commentView.js b/src/components/comment/view/commentView.js index d3df2fde1..64a9b267b 100644 --- a/src/components/comment/view/commentView.js +++ b/src/components/comment/view/commentView.js @@ -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 ( - + - + ); }; diff --git a/src/components/postElements/body/view/commentBodyView.js b/src/components/postElements/body/view/commentBodyView.js index 3ef702c6b..8a3885bc9 100644 --- a/src/components/postElements/body/view/commentBodyView.js +++ b/src/components/postElements/body/view/commentBodyView.js @@ -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); diff --git a/src/components/postElements/body/view/config.js b/src/components/postElements/body/view/config.js index 690bc050a..b5cfdeb9a 100644 --- a/src/components/postElements/body/view/config.js +++ b/src/components/postElements/body/view/config.js @@ -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') {