Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openOnPress property #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions ActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@ export default class ActionButton extends Component {
this.props.fixNativeFeedbackRadius
)}
activeOpacity={this.props.activeOpacity}
onLongPress={this.props.onLongPress}
onLongPress={() => {
this.props.onLongPress();
if (this.props.children && !this.props.openOnPress) this.animateButton();
}}
onPress={() => {
this.props.onPress();
if (this.props.children) this.animateButton();
if (this.props.children && (this.state.active || this.props.openOnPress)) this.animateButton();
}}
onPressIn={this.props.onPressIn}
onPressOut={this.props.onPressOut}
Expand Down Expand Up @@ -337,7 +340,7 @@ export default class ActionButton extends Component {

setTimeout(() => {
if (this.mounted) {
this.setState({ active: false, resetToken: this.state.resetToken });
this.setState({ active: false, resetToken: this.state.resetToken });
}
}, 250);
}
Expand Down Expand Up @@ -376,6 +379,8 @@ ActionButton.propTypes = {
onPress: PropTypes.func,
onPressIn: PropTypes.func,
onPressOut: PropTypes.func,
onLongPress: PropTypes.func,
openOnPress: PropTypes.bool,
backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
degrees: PropTypes.number,
verticalOrientation: PropTypes.oneOf(["up", "down"]),
Expand Down Expand Up @@ -405,6 +410,8 @@ ActionButton.defaultProps = {
onPress: () => {},
onPressIn: () => {},
onPressOn: () => {},
onLongPress: () => {},
openOnPress: true,
backdrop: false,
degrees: 45,
position: "right",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
| onPressIn | function | null | fires, before ActionButton is released
| onPressOut | function | null | fires, after ActionButton is released
| onLongPress | function | null | fires, when ActionButton is long pressed
| openOnPress | boolean | true | if true action buttons will open on press, if false they will open only on long press
| 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.
| icon         | Component     | +                   | **Deprecated, use `renderIcon`** Custom component for ActionButton Icon
| 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))
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface ActionButtonProperties extends ViewProperties {
size?: number,
autoInactive?: boolean,
onPress?: () => void,
onLongPress?: () => void,
openOnPress?: boolean,
renderIcon?: (active: boolean) => React.ReactElement<any>,
backdrop?: boolean | object,
degrees?: number,
Expand Down