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 ...
随机推荐
- 4、CentOS6.5下安装php5.3
操作系统:CentOS6.5 环境:Apache2.2安装成功.可查看:http://www.centoscn.com/image-text/install/2014/0505/2910.html M ...
- [转载]web安全之token
参考:http://blog.csdn.net/sum_rain/article/details/37085771 Token,就是令牌,最大的特点就是随机性,不可预测.一般黑客或软件无法猜测出来. ...
- jquery easyui datagrid 空白条处理 自适应宽高 格式化函数formmater 初始化时会报错 cannot read property 'width'||'length' of null|undefined
1---表格定义好之后右侧可能会有一个空白条 这个空白条是留给滚动条的,当表格中的一页的数据在页面中不能全显示时会自动出现滚动条,网上有很多事要改源码才可以修改这个,但是当项目中多处用到时,有的需要滚 ...
- 从零开始部署一个 Laravel 站点
从零开始部署一个 Laravel 站点 此文章为原创文章,未经同意,禁止转载. PHP Laravel Web Git 在阿里云买ECS的时候选择自己习惯的镜像系统,我一般都是使用Linux Ubun ...
- Django基础(10): URL重定向的HttpResponseDirect, redirect和reverse的用法详解
利用django开发web应用, 我们经常需要进行URL重定向,有时候还需要给URL传递额外的参数.比如用户添加文章完成后需要转到文章列表或某篇文章详情.因此熟练掌握HttpResponseDirec ...
- socket编程-阻塞和非阻塞
转自:https://www.cnblogs.com/sunziying/p/6501045.html 建立连接 阻塞方式下,connect首先发送SYN请求道服务器,当客户端收到服务器返回的SYN的 ...
- 09:vuex组件间通信
1.1 vuex简介 官网:https://vuex.vuejs.org/zh/guide/ 参考博客:https://www.cnblogs.com/first-time/p/6815036.htm ...
- VR AR MR
VR.AR和MR的区别? VR就是创造一个完全取代现实的世界,让人感觉「我怎么在这里?」 AR则是在现实世界的图像中叠加一些东西,让人感觉「哎?这里多了个本来不存在的东西」 MR则是虚拟物体完全和现实 ...
- 安装kali linux 2017.1 【一、更新源 升级软件和内核等】
呃,我这次安装是在VMware WorkStation里进行的,具体操作系统安装步骤不谈. ISO文件下载地址:https://www.kali.org/downloads/ 说下安装后的升级操作.下 ...
- Eclipse中手动清理项目缓存,
用过Eclipse或MyEclipse的小伙伴肯定遇到过这种情况: 代码出错后,在前台访问出问题.然后把代码改好,已经检查不到错误,可是项目在前台访问还是有问题. 这个时候,可能就是Eclipse/M ...