Skip to content
9 changes: 8 additions & 1 deletion app/containers/markdown/Link.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 (
<Text
onPress={preview ? undefined : handlePress}
onLongPress={onLongPress}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to handle preview cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preview Cases are handled by the onPress function already.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we not want that when user long press a link on roomsListView this link are copy. Use some condition like on onPress.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will apply some conditions

style={
!preview
? { ...styles.link, color: themes[theme].actionTintColor }
Expand Down
19 changes: 16 additions & 3 deletions app/containers/message/Urls.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import {
View,
Text,
StyleSheet,
Clipboard,
ToastAndroid,
Platform,
Vibration
} from 'react-native';
Comment on lines +2 to +4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included Clipboard, Vibrations, Platform modules of react-native which are not required by Url.js as they aren't required there. I included them for fixing the issue but you redirected me to our own Toast.js component, therefore, I removed the modules.
I'll revert them.

import PropTypes from 'prop-types';
import FastImage from 'react-native-fast-image';
import Touchable from 'react-native-platform-touchable';
import isEqual from 'lodash/isEqual';
Comment on lines 1 to 8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, undo all changes in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they'll be undone


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo these changes.

import openLink from '../../utils/openLink';
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';

const styles = StyleSheet.create({
button: {
Expand Down Expand Up @@ -81,10 +90,14 @@ const Url = React.memo(({
}

const onPress = () => openLink(url.url, theme);

Comment thread
djorkaeffalexandre marked this conversation as resolved.
const onLongPress = () => {
Clipboard.setString(url.url);
EventEmitter.emit(LISTENER, { message: 'Copied_to_clipboard' });
};
Comment on lines +91 to +93

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For first, you don't need to use ToastAndroid, we have our own Toast Component, you can search on our code how to use this.
I don't think you need to add some vibration when a link was copied, only the Toast is a feedback great.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Thanks for the guidance. 👍

return (
<Touchable
onPress={onPress}
onLongPress={onLongPress}
style={[
styles.button,
index > 0 && styles.marginTop,
Expand Down