From 414a8e91e00c3012fd0d5e73e1bcb84aaa9edf25 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 6 May 2022 09:15:50 -0400 Subject: [PATCH] Dismiss keyboard when a post is pressed (#6242) --- app/components/post_list/post/post.tsx | 43 ++++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/components/post_list/post/post.tsx b/app/components/post_list/post/post.tsx index 78f552c347..37c536bb83 100644 --- a/app/components/post_list/post/post.tsx +++ b/app/components/post_list/post/post.tsx @@ -128,31 +128,34 @@ const Post = ({ return false; }, [isConsecutivePost, post, previousPost, isFirstReply]); + const handlePostPress = () => { + if ([Screens.SAVED_POSTS, Screens.MENTIONS, Screens.SEARCH].includes(location)) { + showPermalink(serverUrl, '', post.id, intl); + return; + } + + const isValidSystemMessage = isAutoResponder || !isSystemPost; + if (post.deleteAt === 0 && isValidSystemMessage && !isPendingOrFailed) { + if ([Screens.CHANNEL, Screens.PERMALINK].includes(location)) { + const rootId = post.rootId || post.id; + fetchAndSwitchToThread(serverUrl, rootId); + } + } else if ((isEphemeral || post.deleteAt > 0)) { + removePost(serverUrl, post); + } + + setTimeout(() => { + pressDetected.current = false; + }, 300); + }; + const handlePress = preventDoubleTap(() => { pressDetected.current = true; if (post) { - if (location === Screens.THREAD) { - Keyboard.dismiss(); - } else if ([Screens.SAVED_POSTS, Screens.MENTIONS, Screens.SEARCH].includes(location)) { - showPermalink(serverUrl, '', post.id, intl); - return; - } + Keyboard.dismiss(); - const isValidSystemMessage = isAutoResponder || !isSystemPost; - if (post.deleteAt === 0 && isValidSystemMessage && !isPendingOrFailed) { - if ([Screens.CHANNEL, Screens.PERMALINK].includes(location)) { - const rootId = post.rootId || post.id; - fetchAndSwitchToThread(serverUrl, rootId); - } - } else if ((isEphemeral || post.deleteAt > 0)) { - removePost(serverUrl, post); - } - - const pressTimeout = setTimeout(() => { - pressDetected.current = false; - clearTimeout(pressTimeout); - }, 300); + setTimeout(handlePostPress, 300); } });