|
| 1 | +## react-native-animatable-button |
| 2 | +[](https://badge.fury.io/js/react-native-animatable-button) |
| 3 | +## Installation |
| 4 | +``` |
| 5 | +npm install react-native-animatable-button --save |
| 6 | +``` |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +- [x] States |
| 11 | +- [x] Opacity animation |
| 12 | +- [x] Tap animations |
| 13 | +- [x] Fully customizable |
| 14 | + |
| 15 | +## Props |
| 16 | + |
| 17 | +### Button Props |
| 18 | + |
| 19 | +| Props | Type | Description | Required | Default | |
| 20 | +|:---------------------|:----------------------------|:-----------------------------------|:-------------|:----------------------------| |
| 21 | +| accessibilityLabel | string | custom access label | not required | reactNativeAnimetableButton |
| 22 | +| buttonContainerStyle | Object<ViewSyle> | must be provided Object not STYLE | not required | see below |
| 23 | +| selectedState | string | selected id of provided states | not required | default |
| 24 | +| states | [key: string]: IButtonState | state object | not required | default state |
| 25 | +| disabled | boolean | enable/disable button | not required | false |
| 26 | +| touchFeedbaack | boolean | enable/disable tap opacity animate | not required | true |
| 27 | +| touchFeedbaackDelay | boolean | set delayPressIn prop of TOpacity | not required | 0 |
| 28 | + |
| 29 | +### Button Animation Props |
| 30 | + |
| 31 | +| Props | Type | Description | Required | Default | |
| 32 | +|:---------------------------|:----------------------------|:-----------------------------------|:-------------|:----------------------------------| |
| 33 | +| animationDelay | number | delay of animations | not required | 0 |
| 34 | +| animationDuration | number | animation duration time | not required | 400 |
| 35 | +| animationEasing | EasingFunction | easing options | not required | Easing.bezier(0.4, 0.2, 0.4, 1.3) |
| 36 | +| onPressAnimationEnable | boolean | tap animation config | not required | true |
| 37 | +| onPressAnimationScaleValue | number | number of scale to | not required | 1.05 |
| 38 | +| onPressAnimationType | button - inside | scale all button or inside | not required | button |
| 39 | +| startAnimationDelay | number | delay of start animation | not required | 0 |
| 40 | +| startAnimationDuration | number | animation duration time for start | not required | 400 |
| 41 | +| startAnimationEnable | boolean | enable/disable start animation | not required | true |
| 42 | +| backgroundAnimation | animated - slide | set background option | not required | animated |
| 43 | + |
| 44 | + |
| 45 | +### Button State Props |
| 46 | + |
| 47 | +| Props | Type | Description | Required | Default | |
| 48 | +|:------------------------------|:----------------------------|:-----------------------------------|:-------------|:----------------------------------| |
| 49 | +| buttonInsideContainerStyle | Object<ViewSyle> | must be provided Object not STYLE | not required | see below |
| 50 | +| icon | ImageURISource - any | icon uri or source | not required | - |
| 51 | +| iconStyle | ImageStyle | icon style | not required | see below |
| 52 | +| iconPosition | left - right | position of icon | not required | left |
| 53 | +| text | string | button text | not required | - |
| 54 | +| textStyle | TextStyle | text style | not required | see below |
| 55 | +| spinner | boolean | enable/disable spinner | not required | false |
| 56 | +| spinnerProps | ActivityIndicatorProperties | spinner Props | not required | - |
| 57 | +| syncIconAndTextAnimation | boolean | enable/disable animation diff | not required | false |
| 58 | +| asyncIconAndTextAnimationDiff | number [0 - 100] | percent of diff | not required | 50 |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +#### buttonContainerStyle |
| 63 | +```javascript |
| 64 | +{ |
| 65 | + backgroundColor: 'rgba(0,0,0,0)', |
| 66 | + borderRadius: 5, |
| 67 | + borderWidth: 1, |
| 68 | + height: ButtonSize.height, |
| 69 | + overflow: 'hidden' |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +#### buttonInsideContainerStyle |
| 74 | +```javascript |
| 75 | +{ |
| 76 | + alignItems: 'center', |
| 77 | + backgroundColor: 'rgba(0,0,0,0)', |
| 78 | + flexDirection: 'row', |
| 79 | + height: ButtonSize.height, |
| 80 | + justifyContent: 'center', |
| 81 | + overflow: 'hidden', |
| 82 | + paddingHorizontal: 10 |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +#### textStyle |
| 87 | +```javascript |
| 88 | +{ |
| 89 | + paddingHorizontal: 5 |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +#### iconStyle |
| 94 | +```javascript |
| 95 | +{ |
| 96 | + flex: 1, |
| 97 | + resizeMode: 'contain' |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +## Note |
| 102 | + Master props and state props are combined when provided. |
| 103 | + |
| 104 | +## Usage example |
| 105 | +```javascript |
| 106 | +constructor() { |
| 107 | + super(); |
| 108 | + |
| 109 | + this.state = { |
| 110 | + activeState: 'idle2' |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +render () { |
| 115 | + <Button |
| 116 | + touchFeedback={false} |
| 117 | + onPress={this.onPress.bind(this)} |
| 118 | + selectedState={this.state.activeState} |
| 119 | + buttonContainerStyle={{ |
| 120 | + height: 40 |
| 121 | + }} |
| 122 | + buttonInsideContainerStyle={{ |
| 123 | + backgroundColor: 'rgba(100,100,100,0.5)' |
| 124 | + }} |
| 125 | + onPress={() => { |
| 126 | + console.log('master pressed'); |
| 127 | + if (this.state.activeState === 'idle2') this.setState({ activeState: 'idle' }); |
| 128 | + }} |
| 129 | + states={{ |
| 130 | + laodList: { |
| 131 | + text:"Load List", |
| 132 | + buttonInsideContainerStyle:{ |
| 133 | + backgroundColor: 'rgba(255,0,0,0.5)' |
| 134 | + }, |
| 135 | + onPress: () => { |
| 136 | + console.log('loadList pressed'); |
| 137 | + this.setState({ activeState: 'loading' }) |
| 138 | + |
| 139 | + return false; |
| 140 | + } |
| 141 | + }, |
| 142 | + // when tap laodList logs => loadList pressed; master pressed |
| 143 | + |
| 144 | + loading: { |
| 145 | + text:"loading", |
| 146 | + buttonInsideContainerStyle:{ |
| 147 | + backgroundColor: 'rgba(0,255,0,0.5)' |
| 148 | + }, |
| 149 | + spinner: true, |
| 150 | + onPress: () => { console.log('loading pressed'); return true; } |
| 151 | + }, |
| 152 | + // when tap loading logs => loading pressed; |
| 153 | + |
| 154 | + idle: { |
| 155 | + text:"idle", |
| 156 | + onPress: () => { |
| 157 | + console.log('idle pressed'); |
| 158 | + this.setState({ activeState: 'loadList' }) |
| 159 | + } |
| 160 | + }, |
| 161 | + // when tap idle logs => idle pressed; master pressed |
| 162 | + |
| 163 | + idle2: { |
| 164 | + text:"idle2", |
| 165 | + } |
| 166 | + // when tap idle2 logs => master pressed |
| 167 | + }} |
| 168 | + /> |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +### Description |
| 173 | +if you are return `false` or `undefined` in sub onPress functions when call master onPress function. |
| 174 | + |
0 commit comments