Skip to content

Commit 0ec80b8

Browse files
jakewtaylormastermoo
authored andcommitted
Add render prop to ActionButton (#254)
* Add render prop to ActionButton * Add documentation for `renderIcon` prop * Add deprecation warning for `icon` prop
1 parent cd06f74 commit 0ec80b8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

ActionButton.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,12 @@ export default class ActionButton extends Component {
222222
}
223223

224224
_renderButtonIcon() {
225-
const { icon, btnOutRangeTxt, buttonTextStyle, buttonText } = this.props;
226-
if (icon) return icon;
225+
const { icon, renderIcon, btnOutRangeTxt, buttonTextStyle, buttonText } = this.props;
226+
if (renderIcon) return renderIcon(this.state.active);
227+
if (icon) {
228+
console.warn('react-native-action-button: The `icon` prop is deprecated! Use `renderIcon` instead.');
229+
return icon;
230+
}
227231

228232
const textColor = buttonTextStyle.color || "rgba(255,255,255,1)";
229233

@@ -344,6 +348,8 @@ ActionButton.propTypes = {
344348
PropTypes.number
345349
]),
346350

351+
renderIcon: PropTypes.func,
352+
347353
bgColor: PropTypes.string,
348354
bgOpacity: PropTypes.number,
349355
buttonColor: PropTypes.string,

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
114114
| onPressIn | function | null | fires, before ActionButton is released
115115
| onPressOut | function | null | fires, after ActionButton is released
116116
| onLongPress | function | null | fires, when ActionButton is long pressed
117-
| icon | Component | + | Custom component for ActionButton Icon
117+
| 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.
118+
| icon         | Component     | +                   | **Deprecated, use `renderIcon`** Custom component for ActionButton Icon
118119
| 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))
119120
| degrees | number | 135 | degrees to rotate icon
120121
| buttonText | string | + | use this to set a different text on the button

0 commit comments

Comments
 (0)