React Native : 按钮 Button

React Native初探: http://www.jb51.cc/article/p-wtukbzxm-bob.html

RN内置了Touchable*可用来生成按钮。例如:

<TouchableHighlight onPress={this._onPressButton}>
          <Text>Button1</Text>
        </TouchableHighlight>

就差自定义样式了。

1、react-native-button库

https://github.com/ide/react-native-button 里做了简单的封装。

npm install react-native-button --save

代码示例:

import React,{ Component } from 'react';
import {
  AppRegistry,StyleSheet,Text,View,TouchableHighlight
} from 'react-native';

import Button from 'react-native-button';

class MyReactNativeProject extends Component {

  _onPressButton() {
    console.log("You tapped the button!");
  }

  _onPressButton2() {
    console.log('pressed!');
  }
  render() {

    return (
      <View style={styles.container}>

        <TouchableHighlight onPress={this._onPressButton}>
          <Text>Button1</Text>
        </TouchableHighlight>

        <Button
          style={{fontSize: 20,color: 'green'}}
          styledisabled={{color: 'red'}}
          onPress={() => this._onPressButton2()}>
          Button2
        </Button>

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},});

AppRegistry.registerComponent('MyReactNativeProject',() => MyReactNativeProject);

效果图:

2、react-native-awesome-button库

这个更像按钮。

https://github.com/larsvinter/react-native-awesome-button

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...