Created
July 4, 2019 01:16
-
-
Save lrlineroa/61dddfdfa3c7c806405edb7bffdd929b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { View, Text } from 'react-native'; | |
import { Card, CardItem, Button, Item, Label, Input } from 'native-base'; | |
class AddACard extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
cardValue: '', | |
cards: [] | |
} | |
} | |
//nuevo | |
static navigationOptions = ({ navigation }) => { | |
return { | |
title: 'Formulario' | |
} | |
}; | |
//nuevo | |
handleInputText(value) { | |
this.setState({ | |
cardValue: value | |
}) | |
} | |
//nuevo | |
handleSubmit() { | |
let cardsCopy=this.state.cards.slice() | |
let card={ | |
value:this.state.cardValue | |
} | |
cardsCopy.push(card) | |
this.setState({ | |
cardValue:'', | |
cards:cardsCopy | |
}) | |
} | |
//nuevo | |
render() { | |
console.log('cards : '+ JSON.stringify(this.state.cards))//<--para testear | |
return ( | |
<View style={{ padding: 10 }}> | |
<Card> | |
<CardItem header> | |
<Text> | |
Añade una tarjeta | |
</Text> | |
</CardItem> | |
<CardItem> | |
<Item floatingLabel> | |
<Label>Front</Label> | |
<Input | |
value={this.state.cardValue} | |
onChangeText={ | |
(text) => { | |
this.handleInputText(text) | |
} | |
} | |
/> | |
</Item> | |
</CardItem> | |
<CardItem footer> | |
<Button | |
onPress={() => this.handleSubmit()}//<------nuevo | |
block | |
light | |
> | |
<Text> | |
Añadir | |
</Text> | |
</Button> | |
</CardItem> | |
</Card> | |
</View> | |
); | |
} | |
} | |
export default AddACard; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment