美文网首页
ReactNative→事件

ReactNative→事件

作者: 动感超人丶 | 来源:发表于2017-04-21 15:31 被阅读9次

// ES5的写法

var  helloworld = React.createClass({
});

// ES6的写法

export default class helloworld extends Component {
});

生命周期:
三个阶段:初始化、存在、销毁
注意:default和init函数内的变量存取方法,ref的运用类似OC tag


var  helloworld = React.createClass({

  // 这个函数存放常亮
      getDefaultProps(){
        return{
          a:'常亮'
        }
      },
  // 这个函数存放变量
      getInitialState(){
        return{
          title: '默认'
        };
      },

  render() {

    return (

        <View style={styles.container}>
          <TouchableOpacity
              activeOpacity={0.5}
              onPress={()=>this.actvitEvent('点击')}
              onPressIn={()=>this.actvitEvent('按下')}
              onPressOut={()=>this.actvitEvent('抬起')}
              onLongPress={()=>this.actvitEvent('长按')}
          >
            <View style={styles.loginview}>
            <Text>{this.state.title}</Text>
             <Text>{this.props.a}</Text>
             <Text ref="tags">'ref测试'</Text>

             </View>
          </TouchableOpacity>

        </View>
    );
  },
      actvitEvent:function(event) {

  this.setState({
    title:event
    this.refs.tags.....
  });
  }
}
);

相关文章

网友评论

      本文标题:ReactNative→事件

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