Permalink
Browse files

Refactor a bit to share models between Android and iOS

  • Loading branch information...
lmorchard committed Sep 17, 2015
1 parent fd80e98 commit dd8b6b307c31b67fde23c6b090e7b1f1d8b0f579
View

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
File renamed without changes.
View
@@ -11,23 +11,23 @@ var App = module.exports = React.createClass({
mixins: [Views.AppCommonMixin],
appStateClass: require('../../models/ios/App'),
appStateClass: require('../../models/native/App'),
render() {
var listModeButtons = Views.LIST_MODES.map((item) => {
var textStyle = (this.state.app.mode == item.mode) ?
styles.todoListFilterButtonTextSelected :
styles.todoListFilterButtonText;
styles.todoListModeButtonTextSelected :
styles.todoListModeButtonText;
return (
<TouchableHighlight
activeOpacity={1}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
onPress={()=>this.setListMode(item.mode)}>
<View style={styles.todoListFiltersButton}>
<View style={styles.todoListModeButton}>
<Text style={textStyle}>{item.label.replace('%s', this.state.app[item.state])}</Text>
</View>
</TouchableHighlight>
@@ -42,27 +42,12 @@ var App = module.exports = React.createClass({
ref="newField"
placeholder="tap to add a new todo"
onSubmitEditing={this.handleNewTodoSubmit} />
<View style={styles.todoListFilters}>
<View style={styles.todoListMode}>
{listModeButtons}
</View>
<TodoList collection={this.state.app.todos.subset} />
</View>
);
},
handleListModeChange(event) {
var index = event.nativeEvent.selectedSegmentIndex;
var selectedMode = Views.LIST_MODES[index];
this.setListMode(selectedMode ? selectedMode.mode : 'all');
},
handleNewTodoSubmit(event) {
var val = event.nativeEvent.text.trim();
this.refs.newField.setNativeProps({text: ''});
this.state.app.todos.add({
title: val,
completed: false
});
}
});
@@ -12,28 +12,28 @@ module.exports = React.StyleSheet.create({
textAlign: 'center',
margin: 10,
},
todoListFilters: {
todoList: {
// padding: 10
},
todoListMode: {
marginTop: 10,
marginBottom: 10,
height: 40,
flexDirection: 'row',
flexWrap: 'nowrap',
justifyContent: 'flex-start',
alignItems: 'center'
},
todoListFiltersButton: {
todoListModeButton: {
borderWidth: 1,
borderColor: '#000',
padding: 10,
height: 40
},
todoListFilterButtonTextSelected: {
fontWeight: 'bold'
},
todoList: {
// padding: 10
todoListModeButtonText: {
},
todoListMode: {
marginTop: 10,
marginBottom: 10
todoListModeButtonTextSelected: {
fontWeight: 'bold'
},
todoItem: {
height: 40,
View
@@ -23,6 +23,14 @@ exports.AppCommonMixin = {
},
componentWillUnmount() {
this.state.app.off(null, null, this);
},
handleNewTodoSubmit(event) {
var val = event.nativeEvent.text.trim();
this.refs.newField.setNativeProps({text: ''});
this.state.app.todos.add({
title: val,
completed: false
});
}
};
View
@@ -11,7 +11,7 @@ var App = module.exports = React.createClass({
mixins: [Views.AppCommonMixin],
appStateClass: require('../../models/ios/App'),
appStateClass: require('../../models/native/App'),
render() {
@@ -39,15 +39,6 @@ var App = module.exports = React.createClass({
var index = event.nativeEvent.selectedSegmentIndex;
var selectedMode = Views.LIST_MODES[index];
this.setListMode(selectedMode ? selectedMode.mode : 'all');
},
handleNewTodoSubmit(event) {
var val = event.nativeEvent.text.trim();
this.refs.newField.setNativeProps({text: ''});
this.state.app.todos.add({
title: val,
completed: false
});
}
});

0 comments on commit dd8b6b3

Please sign in to comment.