Skip to content

Commit

Permalink
fix: prevent animateIn/Out in default options from overriding animate…
Browse files Browse the repository at this point in the history
…In/OutConfig in specific modal options 🐞
  • Loading branch information
CharlesMangwa committed Jan 24, 2022
1 parent 02ad71e commit 3bdc9df
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions utils/getStackItemOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export default function <P>(
stackItem: ModalStackItem<P> | undefined,
stack: ModalStack<P>,
): ModalOptions {
const stackItemOption = <K extends keyof ModalOptions>(
key: K,
): ModalOptions[K] =>
stackItem?.component.modalOptions?.[key] || stackItem?.options?.[key]

const extractOption = <K extends keyof ModalOptions>(
key: K,
): ModalOptions[K] =>
Expand All @@ -12,17 +17,27 @@ export default function <P>(
stack.defaultOptions[key]

return {
disableFlingGesture: extractOption('disableFlingGesture'),
transitionOptions: extractOption('transitionOptions'),
animateOutConfig: extractOption('animateOutConfig'),
shouldAnimateOut: extractOption('shouldAnimateOut'),
backdropOpacity: extractOption('backdropOpacity'),
animateInConfig: extractOption('animateInConfig'),
containerStyle: extractOption('containerStyle'),
backdropColor: extractOption('backdropColor'),
backBehavior: extractOption('backBehavior'),
animationOut: extractOption('animationOut'),
animationIn: extractOption('animationIn'),
position: extractOption('position'),
backBehavior: extractOption('backBehavior'),
backdropColor: extractOption('backdropColor'),
containerStyle: extractOption('containerStyle'),
animateInConfig: extractOption('animateInConfig'),
backdropOpacity: extractOption('backdropOpacity'),
animateOutConfig: extractOption('animateOutConfig'),
transitionOptions: extractOption('transitionOptions'),
disableFlingGesture: extractOption('disableFlingGesture'),
/**
* NOTE: In StackItem's updateAnimatedValue() we don't use the `animateIn/OutConfig` if
* the `animateIn/Out` exists. However, those can be coming from the defaultOptions and
* in the stackItem option, only `animateIn/OutConfig` would be defined. Hence the need
* for this check so that the default `animateIn/Out` wouldn't override the stackItem
* specific `animateIn/OutConfig`.
*/
animationIn: stackItemOption('animateInConfig')
? undefined
: extractOption('animationIn'),
animationOut: stackItemOption('animateOutConfig')
? undefined
: extractOption('animationOut'),
}
}

0 comments on commit 3bdc9df

Please sign in to comment.