Giter VIP home page Giter VIP logo

react-native-url-preview's Introduction

react-native-url-preview 🐜

NPM

Parses text and wraps URLs , transform the url to a beautiful link preview

Getting started 🐜

$ npm install react-native-url-preview --save

Usage 🐜

import RNUrlPreview from 'react-native-url-preview';

<RNUrlPreview text={"any text to be parsed , https://www.youtube.com/watch?v=Kmiw4FYTg2U"}/>

Examples🐜

Please refer to the react-native-url-preview example provided to see how react-native-url-preview can be used .

Demo🐜

Β  Β 

Customization 🐜

Parameter Required? Default Type Description
text YES Null string The text that is parsed and where the URL is retrieved
title NO True Boolean determine whether the URL title is displyed or not
description NO True Boolean determine whether the URL description is displyed or not
titleStyle NO defaultStyle style self explanatory i believe
containerStyle NO defaultStyle style you can pass a custom container style
imageStyle NO defaultStyle style you can pass a custom image style
faviconStyle NO defaultStyle style you can pass a custom favicon style
textContainerStyle NO defaultStyle style you can pass a custom style for the text container
descriptionStyle NO defaultStyle style self explanatory i believe
titleNumberOfLines NO 2 number self explanatory i believe
descriptionNumberOfLines NO Ipad?4:3 number self explanatory i believe
imageProps NO { resizeMode: "contain"} object you can pass a custom props to image
requestOptions NO {} object pass additional options to url preview request
onLoad NO () => {} function callback called when url preview data is loaded
onError NO () => {} function callback called if url preview fails to load

Credits 🐜

react-native-url-preview's People

Contributors

dependabot[bot] avatar dfabreguette avatar evanb2 avatar hermanyo avatar maherzaidoune avatar moneemsaadaoui avatar nmvikings avatar sam1463 avatar vuki656 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

Watchers

 avatar  avatar  avatar  avatar

react-native-url-preview's Issues

link https://fb.watch is not working

Component <RNUrlPreview text={'https://fb.watch'} onError={(error) => console.log('eere', error)} onLoad={console.log} /> creates such view:
fb watch

Handler onLoad outputs this info:

contentType: "application/vnd.wap.xhtml+xml; charset=utf-8"
favicons: ["https://m.facebook.com/favicon.ico"]
mediaType: "application"
url: "https://m.facebook.com/watch"

Handler onError does not firing.

So, when I tap this url preview, I get this error:

TypeError: Cannot read property '0' of null

Add web support

Hi,
I really like this library. But I got this err 'TypeError: Cannot read property 'style' of undefined
' when I set up on webapp.

Loading Component

Add a loading component (may be a custom one like shimmer) while the link is loading

Extending style props is not working

Hi, I really appreciate this library.

When I try to customize the rendering by using some props as textContainerStyle, it overrides the default value

Doesnt render again when text changed

I have an input and im trying to develop input as twitter. In this case, i needed to check links and display them. If this library works once correct, doesnt change after that.

const UrlPreview = ({ text }) => {
  useEffect(() => {}, [text]);
  return (
    <View style={{ width: '100%', height: 200 }}>
      <Text>{text}</Text>
      <RNUrlPreview text={text} />
    </View>
  );
};

I'm passing my changevalue from input here. I added text component to check text is changed, yes text is changed but rnurlpreview doesnt display new url. I hope it is clear, is there any suggestion?

New feature: onPress props

Hi there,

Thanks for this great library.

Would it be possible to add an onPress prop? This would allow to use an in-app browser or open up plenty of possibilities.

Best

Images are not displayed

Try putting an image url like that, or any other working image URL.
<UrlPreview text="https://i.picsum.photos/id/630/200/300.jpg" />

Instead of an image preview you will see container with the background.
I checked on the code. There is an error of getting image URL link from array of data.images.

Could not find a declaration file for module 'react-native-url-preview'

