This repository has been archived by the owner on Oct 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect disappearing sidebar modal with RTL enabled
Change the way login and register modals are animated, make the transitions fully configurable and predictable
- Loading branch information
1 parent
e187a24
commit d33f3ea
Showing
7 changed files
with
113 additions
and
42 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
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
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,59 @@ | ||
const findNearestAncestorSatifying = (doneCondition, needNext, getNext) => { | ||
return function iterate(ancestor) { | ||
if (!ancestor) { | ||
return undefined; | ||
} | ||
if (doneCondition(ancestor)) { | ||
return ancestor; | ||
} | ||
if (!needNext(ancestor)) { | ||
return undefined; | ||
} | ||
|
||
return iterate(getNext(ancestor)); | ||
}; | ||
}; | ||
|
||
const TRANSITION_LIFECYCLE_HOOKS = [ | ||
'componentWillAppear', 'componentDidAppear', | ||
'componentWillEnter', 'componentDidEnter', | ||
'componentWillLeave', 'componentDidLeave' | ||
]; | ||
|
||
const getAncestorTransitionLifecycleHooks = (object) => { | ||
const component = findNearestAncestorSatifying( | ||
ancestor => TRANSITION_LIFECYCLE_HOOKS.some(hookName => hookName in ancestor), | ||
ancestor => 'getWrappedInstance' in ancestor, | ||
ancestor => ancestor.getWrappedInstance() | ||
)(object); | ||
|
||
if (!component) { | ||
return undefined; | ||
} | ||
|
||
return TRANSITION_LIFECYCLE_HOOKS.reduce( | ||
(acc, hookName) => (acc[hookName] = component[hookName], acc), {} | ||
); | ||
}; | ||
|
||
/** | ||
* Keep in mind the possibility of methods' `this` bind to change. | ||
* Define them as arrow functions, like `componentWillEnter = (callback) => ...` | ||
*/ | ||
export default function wrapWithTransition(WrappedComponent) { | ||
const componentName = WrappedComponent.displayName | ||
|| WrappedComponent.name | ||
|| 'Component'; | ||
|
||
return class Transition extends WrappedComponent { | ||
static displayName = `Transition(${componentName})`; | ||
|
||
// Refs are first available now | ||
componentDidMount() { | ||
const ancestorTransitionHooks = getAncestorTransitionLifecycleHooks(this); | ||
if (ancestorTransitionHooks) { | ||
Object.assign(this, ancestorTransitionHooks); | ||
} | ||
} | ||
}; | ||
} |