To show a list of unchanging data in React Native you can use the scroll view component. In this lesson, we'll map through the data we got back from the Github API, and fill complete ScrollView component for the user profile.

After call goToProfile function in Dashboard:

    goToProfile(){
this.props.navigator.push({
title: 'Profile',
component: Profile,
passProps: {userInfo: this.props.userInfo}
});
}

We create a new component 'Profile.js'

import React, {Component} from 'react';
import {View, StyleSheet, Text, ScrollView} from 'react-native'; import Badge from './Badge'; const styles = StyleSheet.create({
container: {
flex:
},
buttonText: {
fontSize: ,
color: 'white',
alignSelf: 'center'
},
rowContainer: {
padding:
},
rowTitle: {
color: '#48BBEC',
fontSize:
},
rowContent: {
fontSize:
}
}); class Profile extends React.Component{
getRowTitle(userInfo, item){
item = (item === 'public_repos') ? item.replace('_', ' ') : item;
return item[] ? item[].toUpperCase() + item.slice() : item;
}
createList(userInfo, topicArr){
return topicArr.map( (item, index) => {
if(!userInfo[item]){
return <View key={index}></View>
}else{
return (
<View style={styles.rowContainer}>
<Text style={styles.rowTitle}> {this.getRowTitle(userInfo, item)} </Text>
<Text style={styles.rowContent}> {userInfo[item]} </Text>
</View>
);
}
})
}
render(){
const userInfo = this.props.userInfo;
const topicArr = ['company', 'location', 'followers', 'following', 'email', 'bio', 'public_repos']; return (
<ScrollView style={styles.container} >
<Badge userInfo={this.props.userInfo} />
{this.createList(userInfo, topicArr)}
</ScrollView>
);
}
} module.exports = Profile;

												

[React Native] Create a component using ScrollView的更多相关文章

  1. React Native 中的component 的生命周期

    React Native中的component跟Android中的activity,fragment等一样,存在生命周期,下面先给出component的生命周期图 getDefaultProps ob ...

  2. [RN] React Native 中使用 stickyHeaderIndices 实现 ScrollView 的吸顶效果

    React Native中,ScrollView组件可以使用 stickyHeaderIndices 轻松实现 sticky 效果. 例如下面代码中: <ScrollView showsVert ...

  3. React Native 获取组件(Component)在屏幕上的位置

    年后主客户端的需求以及老的业务迁移RN,现在疯狂的在学RN.在迁移需求的时候遇到需要获取组件在屏幕上的绝对位置.页面如下: 就需要展开的时候获取sectionHeader(默认排序)在屏幕上的具体位置 ...

  4. React Native Expected a component class,got [object Object]解决

    报错原因: 组件大小写错误. 解决方式: 修改组件名称即可. 这篇博客介绍了大部分RN的错误原因和解决方法: http://blog.csdn.net/chichengjunma/article/de ...

  5. React Native 控制一个component的显示隐藏

      // 首先在constructor里:   this.state = { visible: false }   // 然后在点击事件设置:   this.setState({ visible: t ...

  6. [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 reus ...

  7. React Native 中 component 生命周期

    React Native 中 component 生命周期 转自 csdn 子墨博客  http://blog.csdn.net/ElinaVampire/article/details/518136 ...

  8. [转] React Native Navigator — Navigating Like A Pro in React Native

    There is a lot you can do with the React Native Navigator. Here, I will try to go over a few example ...

  9. React Native之 ScrollView介绍和使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

随机推荐

  1. Innodb引擎 long semaphore waits

    上一篇介绍了因为子表过多,导致innodb crash的情况,但crash的原因是long semaphore waits.long semaphore waits又为何物? 背景:Innodb使用了 ...

  2. Java [leetcode 13] Roman to Integer

    问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...

  3. Java [leetcode 30]Substring with Concatenation of All Words

    题目描述: You are given a string, s, and a list of words, words, that are all of the same length. Find a ...

  4. chmod命令

    chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...

  5. JMX学习笔记(三)-MXBean

    在MBean中有只要遵循以下两个规则,我们就可以在jconsole中动态的改变MBean中的属性值 1. JMX中要定义接口必须以xxxMBean的规范定义 2. 得有类实现xxxMBean接口 例如 ...

  6. How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu

    sudo apt-get update sudo apt-get install nginxsudo mkdir -p /var/www/example.com/html sudo chown -R ...

  7. iOS7程序后台运行

    介绍 这次 iOS7 对程序后台运行进行了加强,但是仅仅是加强而已,要想像 Android 程序那样自由当然就别想了,苹果这么做主要还是出于电池使用时间考虑,但是这次的加强对大部分程序基本够用. 在介 ...

  8. Java String StringBuffer StringBuilder

    String  字符串常量存储在常量区,每次追加操作会创建新的对象: StringBuffer  字符串变量  线程安全 在堆上创建,每次追加操作在原对象上进行操作:  速度 StringBuffer ...

  9. TCP 滑动窗口的简介

    TCP 滑动窗口的简介 POSTED BY ADMIN ON AUG 1, 2012 IN FLOWS34ARTICLES | 0 COMMENTS TCP的滑动窗口主要有两个作用,一是提供TCP的可 ...

  10. NOIP2012 同余方程

    1同余方程 题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开. 输出格式: 输出只有一行 ...