Could not find a declaration file for module 'react-native-url-preview'. '/node_modules/react-native-url-preview/index.js' implicitly has an 'any' type.
Try `npm install @types/react-native-url-preview` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-url-preview';`

Should add support to TypeScript declaration.

Noticed link wasn't being updated. Bug?

I noticed in a list of link previews that the latest item in the list wouldn't have the updated url

is this right? doesn't componentDidUpdate get previous props instead of next props?

 componentDidUpdate(nextProps) {
    if (nextProps.text !== this.props.text) {
      this.getPreview(nextProps.text);
    } else if (nextProps.text == null) {
      this.setState({isUri: false});
    }
  }

this works

 componentDidUpdate(prevProps) {
    if (prevProps.text !== this.props.text) {
      this.getPreview(this.props.text);
    } else if (this.props.text == null) {
      this.setState({isUri: false});
    }
  }

Not working

Hi, i use a simple case like your example but getting error when loading
I'm using React Native version 0.61.5
"Attempt to invoke interface method 'java.lang.String com.facebook.react.bridge.ReadableMap.getString(java.lang.String)' on a null object reference"

Support web

Hey!
I really love this library, and it works perfectly on native platforms.
The only thing is I'm using my app on the web with react-native-web.
I get this error:

TypeError: Cannot read property 'style' of undefined
Module.../../../../../../../../../Users/kristinabuscail/nodejs/wavychat-expo/node_modules/react-native-url-preview/index.js
node_modules/react-native-url-preview/index.js:252
249 | onLoad: PropTypes.func,
250 | onError: PropTypes.func,
251 | text: PropTypes.string,

252 | containerStyle: ViewPropTypes.style,
253 | imageStyle: ViewPropTypes.style,
254 | faviconStyle: ViewPropTypes.style,
255 | textContainerStyle: ViewPropTypes.style,
View compiled

Would be really cool to have your help.
BTW could you add typescript types. Would be much easier

LinkPreviewError

I'm honestly not sure if this is an issue with RNUrlPreview but in the latest build of our app some link previews were not rendering and on inspection we were getting LinkPreviewError logged in the console for those urls which then don't render the preview.

"github.com" works
"https://www.google.com" fails
"www.google.com" works on Android, fails on iOS
"omnilife.ai" fails
"www.omnilife.ai" works

To diagnose I regressed back to our last release branch and rebuilt the app - with the same failures as above, yet our live app works.

The only difference that I can see therefore is that both xcode and Android studio have both upgraded. I may be clutching at straws, but could there be an issue with your library and xcode 11.4.1?

customize onPress prop

Hi there,

I'm using your package and found that whatever I do on 'onPress' action, it will redirect me to my external browser. Please have it customizable so that we can also navigate within the App if we want when the link is pressed.

Feature Request: support for closing url previews

Hi, really appreciate this library! I'm using it to render url previews in a chat, and I would like to support "close preview" functionality, where a preview is rendered, but if the user presses a close button, it would hide the preview for the remainder of the time that the component is mounted.

I have two ideas for how to do this, but both would require changes to this library, so wanted to get feedback on whether you'd have a preference, so I can try to implement one and open a PR.

  1. Update this library to accept callback props like onLoad and onError which would be called when the info is successfully retrieved to render the preview, or if that fails, respectively. These could be used by consumers of this library to listen for when the preview is ready (or if getting the preview failed), and then render their own "close" button and stop rendering the url-preview component if it's pressed. Without these listeners, I could still render my own "close" button to hide the preview, but I won't know whether the preview is even rendering, so it would end up looking weird having just a "close preview" button without a preview present πŸ˜„
  2. Add the functionality for closing previews directly to this library. Could just be an "X" icon in the top right that updates component state to hide the preview when it's pressed, and maybe support for passing in a custom button as a prop.

I would be happy to do either (or both) and open a PR, but wanted to get feedback first. Let me know what you think!

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.