diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..8eadd33 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,63 @@ +[ignore] + +# We fork some components by platform. +.*/*.web.js +.*/*.android.js + +# Some modules have their own node_modules with overlap +.*/node_modules/node-haste/.* + +# Ugh +.*/node_modules/babel.* +.*/node_modules/babylon.* +.*/node_modules/invariant.* + +# Ignore react and fbjs where there are overlaps, but don't ignore +# anything that react-native relies on +.*/node_modules/fbjs-haste/.*/__tests__/.* +.*/node_modules/fbjs-haste/__forks__/Map.js +.*/node_modules/fbjs-haste/__forks__/Promise.js +.*/node_modules/fbjs-haste/__forks__/fetch.js +.*/node_modules/fbjs-haste/core/ExecutionEnvironment.js +.*/node_modules/fbjs-haste/core/isEmpty.js +.*/node_modules/fbjs-haste/crypto/crc32.js +.*/node_modules/fbjs-haste/stubs/ErrorUtils.js +.*/node_modules/react-haste/React.js +.*/node_modules/react-haste/renderers/dom/ReactDOM.js +.*/node_modules/react-haste/renderers/shared/event/eventPlugins/ResponderEventPlugin.js + +# Ignore commoner tests +.*/node_modules/commoner/test/.* + +# See https://github.com/facebook/flow/issues/442 +.*/react-tools/node_modules/commoner/lib/reader.js + +# Ignore jest +.*/node_modules/jest-cli/.* + +# Ignore Website +.*/website/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js + +[options] +module.system=haste + +munge_underscores=true + +module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub' +module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub' + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FixMe + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-8]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-8]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy + +[version] +0.18.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94fc867 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IJ +# +.idea +.gradle +local.properties + +# node.js +# +node_modules/ +npm-debug.log diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/DataWarehouse.js b/DataWarehouse.js new file mode 100644 index 0000000..c01aa66 --- /dev/null +++ b/DataWarehouse.js @@ -0,0 +1,9 @@ +'use strict'; +var API_COVER_URL = 'http://news-at.zhihu.com/api/4/start-image/1080*1776'; +var API_NEWS_URL = 'http://news-at.zhihu.com/api/4/news/latest'; +const DataWarehouse = { + cover: API_COVER_URL, + news: API_NEWS_URL +} + +module.exports = DataWarehouse; \ No newline at end of file diff --git a/MainScreen.js b/MainScreen.js new file mode 100644 index 0000000..3af88e9 --- /dev/null +++ b/MainScreen.js @@ -0,0 +1,191 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + */ +'use strict'; + +var React = require('react-native'); +var DataWarehouse = require('./DataWarehouse'); + +var { + StyleSheet, + ListView, + TouchableHighlight, + Text, + View, + Image, + Component, + ActivityIndicatorIOS, +} = React; + +let requestUrl = DataWarehouse.news; + + +// class MainScreen extends React.Component{ +// constructor(){//ES6 风格 +// super(); +// this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); +// return { +// dataSource: this.ds.cloneWithRows([]), +// }; +// } +// componentDidMount(){ +// //this._fetchData(); +// this.setState({dataSource:this.ds.cloneWithRows(["Row 1", "Row 2", "Row 3", "Row 4"])}); + +// } + +// _fetchData(){ +// fetch(requestUrl) +// .then(response => response.json()) +// .then(response => { +// console.log(response); +// this.setState({ +// dataSource: this.ds.cloneWithRows(response.stories) +// }); + +// } +// );//setState之后会自动调用render函数 +// } +// renderRow(rowData, sectionID, rowID) { +// console.log(rowData); +// return ( +// +// +// +// +// +// {rowData.title} +// +// +// +// + +// +// + +// ); +// } + +// render() { +// console.log('render listview'); +// return ( +// +// +// +// ); +// } +// }; +class MainScreen extends Component { + + constructor(props) { + super(props); + this.state = { + isLoading : true + } + + this.ds = new ListView.DataSource( + {rowHasChanged: (r1, r2) => r1.id !== r2.id}); + this.state = { + dataSource: this.ds.cloneWithRows([{images:[]}]) + }; + } + componentDidMount(){ + this._fetchData(); + + } + + _fetchData(){ + fetch(requestUrl) + .then(response => response.json()) + .then(response => { + console.log(response); + this.setState({ + dataSource: this.ds.cloneWithRows(response.stories), + isLoading: false + }); + + } + );//setState之后会自动调用render函数 + } + + renderRow(rowData, sectionID, rowID) { + console.log(rowData); + return ( + + + + + + {rowData.title} + + + + + + + + + ); + } + + render() { + var spinner =