Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

New properties #371

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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class Application extends React.Component {
| animationStyle | none | (Function -> Object) | Function that accept 1 argument (value) and return an object: <br /> - `value` you should use at the place you need current value of animated parameter (left offset of content view) |
| bounceBackOnOverdraw | true | boolean | when true, content view will bounce back to openMenuOffset when dragged further |
| autoClosing | true | boolean | When true, menu close automatically as soon as an event occurs |
| closeByClickingOnContent | true | boolean | When true, menu close automatically as soon as the content area was touched |
| fixedMenuOffset | false | boolean | When true, menu offset is independent of the layout size |

### FAQ

Expand Down
19 changes: 15 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type Props = {
onStartShouldSetResponderCapture: Function,
isOpen: bool,
bounceBackOnOverdraw: bool,
autoClosing: bool
autoClosing: bool,
closeByClickingOnContent: bool,
fixedMenuOffset: bool
};

type Event = {
Expand Down Expand Up @@ -101,7 +103,7 @@ export default class SideMenu extends React.Component {
left,
};

this.state.left.addListener(({value}) => this.props.onSliding(Math.abs((value - this.state.hiddenMenuOffset) / (this.state.openMenuOffset - this.state.hiddenMenuOffset))));
this.state.left.addListener(({ value }) => props.onSliding(Math.abs((value - this.state.hiddenMenuOffset) / (this.state.openMenuOffset - this.state.hiddenMenuOffset))));
}

componentWillMount(): void {
Expand All @@ -124,7 +126,11 @@ export default class SideMenu extends React.Component {
const { width, height } = e.nativeEvent.layout;
const openMenuOffset = width * this.state.openOffsetMenuPercentage;
const hiddenMenuOffset = width * this.state.hiddenMenuOffsetPercentage;
this.setState({ width, height, openMenuOffset, hiddenMenuOffset });
if (this.props.fixedMenuOffset === true) {
this.setState({ width, height, hiddenMenuOffset });
} else {
this.setState({ width, height, openMenuOffset, hiddenMenuOffset });
}
}

/**
Expand All @@ -134,7 +140,7 @@ export default class SideMenu extends React.Component {
getContentView() {
let overlay: React.Element<void, void> = null;

if (this.isOpen) {
if (this.props.closeByClickingOnContent && this.isOpen) {
overlay = (
<TouchableWithoutFeedback onPress={() => this.openMenu(false)}>
<View style={styles.overlay} />
Expand Down Expand Up @@ -275,6 +281,9 @@ SideMenu.propTypes = {
isOpen: PropTypes.bool,
bounceBackOnOverdraw: PropTypes.bool,
autoClosing: PropTypes.bool,
closeByClickingOnContent: PropTypes.bool,
onSliding: PropTypes.func,
fixedMenuOffset: PropTypes.bool,
};

SideMenu.defaultProps = {
Expand Down Expand Up @@ -304,4 +313,6 @@ SideMenu.defaultProps = {
isOpen: false,
bounceBackOnOverdraw: true,
autoClosing: true,
closeByClickingOnContent: true,
fixedMenuOffset: false,
};