Skip to content

Commit

Permalink
Merge pull request #24 from santomegonzalo/open-on-mount
Browse files Browse the repository at this point in the history
Open on mount
  • Loading branch information
santomegonzalo authored Jan 22, 2018
2 parents 38b3243 + 46847f4 commit 3025529
Show file tree
Hide file tree
Showing 76 changed files with 184 additions and 8,065 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#exclude all examples

./example
.DS_STORE
README.md
node_modules/
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ yarn add react-native-floating-action

## Usage

To see how works, take a look into **example/FloatingAction**
To see how works, take a look into **example/ReactNativeFloatingAction-Expo**

To execute an example using Expo run the following command:

```bash
yarn test
```

**First step:** import the component:

Expand Down Expand Up @@ -98,6 +104,8 @@ import { FloatingAction } from 'react-native-floating-action';
| position | string | right | Position to render the main button and actions, options: (**left**, **right**, **center**) |
| overrideWithAction | string | false | Override the main action with the first action inside list actions, will not show other action |
| floatingIcon | node | ReactElement | | Change the default plus icon using **require(pathToImage)** or **ReactElement** |
| showBackground | boolean | true | **Show** or **Hide** background after open it |
| openOnMount | boolean | false | Open component after mounting it, useful on some weird cases like tutorials |
| onPressItem | function | | Function to be call as soon as the user select an option from actions. Will return the name of the action. |
| onPressMain | function | | Function to be call as soon as use click main button and will return **true** or **false** depeneding of the state. |

Expand All @@ -117,6 +125,9 @@ import { FloatingAction } from 'react-native-floating-action';
- [x] add colors configurations
- [x] add more positions like left, center and right
- [x] support hide or show the component with an animation
- [ ] add sizing configurations
- [x] change plus icon to be customizable
- [x] use components as icon
- [x] hide background
- [x] open on mounting
- [ ] allow user defined animations
- [ ] use crazy animations
26 changes: 23 additions & 3 deletions component/FloatingAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class FloatingAction extends Component {
this.visibleAnimation = new Animated.Value(props.visible ? 0 : 1);
}

componentDidMount() {
const { openOnMount } = this.props;

if (openOnMount) {
this.animateButton();
}
}

componentWillReceiveProps(nextProps) {
if (nextProps.visible !== this.props.visible) {
if (nextProps.visible) {
Expand Down Expand Up @@ -86,7 +94,12 @@ class FloatingAction extends Component {
};

animateButton = () => {
const { overrideWithAction, actions, floatingIcon, onPressMain } = this.props;
const {
overrideWithAction,
actions,
floatingIcon,
onPressMain
} = this.props;

if (overrideWithAction) {
this.handlePressItem(actions[0].name);
Expand Down Expand Up @@ -250,13 +263,16 @@ class FloatingAction extends Component {
}

render() {
const { active } = this.state;
const { showBackground } = this.props;

return (
<Animated.View
pointerEvents="box-none"
style={[styles.overlay, { backgroundColor: 'transparent' }]}
>
{
this.state.active &&
active && showBackground &&
this.renderTappableBackground()
}
{
Expand Down Expand Up @@ -288,6 +304,8 @@ FloatingAction.propTypes = {
overrideWithAction: PropTypes.bool, // use the first action like main action
onPressItem: PropTypes.func,
distanceToEdge: PropTypes.number,
openOnMount: PropTypes.bool,
showBackground: PropTypes.bool,
onPressMain: PropTypes.func
};

Expand All @@ -297,7 +315,9 @@ FloatingAction.defaultProps = {
buttonColor: '#1253bc',
overlayColor: 'rgba(68, 68, 68, 0.6)',
position: 'right',
distanceToEdge: 30
distanceToEdge: 30,
openOnMount: false,
showBackground: true
};

const styles = StyleSheet.create({
Expand Down
Binary file modified example/.DS_Store
Binary file not shown.
3 changes: 0 additions & 3 deletions example/FloatingAction/.babelrc

This file was deleted.

6 changes: 0 additions & 6 deletions example/FloatingAction/.buckconfig

This file was deleted.

34 changes: 0 additions & 34 deletions example/FloatingAction/.eslintrc

This file was deleted.

47 changes: 0 additions & 47 deletions example/FloatingAction/.flowconfig

This file was deleted.

1 change: 0 additions & 1 deletion example/FloatingAction/.gitattributes

This file was deleted.

53 changes: 0 additions & 53 deletions example/FloatingAction/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion example/FloatingAction/.watchmanconfig

This file was deleted.

12 changes: 0 additions & 12 deletions example/FloatingAction/__tests__/index.android.js

This file was deleted.

12 changes: 0 additions & 12 deletions example/FloatingAction/__tests__/index.ios.js

This file was deleted.

65 changes: 0 additions & 65 deletions example/FloatingAction/android/app/BUCK

This file was deleted.

Loading

0 comments on commit 3025529

Please sign in to comment.