react-native-button github上一个开源的button组件,目前仍保持比较快的更新频率。使用起来很棒~感谢作者的贡献~
使用一:通过
npm install react-native-button --save
指令从npm中安装react-native-button组件。在使用的使用使用import语句引入即可。
以下来自官网的使用例子:
import React, { Component } from 'react';
import Button from 'react-native-button';
export default class ExampleComponent extends Component {
constructor(props, context) {
super(props, context);
}
_handlePress() {
console.log('Pressed!');
}
render() {
return (
<Button
style={{fontSize: 20, color: 'green'}}
styleDisabled={{color: 'red'}}
onPress={() => this._handlePress()}>
Press Me!
</Button>
);
}
};
The React packager will include the Button component in your app's JS package and make it available for your app to use.
Container Style
You can make a button with rounded corners like this:
<Button
containerStyle={{padding:10, height:45, overflow:'hidden', borderRadius:4, backgroundColor: 'white'}}
style={{fontSize: 20, color: 'green'}}>
Press me!
</Button>