From 42975f8d362f55bda28d1195e9d06ebf80899245 Mon Sep 17 00:00:00 2001 From: Suhair Zain Date: Fri, 6 Oct 2017 15:22:10 +0530 Subject: [PATCH 1/3] Made Hamburger a controlled component This is useful to animation only if a certain condition is met, like only when navigating to a certain page. Also fixed an issue where this.props.active was being used instead of nextProps.active --- Hamburger.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Hamburger.js b/Hamburger.js index 4fee6b0..4adcff6 100644 --- a/Hamburger.js +++ b/Hamburger.js @@ -186,12 +186,8 @@ export default class Hamburger extends Component { } - _animate() { - setTimeout(()=> { - this.setState({ - active: this.props.active - }); - }, 0); + _animate(active) { + this.setState({ active }); const { props: { type } } = this; type=="spinArrow" ? this.spinArrow() : type=="arrow" ? this.arrow() : @@ -202,7 +198,7 @@ export default class Hamburger extends Component { } componentWillReceiveProps(nextProps) { if (nextProps.active !== this.state.active) { - this._animate(); + this._animate(nextProps.active); } } componentDidMount() { @@ -260,7 +256,7 @@ export default class Hamburger extends Component { return ( {this.props.onPress ? this.props.onPress() : undefined, this._animate()}}> + onPress={()=> {this.props.onPress ? this.props.onPress() : undefined}}> Date: Wed, 20 May 2020 20:06:22 +0100 Subject: [PATCH 2/3] Create index.d.ts --- index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9cf65fa --- /dev/null +++ b/index.d.ts @@ -0,0 +1,6 @@ +export default interface HamburgerProps { + active: boolean; + type: 'cross' | 'spinCross' | 'arrow' | 'spinArrow'; + color?: string; + onPress?: () => void; +} From 6bbd490a6d13825656dd350ef24fae4fde0d50fe Mon Sep 17 00:00:00 2001 From: hmoule <57354264+hmoule@users.noreply.github.com> Date: Wed, 20 May 2020 20:10:17 +0100 Subject: [PATCH 3/3] Update index.d.ts --- index.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 9cf65fa..d25cf90 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,10 @@ -export default interface HamburgerProps { +import { Component } from "react"; + +interface HamburgerProps { active: boolean; type: 'cross' | 'spinCross' | 'arrow' | 'spinArrow'; color?: string; onPress?: () => void; } + +export default class Hamburger extends Component {}