-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(FEC-9309): when clicking on Fast Forward button, the arrow someti…
…mes isn't rotates in playlist when countdown window shown (#406) * add `withAnimation` HOC for reuse * handle the animation restart by `animationend` listener
- Loading branch information
Showing
3 changed files
with
74 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//@flow | ||
import {BaseComponent} from '../components/base'; | ||
import {h} from 'preact'; | ||
|
||
/** | ||
* @param {BaseComponent} WrappedComponent - The component to animate | ||
* @param {string} cssClass - the CSS class to add/remove for the animation | ||
* @returns {BaseComponent} - HOC that handles animation | ||
*/ | ||
export const withAnimation: Function = (WrappedComponent: BaseComponent, cssClass: string): typeof BaseComponent => | ||
class extends BaseComponent { | ||
element: HTMLElement; | ||
|
||
/** | ||
* adds the animation class | ||
* | ||
* @returns {void} | ||
* @memberof HOC | ||
*/ | ||
animate(): void { | ||
this.element.classList.add(cssClass); | ||
} | ||
|
||
/** | ||
* after component mounted, listen to events | ||
* | ||
* @returns {void} | ||
* @memberof HOC | ||
*/ | ||
componentDidMount() { | ||
this.eventManager.listen(this.element, 'animationend', () => { | ||
this.element.classList.remove(cssClass); | ||
}); | ||
} | ||
|
||
/** | ||
* before component unmounted, remove event listeners | ||
* | ||
* @returns {void} | ||
* @memberof HOC | ||
*/ | ||
componentWillUnmount(): void { | ||
super.componentWillUnmount(); | ||
this.element.classList.remove(cssClass); | ||
} | ||
|
||
/** | ||
* render component | ||
* | ||
* @param {*} props - component props | ||
* @returns {React$Element} - component element | ||
* @memberof HOC | ||
*/ | ||
render(props: any): React$Element<any> | void { | ||
return h(WrappedComponent, { | ||
...props, | ||
innerRef: ref => (this.element = ref), | ||
animate: this.animate.bind(this) | ||
}); | ||
} | ||
}; |