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 ...
随机推荐
- 关于js闭包之小问题大错误
闭包是 JavaScript 开发的一个关键方面:匿名函数可以访问父级作用域的变量. 如果闭包的作用域中保存着一个 HTML 元素,则该元素无法被销毁.(下面代码来自高程) 刚看到一个关于闭包自己没注 ...
- JAVA连接数据库 #03# HikariCP
索引 为什么用数据库连接池? HikariCP快速入门 依赖 简单的草稿程序 设置连接池参数(只列举常用的) MySQL配置 修改Java连接数据库#02#中的代码 测试 为什么用数据库连接池? 为什 ...
- 利用Python实现多线程聊天功能
#-*- coding:utf-8 -*- from threading import Thread from socket import * #1.实现接收消息 def recvDate(): wh ...
- 详解Django中六个常用的自定义装饰器
装饰器作用 decorator是当今最流行的设计模式之一,很多使用它的人并不知道它是一种设计模式.这种模式有什么特别之处? 有兴趣可以看看Python Wiki上例子,使用它可以很方便地修改对象行为, ...
- Vue基础进阶 之 Vue生命周期与钩子函数
Vue生命周期 Vue生命周期:Vue实例从创建到销毁的过程,称为Vue的生命周期: Vue生命周期示意图:https://cn.vuejs.org/v2/guide/instance.html#生命 ...
- fjwc2019 D4T1 循环流
#187. 「2019冬令营提高组」循环流 假的网络流,其实是O(1)算法 手画n个图后,你会发现只要分成几种情况讨论讨论就得了. 当$a==1$时显然不存在. 当$a!=1$时 如果$n==2$,显 ...
- socket:10038错误
转自:http://blog.csdn.net/chen495810242/article/details/42029825 winSock的一个bug:当closesocket多次错误使用时会导致问 ...
- MySQL更改relay-bin名称导致同步停止的解决办法
今天在优化io的时候,移动了从库relay-bin的位置,并将hostname部分去掉了,启动后,从库slave状态如下: mysql> show slave status\G; ******* ...
- 论文阅读笔记 Improved Word Representation Learning with Sememes
论文阅读笔记 Improved Word Representation Learning with Sememes 一句话概括本文工作 使用词汇资源--知网--来提升词嵌入的表征能力,并提出了三种基于 ...
- 01: Python基本数据类型
目录: 1.1 列表和元组 1.2 字符串 1.3 字典 1.4 集合 1.1 列表和元组返回顶部 1.列表基本操作 1. 列表赋值 a = [1,2,3,4,5,6,7,8] a[0] = 100 ...