20170822

作者: 入秋未凉的海 | 来源:发表于2017-08-22 21:49 被阅读0次
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

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>
        );
    }
})

class MyApp extends Component{
  constructor(props) {
  super(props)
    this.state = {
        hit: true,
        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);
npm i react-native-vector-icons
npm i rnpm -g
rnpm link react-native-vector-icons
react-native upgrade
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import Icon from 'react-native-vector-icons/Ionicons';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TabBarIOS
} from 'react-native';


var List = React.createClass({
    render: function () {
        return (
            <View style={styles.container}>
                <Text>列表页面</Text>
            </View>
        )
    }
})
var Edit = React.createClass({
    render: function () {
        return (
            <View style={styles.container}>
                <Text>制作页面</Text>
            </View>
        )
    }
})
var Account = React.createClass({
    render: function () {
        return (
            <View style={styles.container}>
                <Text>账户页面</Text>
            </View>
        )
    }
})


var MyApp = React.createClass({

    getInitialState(){
        console.log('getInitialState');
        return {
            selectedTab: 'blueTab'
        }
    },

    _renderContent: function(color: string, pageText: string, num?: number) {
        return (
            <View style={[styles.tabContent, {backgroundColor: color}]}>
              <Text style={styles.tabText}>{pageText}</Text>
              <Text style={styles.tabText}>{num} re-renders of the {pageText}</Text>
            </View>
        );
    },

    render: function() {
        return (
            <TabBarIOS
                tintColor="#ee735c">
              <Icon.TabBarItem
                  iconName='ios-videocam-outline'
                  selectIconName='ios-videocam'
                  selected={this.state.selectedTab === 'list'}
                  onPress={() => {
            this.setState({
              selectedTab: 'list'
            });
          }}>
                  <List/>
              </Icon.TabBarItem>
              <Icon.TabBarItem
                  iconName='ios-recording-outline'
                  selectIconName='ios-recording'
                  selected={this.state.selectedTab === 'edit'}
                  onPress={() => {
            this.setState({
              selectedTab: 'edit'
            });
          }}>
                  <Edit/>
              </Icon.TabBarItem>
              <Icon.TabBarItem
                  iconName='ios-more-outline'
                  selectIconName='ios-more'
                  selected={this.state.selectedTab === 'account'}
                  onPress={() => {
            this.setState({
              selectedTab: 'account'
            });
          }}>
                  <Account/>
              </Icon.TabBarItem>
            </TabBarIOS>
        );
    }
})



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);

相关文章

  • 高铁连连坐🚄🚉

    0200【无辣不欢】20170822学习力践行D160 20170822 ️高铁连连坐 @山东寿光 出门撒欢儿的娃...

  • 20170822

    今天发生了许多开心的事情!一大早就帮爸爸回想过去帮助他人的情景,相当于帮爸爸做咖啡冥想,也让我对爸爸了解更多!给爸...

  • 20170822

    人生最难熬的是孤独,或者说不想孤独的时候,却只能体验到孤独。那时无聊,寂寞,孤独一起袭来,无法阻挡,在这种状况,总...

  • 20170822

    风光的背后总得付出些代价,莫问前路,继续前行吧。

  • 20170822

    今天过生日啦给自己呱唧呱唧哎起得太晚了,还好自习室还有带插头的位置今天也要抓紧写咯 昨天的处理内容先完成 10:0...

  • 20170822

    看着身边的家长们,感觉自己好落后,她们一个个都那么爱学习,学心理学,学写作,学英语,一个家长告诉我只有自己不断改变...

  • 20170822

  • 20170822

    今天周二,晚上开了一个短会,说是短会也有一个小时了。 昨天早回家的,五点半不到就到家了,在家里玩了乒乓球。我和心远...

  • 20170822

    想才是问题,做才是答案

  • 20170822

    今天我注册了简书3344

网友评论

      本文标题:20170822

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