RN 实现简易浏览器
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Dimensions,
  StatusBar,
  TouchableOpacity,
  TextInput,
  WebView
} from 'react-native';
var {width,height} =Dimensions.get('window')
export default class demo extends Component {
  constructor(props){
    super(props);
    this.state={
      source:{
        uri:"https://www.baidu.com"
      },
      status:"NO page Loaded",
      backBuutonEnabled:false,
      forwardButtonEnabled:false,
    }
    this.inputURL="";
    this.goBack=this.goBack.bind(this);
    this.goForward=this.goForward.bind(this);
    this.goButton=this.goButton.bind(this);
    this.stateChange=this.stateChange.bind(this);
    this.onMessage=this.onMessage.bind(this)
  }
  onMessage(data){
    console.log("网页的数据");
  }
  stateChange(navState){
    console.log("网页路由数据");
    console.log(navState);
    this.setState({
      backBuutonEnabled:navState.canGoBack,
      forwardButtonEnabled:navState.canGoForward,
      status:navState.title,
    })
  }
  goBack(){
    //让webView组件退回
    this.refs.webViewRef.goBack();
  }
  //网页前进
  goForward(){
    this.refs.webViewRef.goForward();
  }
  //searh
  goButton(){
    console.log(this.inputURL.toLowerCase());
    //在input和Go都调用这个方法
    let uri=this.inputURL.toLowerCase();
    if(uri==this.state.source.uri){
      //当网页和当前的网址相同时候 重载网址
      this.refs.webViewRef.reload();
      console.log("zhogzao");
    }else{
      console.log("加载新网页");
      let source={};
      source.uri=uri;
      this.setState({
        source
      })
    }
  }
  render() {
    return (
      <View style={styles.container}>
        <StatusBar hidden={true}/>
        <View style={styles.addressBarRow}>
          <TouchableOpacity
            onPress={this.goBack}
            style={this.state.backBuutonEnabled?styles.navButton:styles.disableButton}>
            <Text>{'<'}</Text>
          </TouchableOpacity>
          <TouchableOpacity
              onPress={this.goForward}
            style={this.state.forwardButtonEnabled?styles.navButton:styles.disableButton}>
            <Text>{'>'}</Text>
          </TouchableOpacity>
          <TextInput ref="urlInputRef"
          autoCapitalize="none"
          style={styles.addressInput}
          defaultValue={this.state.url}
          onSubmitEditing={this.goButton}
          onChangeText={(newText)=>this.inputURL=newText}
          clearButtonMode='while-editing'
          />
          <TouchableOpacity
            onPress={this.goButton}
            style={styles.goButton}>
            <Text>Go!</Text>
          </TouchableOpacity>
        </View>
        <WebView
          ref="webViewRef"
          style={styles.webView}
          source={this.state.source}
          javaScriptEnabled={true}
          // 仅限Android平台。指定是否开启DOM本地存储
          domStorageEnabled={true}
          //网页导航 返回的是一些参数对象
          onNavigationStateChange={this.stateChange}
          // 强制WebView在第一次加载时先显示loading视图。默认为true
          startInLoadingState={true}
          //在网页端注入函数 这里得到返回的数据 从而达到RN和网页端的数据的交换
          // onMessage={this.onMessage}
        />
        <View style={styles.statusBar}>
          <Text style={styles.statusBarText}>{this.state.status}</Text>
        </View>
      </View>
    );
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'blue',
  },
  addressBarRow:{
    flexDirection:'row',
    padding:8,
  },
  navButton:{
    width:20,
    padding:3,
    marginRight:20,
    alignItems:'center',
    justifyContent:'center',
    backgroundColor:'#fff',
    borderColor:'transparent',
    borderRadius:3
  },
  disableButton:{
    width:20,
    padding:3,
    marginRight:20,
    alignItems:'center',
    justifyContent:'center',
    backgroundColor:'grey',
    borderColor:'transparent',
    borderRadius:3
  },
  addressInput:{
    backgroundColor:'#fff',
    borderColor:'transparent',
    borderRadius:3,
    height:24,
    paddingLeft:10,
    paddingTop:3,paddingBottom:3,
    flex:1,
    fontSize:14,
  },
  goButton:{
    height:24,
    padding:3,
    marginLeft:8,
    alignItems:'center',
    justifyContent:'center',
    borderColor:'transparent',
    borderRadius:3,
    alignSelf:'stretch'
  },
  webView:{
    backgroundColor:'#fff',
    height:350
  },
  statusBar:{
    flexDirection:'row',
    alignItems:'center',
    paddingLeft:5,
    height:22
  },
  statusBarText:{
    color:'#fff',
    fontSize:13
  }
});
AppRegistry.registerComponent('demo', () => demo);
RN 实现简易浏览器的更多相关文章
- 第4课 简易浏览器-WebViewer组件的使用方法
		做一个手机浏览器,需要哪些组件呢? 一.组件设计 二.组件属性及命名修改 三.逻辑设计 1.导航按钮代码:前进.后退.主页 2.访问网页按钮 1)根据用户在地址栏输入的地址书写,判断书写中是否含有“h ... 
