2016-07-27 105 views
0

我试图让用户在反应本机中看到网页预览,就像在Facebook和其他应用上看到的链接预览一样。我做了一些研究。在React-Native中获取页面预览

我已经看到了一些库,它提供了节点的功能,但它不反应天然的(因为原来cheerio.js不与反应母语直接合作)

https://github.com/cheeriojs/cheerio

工作

我也检查了oEmbed库,但它似乎也没有工作。

我想知道什么可能是让网页预览

回答

2

最后写一个小型图书馆,没有工作的好方法。希望这是非常有用的一些人

https://github.com/changey/react-native-page-previewer

使用

import preview from 'react-native-page-previewer'; 

preview("http://www.google.com", function(err, data) { 
    if(!err) { 
     console.log(data); 
    } 
}); 

采样返回

{ url: 'https://www.google.com', 
    loadFailed: false, 
    title: 'Google', 
    description: 'Search the world\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\'re looking for.', 
    contentType: 'text/html', 
    mediaType: 'website', 
    images: [ 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_white_background_color_272x92dp.png' ], 
    videos: undefined, 
    audios: undefined } 
+0

嘿,我一直在试图使用你的库,但是当我尝试预览谷歌.com我得到一个未处理的承诺拒绝和任何其他页面给出未定义的数据,任何想法? – ospfranco

+0

@ospfranco前段时间合并了一个修复。你能再试一次吗?谢谢! – changey