Skip to content

Commit e4203ee

Browse files
committed
Merge branch 'master' of https://github.com/mastermoo/react-native-action-button into mastermoo-master
2 parents 55cf0d4 + 95a72d6 commit e4203ee

File tree

6 files changed

+164
-11
lines changed

6 files changed

+164
-11
lines changed

ActionButton.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ export default class ActionButton extends Component {
3232
this.timeout = null;
3333
}
3434

35+
componentDidMount() {
36+
this.mounted = true;
37+
}
38+
3539
componentWillUnmount() {
40+
this.mounted = false;
3641
clearTimeout(this.timeout);
3742
}
3843

@@ -211,6 +216,8 @@ export default class ActionButton extends Component {
211216
>
212217
<Touchable
213218
testID={this.props.testID}
219+
accessible={this.props.accessible}
220+
accessibilityLabel={this.props.accessibilityLabel}
214221
background={touchableBackground(
215222
this.props.nativeFeedbackRippleColor,
216223
this.props.fixNativeFeedbackRadius
@@ -237,8 +244,12 @@ export default class ActionButton extends Component {
237244
}
238245

239246
_renderButtonIcon() {
240-
const { icon, btnOutRangeTxt, buttonTextStyle, buttonText } = this.props;
241-
if (icon) return icon;
247+
const { icon, renderIcon, btnOutRangeTxt, buttonTextStyle, buttonText } = this.props;
248+
if (renderIcon) return renderIcon(this.state.active);
249+
if (icon) {
250+
console.warn('react-native-action-button: The `icon` prop is deprecated! Use `renderIcon` instead.');
251+
return icon;
252+
}
242253

243254
const textColor = buttonTextStyle.color || "rgba(255,255,255,1)";
244255

@@ -265,7 +276,9 @@ export default class ActionButton extends Component {
265276

266277
if (!this.state.active) return null;
267278

268-
const actionButtons = !Array.isArray(children) ? [children] : children;
279+
let actionButtons = !Array.isArray(children) ? [children] : children;
280+
281+
actionButtons = actionButtons.filter( actionButton => (typeof actionButton == 'object') )
269282

270283
const actionStyle = {
271284
flex: 1,
@@ -335,10 +348,11 @@ export default class ActionButton extends Component {
335348
this.anim.setValue(0);
336349
}
337350

338-
setTimeout(
339-
() => this.setState({ active: false, resetToken: this.state.resetToken }),
340-
250
341-
);
351+
setTimeout(() => {
352+
if (this.mounted) {
353+
this.setState({ active: false, resetToken: this.state.resetToken });
354+
}
355+
}, 250);
342356
}
343357
}
344358

@@ -360,6 +374,8 @@ ActionButton.propTypes = {
360374
PropTypes.number
361375
]),
362376

377+
renderIcon: PropTypes.func,
378+
363379
bgColor: PropTypes.string,
364380
bgOpacity: PropTypes.number,
365381
buttonColor: PropTypes.string,
@@ -384,7 +400,9 @@ ActionButton.propTypes = {
384400
fixNativeFeedbackRadius: PropTypes.bool,
385401
nativeFeedbackRippleColor: PropTypes.string,
386402

387-
testID: PropTypes.string
403+
testID: PropTypes.string,
404+
accessibilityLabel: PropTypes.string,
405+
accessible: PropTypes.bool
388406
};
389407

390408
ActionButton.defaultProps = {
@@ -414,7 +432,9 @@ ActionButton.defaultProps = {
414432
activeOpacity: DEFAULT_ACTIVE_OPACITY,
415433
fixNativeFeedbackRadius: false,
416434
nativeFeedbackRippleColor: "rgba(255,255,255,0.75)",
417-
testID: undefined
435+
testID: undefined,
436+
accessibilityLabel: undefined,
437+
accessible: undefined
418438
};
419439

420440
const styles = StyleSheet.create({

ActionButtonItem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default class ActionButtonItem extends Component {
108108
>
109109
<Touchable
110110
testID={this.props.testID}
111+
accessibilityLabel={this.props.accessibilityLabel}
111112
background={touchableBackground(
112113
this.props.nativeFeedbackRippleColor,
113114
this.props.fixNativeFeedbackRadius

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
9898
##### ActionButton:
9999
| Property | Type | Default | Description |
100100
| ------------- |:-------------:|:------------: | ----------- |
101+
| size | number | 56 | use this to change the size of the Button
101102
| resetToken | any | null | use this to reset the internal component state (expand/collapse) in a re-render cycle. Synchronize the component state.
102103
| active | boolean | false | action buttons visible or not
103104
| autoInactive | boolean | true | Auto hide ActionButtons when ActionButton.Item is pressed.
@@ -114,7 +115,8 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
114115
| onPressIn | function | null | fires, before ActionButton is released
115116
| onPressOut | function | null | fires, after ActionButton is released
116117
| onLongPress | function | null | fires, when ActionButton is long pressed
117-
| icon | Component | + | Custom component for ActionButton Icon
118+
| renderIcon   | function | null | Function to render the component for ActionButton Icon. It is passed a boolean, `active`, which is true if the FAB has been expanded, and false if it is collapsed, allowing you to show a different icon when the ActionButton Items are expanded.
119+
| icon         | Component     | +                   | **Deprecated, use `renderIcon`** Custom component for ActionButton Icon
118120
| backdrop | Component | false | Custom component for use as Backdrop (i.e. [BlurView](https://github.com/react-native-fellowship/react-native-blur#blur-view), [VibrancyView](https://github.com/react-native-fellowship/react-native-blur#vibrancy-view))
119121
| degrees | number | 135 | degrees to rotate icon
120122
| buttonText | string | + | use this to set a different text on the button
@@ -132,6 +134,7 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
132134
##### ActionButton.Item:
133135
| Property | Type | Default | Description |
134136
| ------------- |:-------------:|:------------: | ----------- |
137+
| size | number | parentSize | use this to change the size of the Button
135138
| title | string | undefined | the title shown next to the button. When `undefined` the title is not hidden
136139
| onPress | func | null | **required** function, triggers when a button is tapped
137140
| buttonColor | string | same as + button | background color of the Button

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface ActionButtonProperties extends ViewProperties {
2828
size?: number,
2929
autoInactive?: boolean,
3030
onPress?: () => void,
31+
renderIcon?: (active: boolean) => React.ReactElement,
3132
backdrop?: boolean | object,
3233
degrees?: number,
3334
verticalOrientation?: 'up' | 'down',
@@ -40,6 +41,7 @@ export interface ActionButtonProperties extends ViewProperties {
4041
}
4142

4243
export interface ActionButtonItemProperties extends ViewProperties {
44+
size?: number,
4345
title?: string
4446
onPress?:() => void
4547
buttonColor?:string

package-lock.json

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-action-button",
3-
"version": "2.10.0",
3+
"version": "2.8.5",
44
"description": "customizable multi-action-button component for react-native",
55
"main": "ActionButton.js",
66
"scripts": {

0 commit comments

Comments
 (0)