分类 props 下的文章

TouchableOpacity


今天学的组件有点于类似于原生Android当中的button,点击它时它的背景会发生变化,给用户一种视觉交互。在Android中叫selector,而在RN中叫Touchable系列。之前在学Text组件时,我们通过onPress事件可以给Text组件绑定触摸点击事件。为了像Text组件那样使得其他组件也可以被点击,RN提供了三个Touchable类组件:

TouchableHightlight:高亮触摸。用户点击时,会产生高亮效果
TouchableOpacity:透明触摸。用户点击时,被点击的组件会出现透明效果


接收一个事件处理器作为props


Talker.js

    var React = require('react');
    var ReactDOM = require('react-dom');
    var Button = require('./Button');
    var Talker = React.createClass({
      handleClick: function () {//一个事件处理器
        for (var speech = '', i = 0; i < 2; i++) {
          speech += 'blah ';
        }
        alert(speech);
      },
      
      render: function () {
        return <Button onClick={this.handleClick}></Button>;//Talker的属性有onClick
      }
    });
    ReactDOM.render(
      <Talker ></Talker>,
      document.getElementById('app')
    );

Button.js

var React = require('react');
var Button = React.createClass({
  render: function () {
    return (
      <button onClick={this.props.onClick}>//后面的onClick是Talker.js中的Talker组件的属性
        Click me!
      </button>
    );
  }
});
module.exports = Button;

A curmudgeonly clarification about grammar


You may have noticed some loose usage of the words prop and props. Unfortunately this is pretty inevitable.

props is the name of the object that stores passed-in information. this.props refers to that storage object. At the same time, each piece of passed-in information is also called a prop. props could refer to two pieces of passed-in information, or it could refer to the object that stores those pieces of information. :(


接收一个事件处理器作为props


接收一个事件处理器作为props


Talker.js
<wiz_code_mirror>
shijiebei 365bet manbetx 188bet xinshui caipiao 95zz tongbaoyule beplay 88bifa 18luck betway bwin hg0088 aomenjinshayulecheng ca88 shenbotaiyangcheng vwin w88 weide