20170819

作者: 入秋未凉的海 | 来源:发表于2017-08-20 00:15 被阅读0次
import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View
} from 'react-native';

var Son = React.createClass({
    getDefaultProps() {
        console.log('child','getDefaultProps');
    },
    getInitialState(){
        console.log('getInitialState');
        return {
            times: this.props.times
        }
    },
    timePlus() {
        let times = this.state.times

        times++;
        this.setState({
            times: times
        })
    },

    componentWillMount() {
        console.log('child','componentWillMount');
    },
    componentDidMount() {
        console.log('child','componentDidMount');
    },
    componentWillReceiveProps(props) {
        console.log('child','componentWillReceiveProps');
        this.setState({
          times: props.times
        })
    },
    shouldComponentUpdate() {
        console.log('child','shouldComponentUpdate');
        return true;
    },
    componentWillUpdate() {
        console.log('child','componentWillUpdate');
    },
    componentDidUpdate() {
        console.log('child','componentDidUpdate');
    },

    timesReset() {
      this.props.timesReset();
    },

    render() {
        console.log('child','render');
        return (
            <View style={styles.container}>
              <Text style={styles.welcome} onPress={this.timePlus}>
                儿子:有本事揍我啊!
              </Text>
              <Text style={styles.instructions}>
                  你居然揍我{this.state.times}次
              </Text>
              <Text style={styles.instructions} onPress={this.timesReset}>
                信不信我亲亲你
              </Text>

            </View>
        );
    }
})

var MyApp = React.createClass({
  getDefaultProps() {
    console.log('father','getDefaultProps');
  },
  getInitialState(){
    console.log('father','getInitialState');
    return {
      hit: false,
      times: 2
    }
  },


  componentWillMount() {
    console.log('father','componentWillMount');
  },
  componentDidMount() {
      console.log('father','componentDidMount');
  },
  shouldComponentUpdate() {
      console.log('father','shouldComponentUpdate');
      return true;
  },
  componentWillUpdate() {
      console.log('father','componentWillUpdate');
  },
  componentDidUpdate() {
      console.log('father','componentDidUpdate');
  },
  timesReset(){
    this.setState({
      time: 0
    })
  },
  willHit(){
    this.setState({
      hit: !this.state.hit
    })
  },
  timePlus() {
      var times = this.state.times

      times += 3;
      this.setState({
          times: times
      })
  },

  render() {
    console.log('father','render');
    return (
      <View style={styles.container}>
        {
          this.state.hit
          ? <Son times={this.state.times} timesReset={this.timesReset}/>
          : null
        }
        <Text style={styles.welcome} onPress={this.timesReset}>
          老子说:心情好就放你一马
        </Text>
        <Text style={styles.instructions} onPress={this.willHit}>
            到底揍不揍
        </Text>
        <Text style={styles.instructions}>
            就揍了你{this.state.times}次而已
        </Text>
        <Text style={styles.instructions} onPress={this.timePlus}>
            不听话,再揍你3次
        </Text>
      </View>
    );
  }
})


var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('MyApp', () => MyApp);
getInitialState(){
    console.log('father','getInitialState');
    return {
      hit: true,
      times: 2
    }
  },
触发timePlus

相关文章

  • 八月的躁动

    20170819愿你我老去之后, 有个嘴角上扬的青春20170819.jpg 20170825选择了自由,就得忍受...

  • 运动使我健康 | 第二周减脂记录

    第二周 20170819-20170825没有及时把记录发出来,但是绝对也没有偷懒哈。 20170819 周六 H...

  • 20170819

    生活就像巧克力,你永远不知道下一刻味道怎么样,…所以,大胆往前吧! 早安?

  • 20170819

    今天一早分享了一位老乡,又是老婆怀孕的,昨天说来办公室找我,我没在,早上分享了一下,希望接下来能成为会员!越来越简...

  • 20170819

    此时此刻我做在书桌前,昏黄的灯光,舒缓的音乐,内心平静淡然。想象着自己想要的生活: 工作:是我稳定生活的最重要前提...

  • 20170819

    1.容易生气的小河豚,是做吉祥物很好的原型。充满趣味性,话题性。 2.客至心常热,人走茶不凉。 3.动不动敬往事一...

  • 20170819

    科研终于有进步了!!!普天同庆

  • 20170819

    我爸说我有个很大的问题,我思考了一下,觉得他是对的。 我一直都习惯于对很多事情表现得不在意,即使我其实很在意,也要...

  • 20170819

    美好的一天从感恩开始:我感恩生命的富足美好!我感恩健康!我感恩天气!我感恩老公辛劳打拼!我感恩骗子投诉让我的微信被...

  • 20170819

    触发timePlus

网友评论

      本文标题:20170819

      本文链接:https://www.haomeiwen.com/subject/oktxdxtx.html