[React Native] Using the Image component and reusable styles
Let's take a look at the basics of using React Native's Image component, as well as adding some reusable styling to our Dashboard component buttons.
We are going to build Dashboard Component, it will looks like this:

Basicly have one image component and three TouchableHighlight components.
import React, { Component } from 'react';
import {Text, View, StyleSheet, Image, TouchableHighlight} from 'react-native';
var styles = StyleSheet.create({
container: {
marginTop: ,
flex:
},
image: {
height: ,
},
buttonText: {
fontSize: ,
color: 'white',
alignSelf: 'center'
}
});
class Dashboard extends React.Component{
makeBackground(btn){
var obj = {
flexDirection: 'row',
alignSelf: 'stretch',
justifyContent: 'center',
flex:
}
if(btn === ){
obj.backgroundColor = '#48BBEC';
} else if (btn === ){
obj.backgroundColor = '#E77AAE';
} else {
obj.backgroundColor = '#758BF4';
}
return obj;
}
goToProfile(){
console.log('Going to Profile Page');
}
goToRepos(){
console.log('Going to Repos');
}
goToNotes(){
console.log('Going to Notes');
}
render(){
return (
<View style={styles.container}>
<Image source={{uri: this.props.userInfo.avatar_url}} style={styles.image}/>
<TouchableHighlight
style={this.makeBackground()}
onPress={this.goToProfile.bind(this)}
underlayColor="#88D4F5">
<Text style={styles.buttonText}>View Profile</Text>
</TouchableHighlight>
<TouchableHighlight
style={this.makeBackground()}
onPress={this.goToRepos.bind(this)}
underlayColor="#E39EBF">
<Text style={styles.buttonText}>View Repositories</Text>
</TouchableHighlight>
<TouchableHighlight
style={this.makeBackground()}
onPress={this.goToNotes.bind(this)}
underlayColor="#9BAAF3">
<Text style={styles.buttonText}>Take Notes</Text>
</TouchableHighlight>
</View>
)
}
};
module.exports = Dashboard;
The data 'this.props.userInfo' was passed from 'navigator' in main.js:
handleSubmit(event){
//update our indicatorIOS spinner
this.setState({
isLoading: true
});
//fetch data from github
api.getBio(this.state.username)
.then( (res) => {
if(res.message === "Not Found"){
this.setState({
error: 'User not found',
isLoading: false
})
}else{
//Pass in a new router component
this.props.navigator.push({
title: res.name || 'Selet an Option',
component: Dashboard,
passProps: {userInfo: res}
});
//Clean the search input and loading
this.setState({
isLoading: false,
error: false,
username: ''
});
}
})
}
[React Native] Using the Image component and reusable styles的更多相关文章
- [React Native] Using the WebView component
We can access web pages in our React Native application using the WebView component. We will connect ...
- React Native(六)——PureComponent VS Component
先看两段代码: export class ywg extends PureComponent { …… render() { return ( …… ); } } export class ywg e ...
- [React Native] Use the SafeAreaView Component in React Native for iPhone X Compatibility
In this lesson, you will learn how to use the SafeAreaView component to avoid the sensor cluster (th ...
- [react native] react-native-tab-navigator在子Component中隐藏
因为文档只列出了TabBarIOS, 不支持Android,所以github上找到这个组件. 先说下我的页面构造: 入口文件 —> 注册组件(包含Navigator, 跳转到欢迎页)—> ...
- React Native 系列(二) -- React入门知识
前言 本系列是基于React Native版本号0.44.3写的,最初学习React Native的时候,完全没有接触过React和JS,本文的目的是为了给那些JS和React小白提供一个快速入门,让 ...
- React Native移植原生Android
(一)前言 之前已经写过了有关React Native移植原生Android项目的文章,不过因为RN版本更新的原因吧,跟着以前的文章可能会出现一些问题,对于初学者来讲还是会有很多疑难的困惑的,而且官方 ...
- React Native开发 - 搭建React Native开发环境
移动开发以前一般都是原生的语言来开发,Android开发是用Java语言,IOS的开发是Object-C或者Swift.那么对于开发一个App,至少需要两套代码.两个团队.对于公司来说,成本还是有的. ...
- React Native 系列(二)
前言 本系列是基于React Native版本号0.44.3写的,最初学习React Native的时候,完全没有接触过React和JS,本文的目的是为了给那些JS和React小白提供一个快速入门,让 ...
- React Native入门 开发第一个React Native应用
1. 首先创建一个目录(比如ReactNativeDir),用于存放各个ReactNative工程的代码 2.使用React Native命令工具来创建(初始化)一个ReactNative项目(tes ...
随机推荐
- 记一次SSH登陆失败问题的定位
创建用户之后,使用ssh协议登陆提示失败. useradd -d /home/hdp -m hdp -g dba -s /bin/bash 通过命令 ssh -v hdp@127.0.0.1 登陆,查 ...
- 使用LINQ 對List分頁/區
listview之類的服務器控件分頁自不用多說,拖拖控件改改屬性分分鐘的事.就不浪費大家時間了. 這裏只寫大概思路及關鍵代碼了. LINQ裏有一個對集合進行分區的操作可用於分頁. page ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- MySQL索引的查看创建和删除
1.索引作用 在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万倍. 例如,有 ...
- UPC 2224 Boring Counting ★(山东省第四届ACM程序设计竞赛 tag:线段树)
[题意]给定一个长度为N的数列,M个询问区间[L,R]内大于等于A小于等于B的数的个数. [题目链接]http://acm.upc.edu.cn/problem.php?id=2224 省赛的时候脑抽 ...
- HDU 4389 X mod f(x)
题意:求[A,B]内有多少个数,满足x % f(x) == 0. 解法:数位DP.转化为ans = solve(b) - solve(a - 1).设dp[i][sum][mod][r]表示长度为i, ...
- [娱乐]GameMaker绘制参数方程的图像
今天,我翻了旧物,硬着头皮看了这源码.突然恍然大悟,这岂不就是当年学的参数方程! 目前,最早开始教授参数方程实在高三时,并作为一门选修课程,简化了求解圆锥曲线方程的难度,在高考中也很容易拿分,考试过后 ...
- 设计模式_Decorator_装饰模式
形象例子: Mary过完轮到Sarly过生日,还是不要叫她自己挑了,不然这个月伙食费肯定玩完,拿出我去年在华山顶上照的照片,在背面写上“最好的的礼物,就是爱你的Fita”,再到街上礼品店买了个像框(卖 ...
- 【原】Storm及特点
Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...
- vim讲解
文本编辑vi使用 最好使用vim,采用sudo apt-get install vim vi是Linux及类Unix系统中主流的命令行文本编辑器,功能极为强大,vim是增强版本的vim.Vim的高级地 ...