- python3用pyqt5开发简易浏览器
		http://python.jobbole.com/82715/ 在这篇教程中,我们会用 Python 的 PyQt 框架编写一个简单的 web 浏览器.关于 PyQt ,你可能已经有所耳闻了,它是 ... 
- (五十九)iOS网络基础之UIWebView简易浏览器实现
		[UIWebView网络浏览器] 通过webView的loadRequest方法可以发送请求显示相应的网站,例如: NSURL *url = [NSURL URLWithString:@"h ... 
- 简易浏览器App webview
		使用 public class MainActivity extends Activity { @Override protected void onCreate(Bundle sav ... 
- HTTP协议之 简易浏览器(3)--转载
		简单的说,今天的全部工作就是 我的目的只有两个 1.加深对http协议的理解 2.深化对B/S结构的认识. 代码 1 /* 2 这个程序把主机地址写死了, 3 想更像的话,可以在加个输入.然后根据 ... 
- C# 封装miniblink 使用HTML/CSS/JS来构建.Net 应用程序界面和简易浏览器
		MiniBlink的作者是 龙泉寺扫地僧 miniblink是什么? (抄了一下 龙泉寺扫地僧 写的简洁) Miniblink是一个全新的.追求极致小巧的浏览器内核项目,其基于chromium最新 ... 
- 写一个简易浏览器、ASP.NET核心知识(3)
		前言 先在文章前面说好了,省得大家发现我根本没有这样的头发,duang的一下一堆人骂我. 这篇文章的标题有点大,其实挺low的,我需要在开头解释一下.我这里只想写一个小的控制台,旨在模拟浏览器的htt ... 
- 手机 简易浏览器 WebView的基本使用 返回 缓存 进度条
		public class MainActivity extends AppCompatActivity { private WebView webView; private String url = ... 
- 【原创】闲来无事,用Winform写了个简易浏览器
		核心是利用了winform自带的WebBrowser控件,修改了下IE内核的版本,目前还是单线程的,逻辑挺简单的,萌新都能看懂. 废话不多说,上代码,附打包project. 链接:https://pa ... 
随机推荐
- [转载]SQL Server中的事务与锁
			了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂,不能保证数据的安全正确读写. 死锁: ... 
- 介绍python中运算符优先级
			下面这个表给出Python的运算符优先级,从最低的优先级(最松散地结合)到最高的优先级(最紧密地结合).这意味着在一个表达式中,Python会首先计算表中较下面的运算符,然后在计算列在表上部的运算符. ... 
- gradle 定义打包后的项目名
			war { archiveName 'ROOT.war' } 或 task makeWar(type:org.gradle.api.tasks.bundling.War) { //指定生成的jar名 ... 
- nginx负载均衡六种策略
			Nginx服务器之负载均衡策略(6种) 一.关于Nginx的负载均衡 在服务器集群中,Nginx起到一个代理服务器的角色(即反向代理),为了避免单独一个服务器压力过大,将来自用户的请求转发给不同的 ... 
- Prometheus监控学习笔记之解读prometheus监控kubernetes的配置文件
			0x00 概述 Prometheus 是一个开源和社区驱动的监控&报警&时序数据库的项目.来源于谷歌BorgMon项目.现在最常见的Kubernetes容器管理系统中,通常会搭配Pro ... 
- Solr导入MySQL数据之dataimport-handler
			Solr不借助手动JSolr编程情况下也可以将Mysql的数据导入到Solr中.实现方式是安装dataimport-Handler从关系数据库将数据导入到索引库. 1.向SolrCore中加入jar包 ... 
- R语言开发环境搭建
			R语言开发环境搭建 一.环境 Win7 64bit系统 二.R软件下载 R 3.5.2 for Windows,官网:https://www.r-project.org/ RStudio 1.1.46 ... 
- alert.log中的minact-scn: useg scan erroring out with error e:376警告
			早上,开发说昨晚一台服务器的undo好像有异常,早上上去一看,库停了,正常startup之后,随手crud了一把,都正常.去看alert.log日志,发现undo某个数据块访问报I/O读错误,如下: ... 
- openstack tap complete
			$ openstack complete > /etc/bash_completion.d/osc.bash_completion re-login and bash 
- 深入浅出MyBatis-快速入门
			http://blog.csdn.net/hupanfeng/article/details/9068003/ 
