react-native - 自定义控件

2017-10-13  本文已影响60人  GA_
MyButton.js
import React,{
  Component
} from 'react';
import {
  Text,
  View,
} from 'react-native';

var MyButton = React.createClass({
  setNativeProps(nativeProps) {
    this._root.setNativeProps(nativeProps);
  },

  render() {
    return (
      <View ref={component => this._root = component} {...this.props}>
        <Text>{this.props.label}</Text>
      </View>
    )
  },
});

module.exports = MyButton;

使用...

    var MyButton = require('./MyButton');
    <MyButton label="Press me!" />
上一篇 下一篇

猜你喜欢

热点阅读