Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. import React, {Component} from 'react' import {AppRegistry,ScrollView,StyleSheet,Text,Alert,View,TouchableHighlight,TextInput,ListView} from 'react-native';
  2. import {Button,Grid,Col,Row } from 'react-native-elements'
  3. import { Actions }from 'react-native-router-flux';
  4. import { getDatabase } from './index.android.js';
  5.  
  6. let lestachesDataSource: new ListView.DataSource({rowHasChanged: (row1, row2)=>row1 !== row2});
  7.  
  8. let lestachesitems=[];
  9.  
  10.  
  11. export default class Layout1 extends Component {
  12. constructor(props)
  13. {
  14. super(props);
  15. //Constructeur
  16. this.lestachesitemsRef = getDatabase().ref('n0rhl66bifuq3rejl6118k8ppo/lestaches');
  17. this.state
  18. =
  19. {
  20. //Debutdustate
  21. lestachesSource: lestachesDataSource.cloneWithRows(lestachesitems)
  22. Prenom: '',
  23. Nom: '',
  24. }
  25. }
  26.  
  27. componentDidMount()
  28. {
  29. //DidMount
  30. this.lestachesitemsRef.on('child_added', (dataSnapshot)=>{ this.lestachesitems.push({id: dataSnapshot.key, text: dataSnapshot.val()}); this.setState({lestachesSource: this.state.lestachesSource.cloneWithRows(this.lestachesitems)}); });
  31. this.lestachesitemsRef.on('child_removed', (dataSnapshot)=>{ this.lestachesitems = this.lestachesitems.filter((x)=>x.id !== dataSnapshot.key); this.setState({ lestachesSource: this.state.lestachesSource.cloneWithRows(this.lestachesitems)});});
  32. }
  33.  
  34. //function
  35. ajouter = () => { if( (this.state.Nom !== '') && (this.state.Prenom !== '')) { this.lestachesitemsRef.push({ Nom: this.state.Nom , Prenom: this.state.Prenom , }); this.setState({ Nom : '' }) , this.setState({ Prenom : '' }) } }
  36. verl2 = () => Actions.Layout2();
  37. renderRowlestaches(rowData) { return ( <TouchableHighlight onPress={() => this.removelestaches(rowData)}><View ><Text >Nom : {rowData.text.Nom}</Text><Text >Prenom : {rowData.text.Prenom}</Text></View></TouchableHighlight> ); }
  38. removelestaches(rowData) { Alert.alert( ' Bravo ligne supprimée !'); this.lestachesitemsRef.child(rowData.id).remove(); }
  39.  
  40.  
  41. render(){
  42. //Vue
  43. return(
  44. <View
  45. style={{marginTop:
  46. 50,
  47. }}>
  48. <ScrollView>
  49. <TextInput style={styles.Dtext} placeholder="Nom" onChangeText={(text) => this.setState({Nom: text})} value={this.state.Nom}/>
  50. <TextInput style={styles.Dtext} placeholder="Prenom" onChangeText={(text) => this.setState({Prenom: text})} value={this.state.Prenom}/>
  51. <Button title='Allerlayout2' onPress={() => this.verl2()} onLongPress={() => this.infol2()} buttonStyle={ styles.View } icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.View }} />
  52. <Button title='ajouter' onPress={() => this.ajouter()} onLongPress={() => this.infoajout()} buttonStyle={ styles.View } icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.View }} />
  53. <ListView dataSource={this.state.lestachesSource} renderRow={this.renderRowlestaches.bind(this)} enableEmptySections={true} />
  54. </ScrollView>
  55. </View>
  56. );
  57. }
  58. }
  59.  
  60.  
  61. var styles = StyleSheet.create({
  62. //StyleSheet
  63. Dtext: { color: 'green' , fontFamily: 'h1', fontStyle: 'normal', fontWeight: 'normal', textAlign: 'auto', },
  64. View: { backgroundColor: 'red', borderBottomColor: 'red', flexWrap: 'wrap', },
  65. });
  66.  
  67.  
  68. AppRegistry.registerComponent( 'Layout1' ,()=> Layout1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement