React Native List列表
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
const Header=require('./header');
class FirstRN extends Component {
render() {
return (
<View style={styles.flex}>
<Header></Header>
<List title="一線城市樓市退燒 有房源一夜跌價160萬"></List>
<List title="上海市民稱墓地太貴買不起 買房存骨灰"></List>
<List title="朝鮮再發視訊:摧毀青瓦臺 一切化作灰機"></List>
<List title="生活大爆炸任務原型都好牛掰"></List>
<ImportantNews news={['一線城市樓市退燒 有房源一夜跌價160萬',
'上海市民稱墓地太貴買不起 買房存骨灰',
'上海市民稱墓地太貴買不起 買房存骨灰',
'上海市民稱墓地太貴買不起 買房存骨灰上海市民稱墓地太貴買不起 買房存骨灰上海市民稱墓地太貴買不起 買房存骨灰上海市民稱墓地太貴買不起 買房存骨灰',
'上海市民稱墓地太貴買不起 買房存骨灰上海市民稱墓地太貴買不起 買房存骨灰上海市民稱墓地太貴買不起 買房存骨灰',
'上海市民稱墓地太貴買不起 買房存骨灰'
]}>
</ImportantNews>
</View>
);
}
}
class List extends Component {
render() {
return (
<View style={styles.list_item}>
<Text style={styles.list_item_font}>{this.props.title}</Text>
</View>
//{this.props.title} 屬性的傳遞
);
}
}
class ImportantNews extends Component {
//方法
show(title) {
alert(title);
}
render() {//渲染的方法
var news = [];//定義陣列
for(var i in this.props.news) {//迴圈
var text = (
<Text onPress={this.show.bind(this, this.props.news[i])}
numberOfLines={2}
style={styles.news_item}
key={i}>
{this.props.news[i]}
</Text>
);
news.push(text);//新增到news陣列中
}
return(
<View style={styles.flex}>
<Text style={styles.news_title}>今日要聞</Text>
{news}
</View>
);
}
}
const styles = StyleSheet.create({
flex: {
flex: 1,
},
list_item: {
height: 40, //高度
marginLeft: 10, //左邊距
marginRight:10, //右邊距
borderBottomWidth: 1, //底部邊框
borderBottomColor: '#ddd', //底部邊框顏色
justifyContent: 'center', //justify-content 用於設定或檢索彈性盒子元素在主軸(橫軸)方向上的對齊方式。
},
list_item_font: {
fontSize: 16, //字型大小
},
news_title: {
fontSize: 20,
fontWeight: 'bold',
color: '#CD1D1C',
marginRight: 10,
marginLeft: 10,
marginTop: 10,
},
news_item: {
marginLeft: 10,
marginRight: 10,
fontSize: 15,
lineHeight: 40,//line-height 屬性設定行間的距離(行高)。註釋:不允許使用負值。
borderBottomWidth: 1, //底部邊框
borderBottomColor: '#ddd', //底部邊框顏色
},
});
AppRegistry.registerComponent('FirstRN', () => FirstRN);
相關文章
- react-native分組列表SectionListReact
- React Native——使用SectionList改造電影列表React Native
- [React Native]react-native-scrollabReact Native
- Python List 列表list()方法Python
- React Native列表檢視FlatList使用優化實踐指南React Native優化
- Python List 列表list()方法分享Python
- Python 列表(List)Python
- python列表(List)Python
- SCSS list 列表CSS
- Python list(列表)Python
- React Native Icon方案:react-native-svgReact NativeSVG
- React List - React RouterReact
- React Native轉web方案:react-native-webReact NativeWeb
- React Native 使用 react-native-webview 渲染 HTMLReact NativeWebViewHTML
- react-native配置react-native-image-crop-pickerReact
- React Native選擇器元件-react-native-slidepickerReact Native元件IDE
- react-nativeReact
- React Native 上手React Native
- 《React Native高效開發》之create-react-native-appReact NativeAPP
- React Native / React除錯技巧React Native除錯
- react native 包學不包會系列--認識react nativeReact Native
- React Native 熱更新React Native
- 詳解 React NativeReact Native
- Redux for react native 指南ReduxReact Native
- React-Native ‘WKWebView` has no propType for native propReactWebView
- react/react-native效能優化React優化
- [譯] Airbnb 在 React Native 上下的賭注(四):React Native 退役AIReact Native
- react 列表&keysReact
- Python List 列表的處理Python
- Python - list 列表常見方法Python
- React Native基礎&入門教程:以一個To Do List小例子,看props和stateReact Native
- React Native --踩坑記 之 建立指定 React Native版本的專案React Native
- React-列表元件(通知列表、私信列表、虛擬列表)React元件
- React Native 的未來與React HooksReact NativeHook
- React Native 環境搭建React Native
- React Native 整合code pushReact Native
- React-Native爬坑React
- React-Native實踐React
- [譯] 圖解 React Native圖解React Native