1.0.4 • Published 1 year ago

react-native-hyperlinks v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

A simple and customizable library to display hyperlinks in React Native

Features ✨

  • 🛑 Automatic detection for links, mentions and hashtags
  • 🔤 Full unicode support
  • 🌐 International domains support
  • 💅 Custom hyperlink style
  • ⚙️ Custom linkify-it instance
  • 📦 Tiny
  • 🚀 Created with Typescript

About 🗞️

Uses linkify-it under the hood. Created for my social network app, Drakkle

Installation ⚙️

yarn add react-native-hyperlinks linkify-it

Usage 🔨

import React from "react";
import { Linking } from "react-native";
import Hyperlinks from "react-native-hyperlinks";

export default function App() {
  function handleOnLinkPress(link: string) {
    console.log(link)
  }

  function handleOnMentionPress (username: string) {
    console.log(username)
  }

  function handleOnHashtagPress (tag: string) {
    console.log(tag)
  }

  return (
    <Hyperlinks
      text="Hello!! @andresribeiro #hi https://duck.com aaaaa"
      style={{ fontSize: 18 }}
      hyperlinkStyle={{ color: 'purple' }}
      onLinkPress={handleOnLinkPress}
      onMentionPress={handleOnMentionPress}
      onHashtagPress={handleOnHashtagPress}
    />
  );
}

Props ✍️

PropertyDefaultTypeRequired
textundefinedstringtrue
hyperlinkStyleundefinedStyleProp<TextStyle>false
autoDetectMentionstruebooleanfalse
autoDetectHastagstruebooleanfalse
customHyperlinksundefinedCustomHyperlink[]false
onLinkPressundefined(link: string) => unknownfalse
onMentionPressundefined(username: string) => unknownfalse
onHashtagPressundefined(tag: string) => unknownfalse
onCustomHyperlinkPressundefined(hyperlink: CustomHyperlink) => unknownfalse
linkifylinkifyIt()linkifyIt.LinkifyItfalse