- 内容简介
- 译者序
- 前言
- 第 1 章 安装配置新项目
- 第 2 章 Flexbox 布局介绍
- 第 3 章 用 React Native 开发一个应用
- 第 4 章 在 React Native 中使用导航
- 第 5 章 动画和滑动菜单
- 第 6 章 用 React Native 绘制 Canvas
- 第 7 章 使用 React Native 播放音频
- 第 8 章 你的第一个自定义视图
- 第 9 章 Flux 介绍
- 第 10 章 处理复杂的应用程序状态
- 第 11 章 使用 Node 来实现服务端 API
- 第 12 章 在 React Native 中使用文件上传
- 第 13 章 理解 JavaScript Promise
- 第 14 章 fetch 简介
- 第 15 章 在 iOS 中使用 SQLite
- 第 16 章 集成 Google Admob
- 第 17 章 React Native 组件国际化
- 附录 A React.js 快速介绍
- 附录 B Objective-C Primer
- 附录 C webpack 入门
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
使用 Canvas 组件
使用 Canvas 组件需要使用相对路径引入 Canvas 模块,将 renderCanvas 方法及上下文对象传给 Canvas 组件。
index.ios.js
'use strict';
var React = require('react-native');
var {
Text,
View
} = React;
var Canvas = require('./Canvas');
var styles = React.StyleSheet.create({
container: {
padding: 30,
marginTop: 65,
borderColor: '#e7e7e7',
},
});
function renderCanvas(canvas) {
// Canvas demo 来自:
http://codepen.io/antoniskamamis/pen/ECrKd
var message = this.msg;
var ctx = canvas.getContext('2d'),
particles = [],
patriclesNum = 50,
w = 200,
h = 200,
colors = ['#f35d4f', '#f36849', '#c0d988', '#6ddaf1', '#f1e85b
'];
canvas.width = 200;
canvas.height = 200;
canvas.style.left = (window.innerWidth - 200) / 2 + 'px';
if (window.innerHeight > 200)
canvas.style.top = (window.innerHeight - 200) / 2 + 'px';
function draw() {
ctx.font = "20px Georgia";
ctx.fillText(message, 10, 50);
}
draw();
}
class SimpleApp extends React.Component {
render() {
var context = {msg: "Hello! "};
return (
<View style={styles.container}>
<View>
<Canvas context={context}
render={renderCanvas}
style={{height: 200, width: 200}} />
</View>
</View>
)
}
}
React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
现在你应该理解 WebView 组件了,在你的项目中使用吧。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论