Skip to content

Commit

Permalink
init master
Browse files Browse the repository at this point in the history
  • Loading branch information
horizon0514 authored and horizon0514 committed Dec 9, 2015
1 parent 39307de commit ba0186f
Show file tree
Hide file tree
Showing 38 changed files with 2,335 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions DataWarehouse.js
Original file line number Diff line number Diff line change
@@ -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;
191 changes: 191 additions & 0 deletions MainScreen.js
Original file line number Diff line number Diff line change
@@ -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 (
// <TouchableHighlight underlayColor='#dddddd'>
// <View>
// <View style={styles.rowContainer}>
// <Image style={styles.thumb} source={require('./img/splash.png')}/>
// <View style={styles.textContainer}>
// <Text style={styles.title}>{rowData.title}</Text>
// <Text style={styles.desc}></Text>
// </View>
// </View>
// <View style={styles.separator}/>

// </View>
// </TouchableHighlight>

// );
// }

// render() {
// console.log('render listview');
// return (
// <View style={styles.container}>
// <ListView
// dataSource={this.state.dataSource}
// renderRow={this.renderRow.bind(this)}/>
// </View>
// );
// }
// };
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 (
<TouchableHighlight underlayColor='#dddddd'>
<View>
<View style={styles.rowContainer}>
<Image style={styles.thumb} source={{uri: rowData.images[0]}}/>
<View style={styles.textContainer}>
<Text style={styles.title}>{rowData.title}</Text>
<Text style={styles.desc}></Text>
</View>
</View>
<View style={styles.separator}/>

</View>
</TouchableHighlight>

);
}

render() {
var spinner = <ActivityIndicatorIOS style={styles.centering} hidden='false' size='large'/>;

if(this.state.isLoading){
return(
<View style={styles.container}>spinner</View>
);
} else {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}/>
</View>
);
}
}

}

var styles = StyleSheet.create({
container: {
flex: 1
},
rowContainer: {
flexDirection: 'row',
padding: 10
},
thumb:{
width: 80,
height: 80,
marginRight: 10

},
title: {
fontSize: 18,
color: 'black',
fontWeight: 'bold'
},
textContainer: {
flex: 1
},
separator: {
height: 1,
backgroundColor: '#dddddd'
},
desc:{
fontSize:14,
color: '#666666'
},
centering: {
position: 'absolute',
left: 100,
top: 200
},
});

module.exports = MainScreen;
78 changes: 78 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apply plugin: "com.android.application"

/**
* The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets.
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"]
* ]
*/

apply from: "react.gradle"

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.rnzhihudaily"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled false // Set this to true to enable Proguard
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.16.+"
}
Loading

0 comments on commit ba0186f

Please sign in to comment.