2016-07-27 104 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