From 02f71f480bcad1d4483b44a73efac18f0ef81f12 Mon Sep 17 00:00:00 2001 From: wushenghua Date: Tue, 23 Feb 2016 17:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Class/View/CollectListView.js | 2 +- Class/View/HomeListView.js | 145 ++++++++++++++++++++++++++++++++++ Class/View/Info.js | 2 +- Class/View/RandListView.js | 2 +- 4 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 Class/View/HomeListView.js diff --git a/Class/View/CollectListView.js b/Class/View/CollectListView.js index b5c880c..a8ef73f 100644 --- a/Class/View/CollectListView.js +++ b/Class/View/CollectListView.js @@ -1,4 +1,4 @@ -//3个主界面的listview +//收藏页面 'use strict'; import React, { diff --git a/Class/View/HomeListView.js b/Class/View/HomeListView.js new file mode 100644 index 0000000..1c5c843 --- /dev/null +++ b/Class/View/HomeListView.js @@ -0,0 +1,145 @@ +//主页 +'use strict'; +import React, { + AppRegistry, + Component, + StyleSheet, + ListView, + Text, + View, + Image, + TouchableOpacity, + AlertIOS, + RefreshControl, + ActivityIndicatorIOS +} from 'react-native'; + + +import MyListView from './MyListView' +var isPromise = require('is-promise') +var REQUEST_URL = 'http://127.0.0.1:3000/users/list'; + +export default class RandListView extends Component{ + + //初始化。 + constructor(props) { + super(props); + this.state = { + dataSource: new ListView.DataSource({ + rowHasChanged: (row1, row2) => row1 !== row2, + }), + }; + } + + componentDidMount(){ + this.props.navComponent.setNavItems({ + title: { + component: ( + + 随机 + + ) + } + }) + } + + onRefresh(){ + this.myfetchData(); + } +//数据查询. + fetchData(){ + var page = Math.random() * 1000; + page = Math.floor(page); + var url = REQUEST_URL + '?page=' + page; + return new Promise((resolve, reject)=>{ + fetch(url) + .then((response) => response.json()) + .catch((error) => { + reject(error); + }) + .then((responseData) => { + if(responseData){ + this.setState({ + dataSource: this.state.dataSource.cloneWithRows(responseData.datas), + }); + resolve(responseData.datas); + }else{ + reject('none'); + } + + }) + .done(); + }) + + } + + render(){ + return ( + + ); + } + +} + +const styles = StyleSheet.create({ + container: { + flex:2, + flexDirection: 'column', + justifyContent: 'center', + alignItems: 'center', + backgroundColor: 'White', + }, + welcome: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, + instructions: { + textAlign: 'center', + color: '#333333', + marginBottom: 5, + }, + title: { + fontSize: 15, + marginBottom: 8, + marginTop: 10, + marginLeft: 4, + marginRight: 4, + textAlign: 'left', + }, + year: { + textAlign: 'center', + }, + rightContainer: { + flex: 1, + }, + topContainer:{ + flex:1, + height : 30, + backgroundColor: 'LightGray', + }, + thumbnail: { + width: 400, + height: 200, + }, + listView: { + paddingTop: 0, + marginBottom: 44, + backgroundColor: 'LightGray', + }, + navItem: { + flex: 1, + justifyContent: 'center', + alignItems: 'center' + }, + // top{ + // height:60, + // flex: 1, + // }, +}); + +module.exports = RandListView; \ No newline at end of file diff --git a/Class/View/Info.js b/Class/View/Info.js index 25ef7f8..b669269 100644 --- a/Class/View/Info.js +++ b/Class/View/Info.js @@ -1,4 +1,4 @@ - +//详情页面 'use strict'; import React, { AppRegistry, diff --git a/Class/View/RandListView.js b/Class/View/RandListView.js index 7c40325..882626e 100644 --- a/Class/View/RandListView.js +++ b/Class/View/RandListView.js @@ -1,4 +1,4 @@ -//3个主界面的listview +//随机页面 'use strict'; import React, {