app.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React, { Component } from "react";
  2. import { View, Text, StyleSheet, Platform } from "react-native";
  3. import Header from "./header";
  4. import Footer from "./footer";
  5. const styles = StyleSheet.create({
  6. container: {
  7. flex: 1,
  8. backgroundColor: "#F5F5F5",
  9. ...Platform.select({
  10. ios: {
  11. paddingTop: 30
  12. }
  13. })
  14. },
  15. content: {
  16. flex: 1
  17. }
  18. });
  19. class App extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. value: "",
  24. items: []
  25. };
  26. this.handleAddItem = this.handleAddItem.bind(this);
  27. }
  28. handleAddItem() {
  29. if (!this.state.value) {
  30. return;
  31. }
  32. const newItems = [
  33. ...this.state.items,
  34. {
  35. key: Date.now(),
  36. text: this.state.value,
  37. complete: false
  38. }
  39. ];
  40. this.setState({
  41. items: newItems,
  42. value: ""
  43. });
  44. }
  45. render() {
  46. console.log(this.state);
  47. return (
  48. <View style={styles.container}>
  49. <Header
  50. onAddItem={this.handleAddItem}
  51. onChange={(value) => this.setState({ value })}
  52. value={this.state.value}
  53. />
  54. <View style={styles.content} />
  55. <Footer />
  56. </View>
  57. );
  58. }
  59. }
  60. export default App;