Authored by 盖剑秋

Subject post page framework.

... ... @@ -20,7 +20,7 @@ import configureStore from './store/configureStore';
import homeInitialState from './reducers/home/homeInitialState';
import HomeContainer from './containers/HomeContainer';
import SubjectPostContainer from './containers/SubjectPostContainer'
import NavBar from './components/NavBar';
let VERSION = '0.0.1';
... ... @@ -112,7 +112,16 @@ export default function community(platform) {
return this.navPushStyle(props);
}}
/>
<Scene
key="SubjectPost"
title="主题帖"
hideNavBar={false}
component={SubjectPostContainer}
initial={false}
navBar={NavBar}
titleStyle={styles.navTitle}
type="push"
/>
</Scene>
</NewRouter>
</Provider>
... ...
... ... @@ -45,7 +45,7 @@ export default class Home extends React.Component {
return (
<View style={{flexDirection: 'row', justifyContent: 'center'}}>
<Text>这是社区首页</Text>
<Text onPress={this.props.testPress}>这是社区首页</Text>
</View>
);
... ...
import React, {Component} from 'react';
import {
View,
Text,
Image,
StyleSheet,
} from 'react-native'
export default class SPHeaderCell extends Component {
constructor(props) {
super(props);
}
renderName() {
if (this.props.data.owner) {
return(
<Text style={styles.nameLabel}>
{this.props.data.name + ' | '}
<Text style={styles.ownerColor}>楼主</Text>
</Text>
);
} else {
return(
<Text style={styles.nameLabel}>this.props.data.name</Text>
);
}
}
renderDelete() {
if (this.props.data.owner) {
return(
<Text style={[styles.nameLabel, styles.ownerColor, styles.deletePosition]}>
删除本帖
</Text>
);
}
}
render() {
return(
<View style={styles.container}>
<Image
style={styles.avatar}
source={{uri:this.props.data.avatar}}
/>
<Text style={styles.timeLabel}>{this.props.data.time}</Text>
{this.renderName()}
{this.renderDelete()}
<Text style={styles.fromLabel}>{this.props.data.templete}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
},
avatar: {
top: 15,
left: 15,
width: 30,
height: 30,
borderRadius: 15,
backgroundColor: 'grey',
},
//来自哪个模块
fromLabel: {
top:15,
right:15,
height: 20,
backgroundColor: '#aaaaaa',
fontSize: 15,
textAlign: 'center'
},
nameLabel: {
top: 15,
marginLeft: 15,
height: 20,
fontSize: 12,
color: 'black',
backgroundColor: 'red',
textAlign: 'left',
bottom: 10,
},
ownerColor: {
color: '#4a90e2',
},
deletePosition: {
left: 0,
top: 60,
},
timeLabel: {
top: 32,
height: 12,
left: 15,
fontSize: 10,
color: '#999999',
},
});
... ...
'use strict'
import React, {Component} from 'react';
import {
View,
Text,
ListView,
StyleSheet,
} from 'react-native'
import SPHeaderCell from './SPHeaderCell'
export default class SubjectPost extends Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged:(r1,r2)=> r1 != r2,
sectionHeaderHasChanged: (s1, s2) => s1 != s2,
});
this.renderRow = this.renderRow.bind(this);
}
renderRow(rowData, sectionId) {
console.log(sectionId);
switch (sectionId) {
case 'header':
return(
<SPHeaderCell data={rowData}/>
);
break;
default:
break;
}
}
render() {
const testDataBlob = {
"header": [
{
"name":"川本小一郎",
"avatar":"http://img0.imgtn.bdimg.com/it/u=441053097,4234222567&fm=21&gp=0.jpg",
"owner":true,
"templete":"永恒的潮流",
"time":"2小时前",
}
],
}
return(
<ListView
style={styles.container}
dataSource={this.dataSource.cloneWithRowsAndSections(testDataBlob)}
renderRow={this.renderRow}
enableEmptySections={true}
/>
);
}
}
const styles = StyleSheet.create({
container: {
top: 0,
flex: 1,
},
});
... ...
... ... @@ -13,6 +13,9 @@ import Home from '../components/Home';
import * as homeActions from '../reducers/home/homeActions';
import {Actions} from 'react-native-router-flux';
const {
StatusBar,
ScrollView,
... ... @@ -61,12 +64,16 @@ class HomeContainer extends React.Component {
constructor(props) {
super(props);
this.testPress = this.testPress.bind(this);
}
componentDidMount() {
}
testPress() {
Actions.SubjectPost();
}
render() {
... ... @@ -76,7 +83,7 @@ class HomeContainer extends React.Component {
hidden={false}
barStyle={'light-content'}
/>
<Home/>
<Home testPress={this.testPress}/>
</View>
);
}
... ...
'use strict';
import React, {Component} from 'react';
import {
View,
StyleSheet,
Dimensions,
Platform,
} from 'react-native';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import SubjectPost from '../components/SubjectPost/SubjectPost';
import * as subjectPostActions from '../reducers/subject/subjectPostActions';
/**
* ## Actions
* 3 of our actions will be available as ```actions```
*/
const actions = [
subjectPostActions,
];
/**
* Save that state
*/
function mapStateToProps(state) {
return {
...state
};
}
/**
* Bind all the functions from the ```actions``` and bind them with
* ```dispatch```
*/
function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return {
actions: bindActionCreators(creators, dispatch),
dispatch
};
}
class SubjectPostContainer extends Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.container}>
<SubjectPost/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
let styles = StyleSheet.create({
container: {
top: navbarHeight,
height: height - navbarHeight - 49,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(SubjectPostContainer);
... ...
/**
* # guideActions.js
*
* App user guide
*
*/
'use strict';
... ...