React Native & iframe & WebView

React Native & iframe & WebView

React Native 怎么渲染 iframe 页面

WebView & source html

https://facebook.github.io/react-native/docs/webview#source
https://facebook.github.io/react-native/docs/webview.html#html

// old

import { WebView } from "react-native";

740516-20190429092932044-1607521044.png

740516-20190429093006177-1437967859.png

https://github.com/react-native-community/react-native-webview

# install
$ yarn add react-native-webview

# link
$ react-native link react-native-webview
// new 

import { WebView } from "react-native-webview";

WebView

https://reactscript.com/tag/iframe/

http://www.hangge.com/blog/cache/detail_1564.html


/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 *
 * @description WebViewIframe
 * @augments
 * @example
 *
 */

import React, {Component} from "react";
import {
    StyleSheet,
    Dimensions,
    Text,
    View,
    WebView
} from "react-native";

// 获取设备的宽度和高度
let {
    height: deviceHeight,
    width: deviceWidth
} = Dimensions.get("window");

class WebViewIframe extends Component {
    render() {
        return (
            <View style={styles.container}>
              <WebView bounces={false}
                scalesPageToFit={true}
                source={{
                    uri:"https://cdn.xgqfrms.xyz",
                    method: "GET",
                }}
                style={{
                    width:deviceWidth,
                    height:deviceHeight,
                }}>
              </WebView>
            </View>
        );
    }
}

// css-in-js
const styles = StyleSheet.create({
    container: {
        flex: 1,
        paddingTop:20
    }
});

export default WebViewIframe;

export {
    WebViewIframe,
};

new version


/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 *
 * @description WebViewIframe
 * @augments
 * @example
 *
 */

import React, {Component} from "react";
import {
    StyleSheet,
    Dimensions,
    Text,
    View,
    WebView
} from "react-native";

// 获取设备的宽度和高度
let {
    height: deviceHeight,
    width: deviceWidth
} = Dimensions.get("window");

class WebViewIframe extends Component {
    render() {
        return (
            <View style={styles.container}>
                {/* <WebView
                    bounces={false}
                    scalesPageToFit={true}
                    source={{
                        uri:"https://cdn.xgqfrms.xyz",
                        method: "GET",
                    }}
                    style={{
                        width: deviceWidth,
                        height: deviceHeight,
                    }}>
                </WebView> */}
                {/* <WebView
                    bounces={false}
                    scalesPageToFit={true}
                    source={{
                        html: `
                            <h1 style="color: #0f0;">
                                WebView & Iframe
                            </h1>
                        `,
                    }}
                    style={{
                        width: "100%",
                        height: 30,
                    }}>
                </WebView> */}
                <WebView
                    bounces={false}
                    scalesPageToFit={true}
                    source={{
                        html: `
                            <iframe
                                name="iframeWindow"
                                src="https://cdn.xgqfrms.xyz"
                                width="100%"
                                height="300"
                                data-dom="iframe"
                                target="_self"
                                about:blank
                                style="border: 1px solid red;"
                            >
                            </iframe>
                        `,
                    }}
                    style={{
                        width: "100%",
                        height: 300,
                    }}>
                </WebView>
            </View>
        );
    }
}

// css-in-js
const styles = StyleSheet.create({
    container: {
        flex: 1,
        paddingTop:20
    }
});

export default WebViewIframe;

export {
    WebViewIframe,
};


https://github.com/archriss/react-native-render-html
https://stackoverflow.com/questions/53736424/how-to-render-html-table-in-react-native

Render HTML in React Native

https://stackoverflow.com/questions/29334984/render-html-in-react-native

转载于:https://www.cnblogs.com/xgqfrms/p/10788441.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值