obipawan / react-native-hyperlink

A <Hyperlink /> component for react-native that makes urls, fuzzy links, emails etc clickable
MIT License
801 stars 76 forks source link

Add TestID to clickable part for e2e tests #43

Closed gran33 closed 4 years ago

gran33 commented 5 years ago

Is your feature request related to a problem? Please describe. Yes. I'm using Detox to e2e tests and Detox can't press on the link without TestID.

Describe the solution you'd like Please add the ability to set TestID to the clickable component. See RN docs for TestId: https://facebook.github.io/react-native/docs/view#testid

Describe alternatives you've considered None.

Additional context Thank you so much, you're awesome 😎

obipawan commented 4 years ago

Hi @gran33 thank you for the context 😄 could you suggest how'd you want to be able to pass down the TestID? I could use some help with the design.

I was thinking something like so

<Hyperlink injectProps={ url => ({TestID: "testID for the given URL"}) }>
    ...
    ...
</Hyperlink>
gran33 commented 4 years ago

Hi @obipawan I there any way to pass props to the clickable part of the hyperlink? injectProps isn't self explanatory (sorry for the douchebaging 😏) I think injectViewProps :)

WDYT?

obipawan commented 4 years ago

injectViewProps sounds good. Apart from the proposed injectViewProps, there isn't a way to pass props to a clickable component. So a func with url as the param and returning props sounds good?

obipawan commented 4 years ago

Opened a PR #46 LMK if this seems good. I'll go ahead with a release if it's all good

gran33 commented 4 years ago

Hi, Thanks for the PR. Why that?

there isn't a way to pass props to a clickable component

obipawan commented 4 years ago

This PR should solve that. You could pass props to a clickable component identified by the url

gran33 commented 4 years ago

Ok, sounds good. As long as I can identify the clickable part by its testID

obipawan commented 4 years ago

Thanks @gran33 Just to clarify, you can pass props to the clickable part identified by the url it matched, like so,

<Hyperlink
  ...
  injectViewProps={ url => ({
        testID: url === 'some url' ? 'id1' : 'id2' ,
        style: url === 'some url' ? { color: 'red', fontSize: 20 } : { ... },
        //any other props you wish to pass to the component
  }) }
>
  ...
  ...
</Hyperlink>
gran33 commented 4 years ago

Amazing! Thanks @obipawan

obipawan commented 4 years ago

Great. Then i'll merge this Thanks for your help @gran33

obipawan commented 4 years ago

Available on v0.0.19