(modalName: N, params?: P[N], callback?: () => void) => void;
stack: ModalStack;
}
export declare type ModalInternalState
= {
currentModal: ModalContextProvider
['currentModal'] | string | null;
stack: ModalContextProvider
['stack'];
};
export interface ModalStateSubscriber
{
state: ModalInternalState
;
equalityFn: ModalStateEqualityChecker
;
error: boolean;
stateListener: ModalStateListener
;
unsubscribe: () => boolean;
}
export interface ModalStateSubscription
{
unsubscribe: ModalStateSubscriber
['unsubscribe'];
}
export declare type ModalStateListener
= (state: ModalInternalState
| null, error?: Error) => void;
export declare type ModalStateEqualityChecker
= (currentState: ModalInternalState
, newState: ModalInternalState
) => boolean;
export declare type ModalState
= Omit, 'currentModal' | 'stack' | 'openModal'> & {
openModal: , N extends M>(args: {
modalName: N;
params?: P[N];
isCalledOutsideOfContext?: boolean;
callback?: () => void;
}) => void;
handleBackPress: () => boolean;
init: (updater: (currentState: ModalInternalState) => ModalInternalState) => ModalInternalState;
getState: () => ModalInternalState;
setState: (updater: (currentState: ModalInternalState) => ModalInternalState) => ModalInternalState;
subscribe: (listener: ModalStateListener, equalityFn?: ModalStateEqualityChecker) => ModalStateSubscription;
queueClosingAction: (action: ModalStatePendingClosingAction) => ModalPendingClosingAction | null;
removeClosingAction: (action: ModalPendingClosingAction) => boolean;
};
export interface SharedProps extends ModalContextProvider
{
clearListeners: (hash: string) => void;
eventListeners: ModalEventListeners;
registerListener: (hash: ModalStackItem
['hash'], eventName: ModalEventName, handler: ModalEventCallback) => ModalEventListener;
removeClosingAction: ModalState
['removeClosingAction'];
}
export declare type UsableModalProp
= Pick, 'closeAllModals' | 'closeModals' | 'currentModal' | 'openModal'> & {
/**
* This function closes the currently displayed modal by default.
*
* You can also provide a `modalName` if you want to close a different modal
* than the latest opened. This will only close the latest instance of that modal,
* see `closeModals()` if you want to close all instances.
*
* @example modal.closeModal('Example', () => console.log('Current modal closed'))
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalprop#closemodal
*
* @note We're using modalfy.closeModal instead of ModalState.closeModal so that the animations
* can be triggered appropriately from the synced custom internal state.
*/
closeModal: (modalName?: Exclude, callback?: () => void) => void;
};
export interface UsableModalComponentProp extends Omit, 'closeModal' | 'stack' | 'getParam'> {
/**
* Ths function that allows you to hook a listener to the modal component you're in. Right now, the only listener
* types supported are: `'onAnimate'` & `'onClose'`.
*
* @example
*
* const onCloseListener = useRef()
*
* const handleClose: ModalOnCloseEventCallback = useCallback(
* closingAction => {
* console.log(`👋 Modal closed by: ${closingAction.type} • ${closingAction.origin}`)
* },
* []
* )
*
* useEffect(() => {
* onCloseListener.current = addListener('onAnimate', handleClose)
*
* return () => {
* onCloseListener.current?.remove()
* }
* }, [addListener, handleClose])
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalcomponentprop#addlistener
*/
addListener: ModalListener;
/**
* This function closes the currently displayed modal by default.
*
* You can also provide a `modalName` if you want to close a different modal
* than the latest opened. This will only close the latest instance of that modal,
* see `closeModals()` if you want to close all instances.
*
* @example closeModal('Example', () => console.log('Current modal closed'))
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalprop#closemodal
*
* @note We're using modalfy.closeModal instead of ModalState.closeModal so that the animations
* can be triggered appropriately from the synced custom internal state.
*/
closeModal: (modalName?: M, callback?: () => void) => void;
/**
* This function looks inside `params` and returns the value of the key corresponding to `paramName`. Returns the provided `defaultValue` if nothing was found.
*
* @example const message = getParam('message', 'Something went wrong... 🤔')
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalcomponentprop#getparam
*/
getParam: (paramName: N, defaultValue?: D) => D extends P[M][N] ? P[M][N] : undefined;
/**
* Optional params object you provided when opening the modal you're in.
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalcomponentprop#params
*/
params?: P[M];
/**
* This function removes all the listeners connected to the modal component you're in.
*
* @example removeAllListeners()
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalcomponentprop#removealllisteners
*/
removeAllListeners: () => void;
/**
* This function allows you to dynamically change the modal options of to the modal component you're in.
*
* @example
*
* useEffect(() => {
* setModalOptions({
* backBehavior: 'clear',
* disableFlingGesture: true,
* })
* }, [])
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalcomponentprop#addlistener
*/
setModalOptions: (modalOptions: ModalOptions) => void;
}
/**
* Interface of the modal stack configuration.
* These settings will let Modalfy know what modals you will be rendering and how.
*
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#config-and-options).
*/
export interface ModalStackConfig {
[key: string]: ComponentType | ModalOptions;
}
/**
* Interface of the modal configuration options.
* These settings will let Modalfy how to render and animate a modal.
*
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#config-and-options).
*/
export interface ModalOptions {
/**
* Animation configuration used to animate a modal in, at the top of the stack.
* It uses Animated.timing() by default, if you want to use another animation type, see `animationIn`.
*
* Note: only `easing` and `duration` are needed.
*
* @default { easing: Easing.inOut(Easing.exp), duration: 450 }
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#animateinconfig).
*/
animateInConfig?: Pick;
/**
* Animation function that receives the `animatedValue` used by the library to animate the modal opening,
* and a `toValue` argument representing the modal position in the stack.
*
* Since Modalfy v3, the function receives a `callback` argument, which _can_ be called when the animation is finished,
* depending on whether or not you'll have a callback in a `openModal()`.
*
* Note: If you just want to use Animated.timing(), check `animateInConfig`.
*
* @default -
* @example
* animationIn: (modalAnimatedValue, modalToValue, callback) => {
* Animated.parallel([
* Animated.timing(modalAnimatedValue, {
* toValue: modalToValue,
* duration: 300,
* easing: Easing.inOut(Easing.exp),
* useNativeDriver: true,
* }),
* Animated.timing(myOtherAnimatedValue, {
* toValue: 1,
* duration: 300,
* easing: Easing.inOut(Easing.exp),
* useNativeDriver: true,
* }),
* ]).start() => callback?.())
* }
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#animationin).
*/
animationIn?: (animatedValue: Animated.Value, toValue: number, callback?: () => void) => Animated.CompositeAnimation | void;
/**
* Animation configuration used to animate a modal out (underneath other modals or when closing the last one).
* Uses Animated.timing(), if you want to use another animation type, use `animationOut`.
*
* Note: only `easing` and `duration` are needed.
*
* @default { easing: Easing.inOut(Easing.exp), duration: 450 }
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#animationout).
*/
animateOutConfig?: Pick;
/**
* Animation function that receives the `animatedValue` used by the library to animate the modal closing,
* and a `toValue` argument representing the modal position in the stack.
*
* Since Modalfy v3, the function receives a `callback` argument, which **_must_** be called when the animation is finished.
*
* Note: If you just want to use Animated.timing(), check `animateOutConfig`.
*
* @default -
* @example
* animationOut: (modalAnimatedValue, modalToValue, callback) => {
* Animated.parallel([
* Animated.timing(modalAnimatedValue, {
* toValue: modalToValue,
* duration: 300,
* easing: Easing.inOut(Easing.exp),
* useNativeDriver: true,
* }),
* Animated.timing(myOtherAnimatedValue, {
* toValue: 1,
* duration: 300,
* easing: Easing.inOut(Easing.exp),
* useNativeDriver: true,
* }),
* ]).start(() => callback())
* }
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#animationout).
*/
animationOut?: (animatedValue: Animated.Value, toValue: number, callback?: () => void) => Animated.CompositeAnimation | void;
/**
* How you want the modal stack to behave when users press the backdrop, but also when the physical back button is pressed on Android.
*
* @default 'pop'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#backbehavior).
*/
backBehavior?: 'clear' | 'pop' | 'none';
/**
* Number that defines how long the backdrop should take to animate in and out.
*
* @default 300
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#backdropanimationduration).
*/
backdropAnimationDuration?: number;
/**
* Color of the modal stack backdrop.
*
* @default 'black'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#backdropcolor).
*/
backdropColor?: ViewStyle['backgroundColor'];
/**
* Number between `0` and `1` that defines the backdrop opacity.
*
* @default 0.6
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#backdropopacity).
*/
backdropOpacity?: number;
/**
* Where in the stack should the backdrop be displayed.
*
* @default 'root'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#backdropposition).
*/
backdropPosition?: 'root' | 'belowLatest';
/**
* Styles applied to the `` directly wrapping your modal component.
*
* @default '{}'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#containerstyle).
*/
containerStyle?: ViewStyle;
/**
* Disable fling gesture detection to close the modal.
*
* Note: the fling gesture handler is not enabled when `position` is `center`.
*
* @default false
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#disableflinggesture).
*/
disableFlingGesture?: boolean;
/**
* React component that will be rendered when you'll open the modal.
*
* Note: only needed when you're using this inside createModalStack() 1st argument.
*
* @default -
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#modal).
*/
modal?: ComponentType;
/**
* Vertical positioning of the modal.
*
* @default 'center'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#position).
*/
position?: 'center' | 'top' | 'bottom';
/**
* Styles applied to the `` directly wrapping the entire modal stack & backdrop.
*
* The styles can be provided as a regular object or as a function (that will receive an `Animated.Value` representing the opacity of the modal stack as sole argument).
*
* Note: the object returned by `stackContainerStyle()` must contain keys that work with `useNativeDriver: true`.
*
* @default '{}'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#stackcontainerstyle).
*/
stackContainerStyle?: ViewStyle | ((opacity: Animated.Value) => ViewStyle);
/**
* `transitionOptions(animatedValue)` returns a React Native style object containing values that can use the provided `animatedValue` to run animation interpolations on a modal.
*
* Note: the object returned by `transitionOptions()` must contain keys that work with `useNativeDriver: true`.
*
* @default -
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#transitionoptions).
*/
transitionOptions?: ModalTransitionOptions;
/**
* How you want any modal to respond to a touch/click.
*
* @default 'auto'
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modaloptions#pointereventsbehavior).
*/
pointerEventsBehavior?: 'auto' | 'none' | 'current-modal-only' | 'current-modal-none';
}
/**
* Interface of the `modal` prop exposed by the library to regular components.
*
* @argument { unknown } ModalStackParamsList? - Interface of the whole modal stack params.
* @argument { unknown } Props? - Component's props interface.
*
* Note: Modal components used in `createModalStack()`'s config should employ `ModalComponentProp` instead.
*
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalprop).
*/
export declare type ModalProp = Props & {
/**
* Interface of the `modal` prop exposed by the library to regular components.
*
* Note: Modal components used in `createModalStack()`'s config should employ `ModalComponentProp` instead.
*
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalprop).
*/
modal: UsableModalProp
;
};
/**
* Interface of the `modal` prop exposed by the library specifically to modal components.
*
* @argument { unknown } ModalStackParamsList? - Interface of the whole modal stack params.
* @argument { unknown } Props? - Component's props interface.
* @argument { string } ModalName? - Name of the current modal
*
* Note: Components that are not used from `createModalStack()`'s config should employ `ModalProp` instead.
*
* @related [`ModalProps`](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalprops).
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalcomponentprop).
*/
export declare type ModalComponentProp
= Props & {
/**
* Interface of the `modal` prop exposed by the library specifically to modal components.
*
* Note:
* * A simplified version of this interface is ModalProps.
* * Components that are not used from `createModalStack()`'s config should employ `ModalProp` instead.
*
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalcomponentprop).
*/
modal: UsableModalComponentProp
;
};
/**
* Interface of the `modal` prop exposed by the library specifically to modal components.
*
* @argument { string } ModalName? - Name of the current modal
* @argument { unknown } Props? - Component's props interface.
*
* Note: Components that are not used from `createModalStack()`'s config should employ `ModalProp` instead.
*
* @related [`ModalComponentProp`](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalcomponentprop).
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalprops).
*/
export declare type ModalProps = ModalComponentProp;
/**
* Interface for a React component containing its props and the `modalOptions` static property.
*
* Note: Only use with Hooks modal components (those present in your `createModalStack()`'s config).
* If you're working with a Class modal component, you can directly use `static modalOptions: ModalOptions`.
*
* @argument { unknown } Props? - Component's props interface.
*
* @see [API reference](https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalcomponentwithoptions).
*/
export declare type ModalComponentWithOptions = ComponentType
& {
modalOptions?: ModalOptions;
};
export {};