xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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";


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



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @   xgqfrms  阅读(1072)  评论(2编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2016-04-29 配置Nginx前端 + Apache后端服务器环境
点击右上角即可分享
微信分享提示