From 418c1ce9bade6560f4bf22c4b76ee11960bd4475 Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 12 Feb 2018 11:03:05 -0300 Subject: [PATCH] Update tooltip library (#1426) * Update tooltip library * Feedback review * remove static field --- .../options_context/options_context.ios.js | 3 +- app/components/post/post.js | 10 ++--- app/components/tooltip.js | 39 +++++++++++++++++++ app/utils/tooltip.js | 12 ++++++ package.json | 2 +- yarn.lock | 6 +-- 6 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 app/components/tooltip.js create mode 100644 app/utils/tooltip.js diff --git a/app/components/options_context/options_context.ios.js b/app/components/options_context/options_context.ios.js index ffff77373..bf5517b26 100644 --- a/app/components/options_context/options_context.ios.js +++ b/app/components/options_context/options_context.ios.js @@ -3,7 +3,8 @@ import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; -import ToolTip from 'react-native-tooltip'; + +import ToolTip from 'app/components/tooltip'; export default class OptionsContext extends PureComponent { static propTypes = { diff --git a/app/components/post/post.js b/app/components/post/post.js index 95164b7d7..5d19962a7 100644 --- a/app/components/post/post.js +++ b/app/components/post/post.js @@ -11,7 +11,6 @@ import { } from 'react-native'; import {injectIntl, intlShape} from 'react-intl'; import MaterialIcon from 'react-native-vector-icons/MaterialIcons'; -import {isToolTipShowing} from 'react-native-tooltip'; import PostBody from 'app/components/post_body'; import PostHeader from 'app/components/post_header'; @@ -20,6 +19,7 @@ import {NavigationTypes} from 'app/constants'; import {emptyFunction} from 'app/utils/general'; import {preventDoubleTap} from 'app/utils/tap'; import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme'; +import {getToolTipVisible} from 'app/utils/tooltip'; import {Posts} from 'mattermost-redux/constants'; import DelayedAction from 'mattermost-redux/utils/delayed_action'; @@ -265,7 +265,7 @@ class Post extends PureComponent { post } = this.props; - if (!isToolTipShowing) { + if (!getToolTipVisible()) { if (onPress && post.state !== Posts.POST_DELETED && !isSystemMessage(post) && !isPostPendingOrFailed(post)) { preventDoubleTap(onPress, null, post); } else if (!isSearchResult && isPostEphemeral(post)) { @@ -276,7 +276,7 @@ class Post extends PureComponent { handleReply = () => { const {post, onReply} = this.props; - if (!isToolTipShowing && onReply) { + if (!getToolTipVisible() && onReply) { return preventDoubleTap(onReply, null, post); } @@ -322,13 +322,13 @@ class Post extends PureComponent { viewUserProfile = () => { const {isSearchResult} = this.props; - if (!isSearchResult && !isToolTipShowing) { + if (!isSearchResult && !getToolTipVisible()) { preventDoubleTap(this.goToUserProfile, this); } }; toggleSelected = (selected) => { - if (!isToolTipShowing) { + if (!getToolTipVisible()) { this.setState({selected}); } }; diff --git a/app/components/tooltip.js b/app/components/tooltip.js new file mode 100644 index 000000000..e82e36d70 --- /dev/null +++ b/app/components/tooltip.js @@ -0,0 +1,39 @@ +// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React, {PureComponent} from 'react'; +import PropTypes from 'prop-types'; +import RNToolTip from 'react-native-tooltip'; + +import {setToolTipVisible} from 'app/utils/tooltip'; + +export default class ToolTip extends PureComponent { + static propTypes = { + onHide: PropTypes.func, + onShow: PropTypes.func + }; + + handleHide = () => { + if (this.props.onHide) { + this.props.onHide(); + } + setToolTipVisible(false); + }; + + handleShow = () => { + if (this.props.onShow) { + this.props.onShow(); + } + setToolTipVisible(); + }; + + render() { + return ( + + ); + } +} diff --git a/app/utils/tooltip.js b/app/utils/tooltip.js new file mode 100644 index 000000000..7932b6830 --- /dev/null +++ b/app/utils/tooltip.js @@ -0,0 +1,12 @@ +// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +let isToolTipVisible = false; + +export function setToolTipVisible(visible = true) { + isToolTipVisible = visible; +} + +export function getToolTipVisible() { + return isToolTipVisible; +} diff --git a/package.json b/package.json index 03b53f0b8..97eb71abd 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "react-native-status-bar-size": "0.3.3", "react-native-svg": "6.1.3", "react-native-tableview": "2.1.0", - "react-native-tooltip": "enahum/react-native-tooltip", + "react-native-tooltip": "5.2.0", "react-native-vector-icons": "4.5.0", "react-native-video": "2.0.0", "react-native-youtube": "1.1.0", diff --git a/yarn.lock b/yarn.lock index 7e26a36f6..7719c8b40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5317,9 +5317,9 @@ react-native-tableview@2.1.0: dependencies: prop-types "^15.6.0" -react-native-tooltip@enahum/react-native-tooltip: - version "5.1.1" - resolved "https://codeload.github.com/enahum/react-native-tooltip/tar.gz/eb47f93a728813b58c01f23ec84f0b8b1bd70bd0" +react-native-tooltip@5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/react-native-tooltip/-/react-native-tooltip-5.2.0.tgz#4358ea1e9bdcb49dad28bf5881440b0182927422" react-native-vector-icons@4.5.0: version "4.5.0"