joshswan / react-native-autolink

Automatic linking of URLs, phone numbers, emails, handles, and even custom patterns in text for React Native
MIT License
649 stars 82 forks source link

Feature: user-specified custom link pattern handling #54

Closed lafiosca closed 3 years ago

lafiosca commented 3 years ago

Hello, thanks for providing this awesome library! We've been using it for a long time now, since v1. We're in the process of adding @-mentions to our app, using react-native-controlled-mentions. We need the ability to render those encoded mentions as links to user profiles to be handled internally by app navigation, but we want to keep the ability to render external links as well. For example:

image

I created a patch to your library to allow users to specify link regex patterns with custom styling and handling to allow us to accomplish this. I thought this might be helpful for a wider variety of uses, as discussed previously in #30 and #25 as well as others, so I am providing this PR. The new logic does however take a slightly different approach, allowing the user to specify styles and press handlers specific to a link type rather than using the top-level override functions. So I will understand if you do not want to incorporate these changes.

joshswan commented 3 years ago

Hey @lafiosca, thanks for this awesome PR! At first glance, I'm totally on board with merging this as it's basically exactly how I was thinking of addressing those feature requests but never had the time to actually implement :)

I'll review this weekend - might do some tweaking and I'm tempted to remove latlng in favor of custom matchers. But looks great to me based on a quick look.

weslleyaraujo commented 3 years ago

@lafiosca this is awesome! I needed exactly that, handle a custom pattern and perform a custom action for it. In my case I need to override the default behaviour for hashtags:

https://user-images.githubusercontent.com/2286385/112681057-737c3a00-8e6e-11eb-89d7-ccc404ebfc44.mov

I made a custom build from your branch to test it, neat 🤘

joshswan commented 3 years ago

@lafiosca @weslleyaraujo v4.0.0-rc.0 has been published to npm. There were a few changes to prop/option names but all the same functionality should be present. Still a pre-release so additional PRs or feedback welcome :)

weslleyaraujo commented 3 years ago

Thanks @joshswan ! I am gonna try the RC and report back case I find something 👍