react-native-smart-button
A smart button for react-native apps, written in JS for cross-platform support. It works on iOS and Android.
This component is compatible with React Native 0.25 and newer.
Inspired by react-native-button
Preview
Installation
npm install react-native-smart-button --save
Full Demo
Usage
Install the package from npm with npm install react-native-smart-button --save
.
Then, require it from your app's JavaScript files with import Button from 'react-native-smart-button'
.
If you need use badge button, Install the badge from npm with npm install react-native-smart-badge --save
.
Then, require it from your app's JavaScript files with import Badge from 'react-native-smart-badge'
.
const styles = StyleSheet; // 构造 { superprops // 初始状态 thisstate = btn_1_loading: false btn_2_loading: false btn_3_loading: false btn_1_disabled: false btn_2_disabled: false btn_3_disabled: false } { return <ScrollView style=flex: 1 marginTop: 20 + 44 > <Button disabled=true style=stylesbuttonStyle textStyle=stylesbuttonTextStyle disabledStyle=stylesbuttonDisabledStyle disabledTextStyle=stylesbuttonDisabledTextStyle> </Button> <Button style=stylesbuttonStyle textStyle=stylesbuttonTextStyle> opacity </Button> <Button touchableType=ButtonconstantstouchableTypesfadeContent style=stylesbuttonStyle textStyle=stylesbuttonTextStyle> opacity </Button> <Button touchableType=ButtonconstantstouchableTypeshighlight underlayColor='#C90000' style=stylesbuttonStyle textStyle=stylesbuttonTextStyle> </Button> <Button touchableType=ButtonconstantstouchableTypesblur style=stylesbuttonStyle textStyle=stylesbuttonTextStyle> blur for </Button> <Button loading=thisstatebtn_1_loading disabled=thisstatebtn_1_disabled touchableType=ButtonconstantstouchableTypesfade style=stylesbuttonStyle textStyle=stylesbuttonTextStyle renderLoadingComponent=this_renderLoadingComponent_1 onPress=this_handlePress_1> </Button> <Button loading=thisstatebtn_2_loading disabled=thisstatebtn_2_disabled touchableType=ButtonconstantstouchableTypesfadeContent style=stylesbuttonStyle textStyle=stylesbuttonTextStyle renderLoadingComponent=this_renderLoadingComponent_2 onPress=this_handlePress_2> </Button> <Button touchableType=ButtonconstantstouchableTypeshighlight underlayColor='#C90000' style=stylesbuttonStyle textStyle=stylesbuttonTextStyle> <Image source=image_liking style=width: 40 height: 40 marginRight: 3 /> </Button> <Button touchableType=ButtonconstantstouchableTypesblur style=stylesbuttonStyle textStyle=stylesbuttonTextStyle> <Badge style= backgroundColor: '#00AAEF' marginLeft: 6 textStyle= color: '#fff' fontSize: 12 > 8 </Badge> </Button> </ScrollView> } { this this } { this this } { return this } { return <View style=flexDirection: 'row' alignItems: 'center'> this <Text style= fontSize: 17 color: 'white' fontWeight: 'bold' fontFamily: '.HelveticaNeueInterface-MediumP4' >loading</Text> </View> } { return ActivityIndicator ? <ActivityIndicator style=margin: 10 animating=true color='#fff' size='small'/> : PlatformOS == 'android' ? <ProgressBarAndroid style=margin: 10 color='#fff' styleAttr='Small'/> : <ActivityIndicatorIOS style=margin: 10 animating=true color='#fff' size='small'/> } AllButton
Props
Prop | Type | Optional | Default | Description |
---|---|---|---|---|
touchableType | string | Yes | constants.fade | determines what kind of style of the button should be when touch is active. |
activeOpacity | number | Yes | 0.2 | see react-native documents |
underlayColor | color | Yes | see react-native documents | |
style | style | Yes | see react-native documents | |
textStyle | style | Yes | see react-native documents | |
disabledStyle | style | Yes | see react-native documents | |
disabledTextStyle | style | Yes | see react-native documents | |
onPressIn | func | Yes | see react-native documents | |
onPressOut | func | Yes | see react-native documents | |
onPress | func | Yes | see react-native documents | |
onLayout | func | Yes | see react-native documents | |
disabled | bool | Yes | see react-native documents | |
loading | bool | Yes | false | determines the loading status of the button |
renderLoadingComponent | func | Yes | determines render function which return the presentation to replaces the content when loading status of the button is true | |
shadowOpacity | number | Yes | 1 | see react-native documents |
shadowColor | color | Yes | '#fff' | see react-native documents |