React Native : 按鈕 Button

React Native初探: https://my.oschina.net/letiantian/blog/753841react

RN內置了Touchable*可用來生成按鈕。例如:git

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

就差自定義樣式了。github

一、react-native-button庫

https://github.com/ide/react-native-button 裏作了簡單的封裝。npm

npm install react-native-button --save

代碼示例:react-native

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

效果圖:app

效果圖

二、react-native-awesome-button庫

這個更像按鈕。ide

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

輸入圖片說明

相關文章
相關標籤/搜索