Git Product home page Git Product logo

react-native-link-preview's Introduction

⚠️⚠️ Currently not maintained, please fork or look for alternatives ⚠️⚠️

React Native Link Preview

npm build Maintainability Test Coverage type-coverage

Fully customizable preview of the URL extracted from the provided text.

Getting Started

yarn add @flyerhq/react-native-link-preview

Usage

import { LinkPreview } from '@flyerhq/react-native-link-preview'
// ...
return (
  <LinkPreview text='This link https://github.com/flyerhq can be extracted from the text' />
)

Props

Required

Name Type Description
text string Text to extract the link from

Optional

Name Type Description
containerStyle ViewStyle Top level container style
enableAnimation boolean Enables LayoutAnimation
header string Text above the link
metadataContainerStyle ViewStyle Title, description and minimized image container style
metadataTextContainerStyle ViewStyle Title and description container style
onPreviewDataFetched (PreviewData) => void Callback to get the fetched preview data
previewData PreviewData Data to render instead of parsing the provided text
renderDescription (string) => ReactNode Custom description render prop
renderHeader (string) => ReactNode Custom header render prop
renderImage (PreviewDataImage) => ReactNode Custom image render prop
renderLinkPreview ({ aspectRatio?: number, containerWidth: number, previewData?: PreviewData }) => ReactNode Custom render prop
renderMinimizedImage (PreviewDataImage) => ReactNode Custom minimised image render prop
renderText (string) => ReactNode Custom provided text render prop
renderTitle (string) => ReactNode Custom title render prop
requestTimeout number Timeout after which request to get preview data should abort
textContainerStyle ViewStyle Text, title, description and minimized image container style
touchableWithoutFeedbackProps TouchableWithoutFeedbackProps Top level touchable props

License

MIT

react-native-link-preview's People

Contributors

ammarahm-ed avatar anton-cleo avatar demchenkoalex avatar tpxp avatar vdanylov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-link-preview's Issues

Styling

Hello, thanks for this truly beautiful but currently can't change stylings of the preview link title and description, and also it seems to only show a preview for one link and not for multiple links, currently I just edited your style.js for this moment, hope to get feedbacks, thanks.

[🐛] Youtube link preview not working correctly on iOS

Issue

On iOS it only shows 'Youtube - Share your videos with friends family and the world'. It's working perfectly on Android with title, description and a preview image.

Reproduce

  1. yarn add @flyerhq/react-native-link-preview
  2. import { LinkPreview } from '@flyerhq/react-native-link-preview'
  3. <LinkPreview text='This link https://www.youtube.com/watch?v=dpw9EHDh2bM can be extracted from the text' />

What I tried

Testing in both Simulator and real device (iPhone X). And I got only a youtube title, no description and no preview image.

Environment

Click to expand!
System:
    OS: macOS 11.2.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 247.37 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.13.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 7.6.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.2
      System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.6953283
    Xcode: 12.4/12D4e - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_242 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.4 => 0.63.4
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Thank you!

Temporary fix I found

When using the Youtube link on react-native, Youtube somehow redirects to the home page of the mobile version, effectively losing all information. Adding a user-agent header temporary fixed the issue.

headers: {
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
},

Can I limit the amount of data fetched when previewing a URL?

We use this module to show link previews for links posted in our app and it works great. Users can type any link in the textbox and it will show a preview of the link before the post is sent.

However, we've found that if a user types a link to a huge file (for example, an Ubuntu ISO), the app will download the whole file since it makes a fetch call on the URL.
https://github.com/flyerhq/react-native-link-preview/blob/main/src/utils.ts#L80

As can be seen in Flipper:
image

Is there a way to stop the download after fetching obviously too much data, say 1MB? Fetching too much/infinite data could cause an app crash by using too much memory. Granted, we can limit the impact of this by fetching the data server-side and passing previewData, in which case only the post sender would fetch that much data. Yet if we could avoid that behaviour, that would be great too.

Custom Interface

Can I custom position view , like i drop image in left , header and desc in right

Feature request - Caching

When you put multiple link preview components to the screen with same link, then it makes multiple fetches to the link. In our use case we could have thousands of previews with same link

Prevent opening link and add longPress event

Hi, I'd like to add the longPress event to the preview (wrapped inside Pressable), but it always opens the link. Is there a way that I could prevent the title/text or image opening the link and wrap the content inside Pressable, so the I can open up a different menu on longPress?

Add option to show/hide URL

A feed system rarely shows the underlying URL, add support to show/hide URL. A custom renderURL can also be an option, then consumers can just return null for that function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.