react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Click and hold to select text using a text component

Open yasemincidem opened this issue 8 years ago • 39 comments

Description

I want click-and-hold-to-select-text using a Text component and then i searched it and i found selectable property.It good works but it copy the entire text field.I want to selecting a subset of the text field for copying.Actually this question is asked on stackoverflow .Here is question on stackoverflow:http://stackoverflow.com/a/37119619/4596143

Reproduction Steps and Sample Code

I try this code block:

<Text
                        selectable={true}
                        style={styles.messageBody}>
                        {"text description"}
</Text>

This full of text ("text description") can copy not partially .I want to it like screenshot

Actual behaviour: image

Expected behavior:

image

Solution

They are said that RN 0.39 adds support to copy the entire text field, but does not yet include support for selecting a subset of the text field for copying on stackoverflow .I wonder Text component include support for selecting a subset of the text field for copying on new versions for react native.If the property does not exist on new versions ,will the property for text integrate ?

Additional Information

  • React Native version:^0.43
  • Platform: IOS
  • Development Operating System: macOS

yasemincidem avatar May 12 '17 07:05 yasemincidem

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

hramos avatar Jul 20 '17 22:07 hramos

This is still reproducible with "react-native": "0.49.0"

ArsenyYankovsky avatar Nov 11 '17 02:11 ArsenyYankovsky

@hramos Could you please reopen that?

ArsenyYankovsky avatar Dec 07 '17 14:12 ArsenyYankovsky

Adding selectable={true} or selectable is not working. v 0.51-RC

kasiselvamk avatar Jan 15 '18 17:01 kasiselvamk

For me, both platforms are existing different problems :

In IOS, adding selectable={true} or selectable is not working for selecting partially text In Android: adding selectable={true} or selectable is working but the nested image in text is disappeared for SOME devices Environment: React Native v0.51

tikkichan4 avatar Jan 29 '18 05:01 tikkichan4

I really need this feature... I'm on 0.52 v and I only can see "Copy" but not the expected behavior as it is said. Someone knows if there is a way to do so?

pausabe avatar Feb 05 '18 14:02 pausabe

@pausabe If you really want this and you dont have complex nested component in Text component. Just using TextInput instead of Text and pass editable={false} as the prop and set the padding and margin as 0. The behavior is just same as Text but selectable. Hope this help.

tikkichan4 avatar Feb 09 '18 16:02 tikkichan4

Thanks @tikkichan4! I've tried this in a simple text with the editable={false} but the text is not selectable... Besides, I need this for complex nested Text so I image that this is not the way I should do it. I hope Text component becomes more completed with this feature some day!

pausabe avatar Feb 12 '18 12:02 pausabe

I think this feature is necessary.

michchan avatar Mar 20 '18 13:03 michchan

+1

fenglu09 avatar Apr 20 '18 01:04 fenglu09

@yasemincidem Have you found a solution?

fenglu09 avatar Apr 20 '18 01:04 fenglu09

This issue looks like a question and not an actual bug report. Please try asking over on Stack Overflow instead.

react-native-bot avatar May 07 '18 17:05 react-native-bot

Hello guys, How I can get the word selected when set selectable={true} Can you tell me? Ths.

BichCNTT avatar May 09 '18 10:05 BichCNTT

@BichCNTT you can try this https://github.com/status-im/status-react/issues/3616

ethanleeX avatar Jun 14 '18 08:06 ethanleeX

@react-native-bot this issue should be reopened

wcandillon avatar Aug 02 '18 08:08 wcandillon

+1

singhsoldier13 avatar Aug 16 '18 23:08 singhsoldier13

+1

thinhtrh avatar Sep 05 '18 03:09 thinhtrh

+1

yusent avatar Sep 19 '18 16:09 yusent

+1

ezrra avatar Sep 19 '18 19:09 ezrra

+1

ghost avatar Oct 05 '18 21:10 ghost

+1

axelfrid avatar Oct 23 '18 11:10 axelfrid

+1

j-ornelas avatar Nov 16 '18 01:11 j-ornelas

+1

xinfang avatar Nov 27 '18 06:11 xinfang

+1

mraak avatar Nov 27 '18 08:11 mraak

+1

AbdelhalimAhmed avatar Nov 27 '18 17:11 AbdelhalimAhmed

+1

jeongsd avatar Nov 28 '18 07:11 jeongsd

this issue should be reopened again

kala888 avatar Nov 29 '18 03:11 kala888

Here is a temporary solution。

    {imageText.length > 0 &&
                device.ios && (
                  <AutoGrowingTextInput
                    scrollEnabled={false}
                    value={`        ${imageText}`}
                    editable={false}
                  />
                )}

              {imageText.length > 0 &&
                device.android && (
                  <Text selectable>
                    {'        '}
                    {imageText}
                  </Text>
                )}

kala888 avatar Nov 29 '18 05:11 kala888

I've published a workaround for now if you're interested: https://github.com/msand/react-native-selectable-text

It's only needed on Android, and works as a drop-in replacement for a TextInput with these specific values on iOS, as TextInput with editable: false already works correctly there. TextInput on Android either fills most of the screen with the keyboard, or disables the ability to select and respond to selection changes. I would assume this component only works well for the specific use-case I had, haven't tested it for any other prop values.

import SelectableText from 'react-native-selectable-text';

export default ({ text, onSelectionChange }) => (
  <SelectableText
    selectable
    multiline
    contextMenuHidden
    scrollEnabled={false}
    editable={false}
    onSelectionChange={onSelectionChange}
    style={{
      color: "#BAB6C8",
    }}
    value={text}
  />);

msand avatar Dec 12 '18 04:12 msand

My solution is to use https://www.npmjs.com/package/react-native-webview-autoheight and load text as html.

zhouanbo avatar Dec 21 '18 20:12 zhouanbo