From 60fb8c3fc2ed334a2b3830fd240cc9b70c144ef1 Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Sat, 8 Feb 2020 17:39:00 +0530 Subject: [PATCH 01/11] [IMPROVEMENT] User Can Copy Link On hold --- app/containers/message/Urls.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 4c67faa7bd9..aeb0b96db41 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -1,5 +1,5 @@ import React from 'react'; -import { View, Text, StyleSheet } from 'react-native'; +import { View, Text, StyleSheet, Clipboard } from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; import Touchable from 'react-native-platform-touchable'; @@ -81,10 +81,14 @@ const Url = React.memo(({ } const onPress = () => openLink(url.url, theme); - + const onLongPress = () => { + console.log(url.url) + Clipboard.setString(url.url) + } return ( 0 && styles.marginTop, From eb1a098191f0b440f681d4f13963f99a46660672 Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Sat, 8 Feb 2020 18:24:57 +0530 Subject: [PATCH 02/11] IMPROVEMENTS On Android: added vibration feedback of 2ms with a toast message showing link was copied On IOS: added vibration feedback ( defaults to 500ms ) --- app/containers/message/Urls.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index aeb0b96db41..96c75e1270c 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -1,10 +1,17 @@ import React from 'react'; -import { View, Text, StyleSheet, Clipboard } from 'react-native'; +import { + View, + Text, + StyleSheet, + Clipboard, + ToastAndroid, + Platform, + Vibration, +} from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; import Touchable from 'react-native-platform-touchable'; import isEqual from 'lodash/isEqual'; - import openLink from '../../utils/openLink'; import sharedStyles from '../../views/Styles'; import { themes } from '../../constants/colors'; @@ -82,9 +89,14 @@ const Url = React.memo(({ const onPress = () => openLink(url.url, theme); const onLongPress = () => { - console.log(url.url) - Clipboard.setString(url.url) - } + Clipboard.setString(url.url); + if(Platform.os === 'ios'){ + Vibration.vibrate(); + } else{ + Vibration.vibrate(200); + ToastAndroid.show('Link copied', ToastAndroid.SHORT); + } + }; return ( Date: Sat, 8 Feb 2020 18:41:21 +0530 Subject: [PATCH 03/11] Corrected code formatting --- app/containers/message/Urls.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 96c75e1270c..9c4881f8e50 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -6,7 +6,7 @@ import { Clipboard, ToastAndroid, Platform, - Vibration, + Vibration } from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; @@ -90,12 +90,12 @@ const Url = React.memo(({ const onPress = () => openLink(url.url, theme); const onLongPress = () => { Clipboard.setString(url.url); - if(Platform.os === 'ios'){ + if (Platform.os === 'ios') { Vibration.vibrate(); - } else{ + } else { Vibration.vibrate(200); - ToastAndroid.show('Link copied', ToastAndroid.SHORT); - } + ToastAndroid.show('Link copied', ToastAndroid.SHORT); + } }; return ( Date: Sun, 9 Feb 2020 09:38:06 +0530 Subject: [PATCH 04/11] Cleaning app/containers/message/Urls.js and removing the onLongPress.js --- app/containers/message/Urls.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 9c4881f8e50..0522b018369 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -2,11 +2,7 @@ import React from 'react'; import { View, Text, - StyleSheet, - Clipboard, - ToastAndroid, - Platform, - Vibration + StyleSheet } from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; @@ -88,19 +84,9 @@ const Url = React.memo(({ } const onPress = () => openLink(url.url, theme); - const onLongPress = () => { - Clipboard.setString(url.url); - if (Platform.os === 'ios') { - Vibration.vibrate(); - } else { - Vibration.vibrate(200); - ToastAndroid.show('Link copied', ToastAndroid.SHORT); - } - }; return ( 0 && styles.marginTop, From 07a3a90fee03a8bcf7300b26a22dac7836bf41b8 Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Sun, 9 Feb 2020 09:49:39 +0530 Subject: [PATCH 05/11] Reverting to "Corrected code formatting" --- app/containers/message/Urls.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 0522b018369..d73420868c4 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -2,7 +2,11 @@ import React from 'react'; import { View, Text, - StyleSheet + StyleSheet, + Clipboard, + ToastAndroid, + Platform, + Vibration, } from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; @@ -84,6 +88,15 @@ const Url = React.memo(({ } const onPress = () => openLink(url.url, theme); + const onLongPress = () => { + Clipboard.setString(url.url); + if(Platform.os === 'ios'){ + Vibration.vibrate(); + } else{ + Vibration.vibrate(200); + ToastAndroid.show('Link copied', ToastAndroid.SHORT); + } + }; return ( Date: Sun, 9 Feb 2020 10:17:11 +0530 Subject: [PATCH 06/11] Reverting Back 1. Reverted changes in URL.js 2. Added Toast and EventEmitter module to Link.js --- app/containers/markdown/Link.js | 9 ++++++++- app/containers/message/Urls.js | 12 +++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/containers/markdown/Link.js b/app/containers/markdown/Link.js index a8f4d4a7cb8..d104e37a9c1 100644 --- a/app/containers/markdown/Link.js +++ b/app/containers/markdown/Link.js @@ -1,10 +1,12 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Text } from 'react-native'; +import { Text, Clipboard } from 'react-native'; import styles from './styles'; import { themes } from '../../constants/colors'; import openLink from '../../utils/openLink'; +import { LISTENER } from '../Toast'; +import EventEmitter from '../../utils/events'; const Link = React.memo(({ children, link, preview, theme @@ -17,11 +19,16 @@ const Link = React.memo(({ }; const childLength = React.Children.toArray(children).filter(o => o).length; + const onLongPress = () => { + Clipboard.setString(link); + EventEmitter.emit(LISTENER, { message: 'Copied_to_clipboard' }); + }; // if you have a [](https://rocket.chat) render https://rocket.chat return ( openLink(url.url, theme); const onLongPress = () => { Clipboard.setString(url.url); - if(Platform.os === 'ios'){ - Vibration.vibrate(); - } else{ - Vibration.vibrate(200); - ToastAndroid.show('Link copied', ToastAndroid.SHORT); - } + EventEmitter.emit( LISTENER, { message: 'Copied_to_clipboard' }); }; return ( 0 && styles.marginTop, From 7a8f5ed850f6fd05ce5c2a98e520f62d9ad56677 Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Sun, 9 Feb 2020 10:29:06 +0530 Subject: [PATCH 07/11] Fixed Formatting --- app/containers/message/Urls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 0d5ae81b904..5ed0dc6a8ef 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -92,7 +92,7 @@ const Url = React.memo(({ const onPress = () => openLink(url.url, theme); const onLongPress = () => { Clipboard.setString(url.url); - EventEmitter.emit( LISTENER, { message: 'Copied_to_clipboard' }); + EventEmitter.emit(LISTENER, { message: 'Copied_to_clipboard' }); }; return ( Date: Wed, 12 Feb 2020 19:12:49 +0530 Subject: [PATCH 08/11] Added mocks for react-native-firebase and bugsnag --- __mocks__/bugsnag-react-native.js | 8 ++++++++ __mocks__/react-native-firebase.js | 3 +++ __tests__/__snapshots__/Storyshots.test.js.snap | 3 +++ app/containers/message/Urls.js | 13 +------------ 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 __mocks__/bugsnag-react-native.js create mode 100644 __mocks__/react-native-firebase.js diff --git a/__mocks__/bugsnag-react-native.js b/__mocks__/bugsnag-react-native.js new file mode 100644 index 00000000000..637b8e450cf --- /dev/null +++ b/__mocks__/bugsnag-react-native.js @@ -0,0 +1,8 @@ +export class Client { } + +export default { + bugsnag: () => '', + leaveBreadcrumb: () => '', + notify: () => '', + loggerConfig: () => '' +}; diff --git a/__mocks__/react-native-firebase.js b/__mocks__/react-native-firebase.js new file mode 100644 index 00000000000..582f7cea1ff --- /dev/null +++ b/__mocks__/react-native-firebase.js @@ -0,0 +1,3 @@ +export default { + analytics: null +}; diff --git a/__tests__/__snapshots__/Storyshots.test.js.snap b/__tests__/__snapshots__/Storyshots.test.js.snap index b7e07750c5b..52995ba91b1 100644 --- a/__tests__/__snapshots__/Storyshots.test.js.snap +++ b/__tests__/__snapshots__/Storyshots.test.js.snap @@ -27460,6 +27460,7 @@ exports[`Storyshots Message list 1`] = ` Support openLink(url.url, theme); - const onLongPress = () => { - Clipboard.setString(url.url); - EventEmitter.emit(LISTENER, { message: 'Copied_to_clipboard' }); - }; return ( 0 && styles.marginTop, From 4a280f02843d9143c9c5f07631c9d8b6ce67799c Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Wed, 12 Feb 2020 20:47:27 +0530 Subject: [PATCH 09/11] Update: 1. all changes made to Url.js in the initial commit where undone 2. app/containers/markdown/Link.js updated, condition applied to make sure user does not coly the link from roomsListView --- app/containers/markdown/Link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/markdown/Link.js b/app/containers/markdown/Link.js index d104e37a9c1..06266bb6c78 100644 --- a/app/containers/markdown/Link.js +++ b/app/containers/markdown/Link.js @@ -28,7 +28,7 @@ const Link = React.memo(({ return ( Date: Wed, 12 Feb 2020 21:13:35 +0530 Subject: [PATCH 10/11] Reverted all the changes in Url.js --- app/containers/message/Urls.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 0522b018369..4c67faa7bd9 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -1,13 +1,10 @@ import React from 'react'; -import { - View, - Text, - StyleSheet -} from 'react-native'; +import { View, Text, StyleSheet } from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; import Touchable from 'react-native-platform-touchable'; import isEqual from 'lodash/isEqual'; + import openLink from '../../utils/openLink'; import sharedStyles from '../../views/Styles'; import { themes } from '../../constants/colors'; @@ -84,6 +81,7 @@ const Url = React.memo(({ } const onPress = () => openLink(url.url, theme); + return ( Date: Fri, 14 Feb 2020 10:29:02 -0300 Subject: [PATCH 11/11] Add i18n and longPress to URL --- app/containers/markdown/Link.js | 3 ++- app/containers/message/Urls.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/containers/markdown/Link.js b/app/containers/markdown/Link.js index 06266bb6c78..c974a0f259e 100644 --- a/app/containers/markdown/Link.js +++ b/app/containers/markdown/Link.js @@ -7,6 +7,7 @@ import { themes } from '../../constants/colors'; import openLink from '../../utils/openLink'; import { LISTENER } from '../Toast'; import EventEmitter from '../../utils/events'; +import I18n from '../../i18n'; const Link = React.memo(({ children, link, preview, theme @@ -21,7 +22,7 @@ const Link = React.memo(({ const childLength = React.Children.toArray(children).filter(o => o).length; const onLongPress = () => { Clipboard.setString(link); - EventEmitter.emit(LISTENER, { message: 'Copied_to_clipboard' }); + EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') }); }; // if you have a [](https://rocket.chat) render https://rocket.chat diff --git a/app/containers/message/Urls.js b/app/containers/message/Urls.js index 4c67faa7bd9..a10459e9ded 100644 --- a/app/containers/message/Urls.js +++ b/app/containers/message/Urls.js @@ -1,5 +1,7 @@ import React from 'react'; -import { View, Text, StyleSheet } from 'react-native'; +import { + View, Text, StyleSheet, Clipboard +} from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; import Touchable from 'react-native-platform-touchable'; @@ -10,6 +12,9 @@ import sharedStyles from '../../views/Styles'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { withSplit } from '../../split'; +import { LISTENER } from '../Toast'; +import EventEmitter from '../../utils/events'; +import I18n from '../../i18n'; const styles = StyleSheet.create({ button: { @@ -82,9 +87,15 @@ const Url = React.memo(({ const onPress = () => openLink(url.url, theme); + const onLongPress = () => { + Clipboard.setString(url.url); + EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') }); + }; + return ( 0 && styles.marginTop,