import type { ComponentType } from 'react' import type { Animated, ViewStyle } from 'react-native' /* ======================== ======================== * * ======================== INTERNAL TYPES ======================== * * ======================== ======================== */ // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ModalfyCustomParams {} type ModalfyExtendedParams = ModalfyCustomParams[keyof ModalfyCustomParams] extends never ? { [key: string]: any } : ModalfyCustomParams // It should be declared as interface to prevent typescript type replacement // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ModalfyParams extends ModalfyExtendedParams {} export type ModalTransitionValue = Animated.AnimatedInterpolation | string | number | undefined | null export type ModalTransitionOptions = (animatedValue: Animated.Value) => { [key: string]: | { [key: string]: ModalTransitionValue }[] | ModalTransitionValue } export type ModalListener = (eventName: ModalEventName, callback: ModalEventCallback) => ModalEventListener export type ModalEventListeners = Set<{ event: string handler: ModalEventCallback }> export type ModalEventName = 'onAnimate' | 'onClose' export type ModalOnAnimateEventCallback = (value?: number) => void export type ModalClosingAction = { type: ModalClosingActionName origin: ModalClosingActionOrigin } export type ModalClosingActionOrigin = 'default' | 'fling' | 'backdrop' export type ModalClosingActionName = 'closeModal' | 'closeModals' | 'closeAllModals' export type ModalOnCloseEventCallback = (closingAction: ModalClosingAction) => void export type ModalEventCallback = ModalOnAnimateEventCallback | ModalOnCloseEventCallback export type ModalEventListener = { remove: () => boolean } export type ModalEventAction = 'add' export type ModalEventPayload = { eventName: ModalEventName handler: ModalEventCallback } export type ModalStatePendingClosingAction = | { modalName?: string action: 'closeModal' callback?: () => void } | { modalName: string action: 'closeModals' callback?: () => void } | { modalName?: never action: 'closeAllModals' callback?: () => void } export type ModalPendingClosingAction = | { hash: string currentModalHash?: string modalName?: string action: 'closeModal' callback?: () => void } | { hash: string currentModalHash?: string modalName: string action: 'closeModals' callback?: () => void } | { hash: string modalName: never currentModalHash?: string action: 'closeAllModals' callback?: () => void } export interface ModalStack
{
names: Array []
defaultOptions: ModalOptions
openedItems: Set = Record {
name: Exclude , callback?: () => void) => void
/**
* This function closes all the instances of a given modal.
*
* You can use it whenever you have the same modal opened
* several times, to close all of them at once.
*
* @example modal.closeModals('ExampleModal', () => console.log('All ExampleModal modals closed'))
*
* @returns { boolean } Whether or not Modalfy found any open modal
* corresponding to `modalName` (and then closed them).
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/api/types/modalprop#closemodals
*
* @note We're using modalfy.closeModals instead of ModalState.closeModals so that the animations
* can be triggered appropriately from the synced custom internal state.
*/
closeModals: (modalName: M, callback?: () => void) => boolean
/**
* 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: ['hash'],
paramName: N,
defaultValue?: D,
) => D extends P[M][N] ? P[M][N] : undefined
/**
* This function opens a modal based on the provided `modalName`.
*
* It will look at the stack passed to `
}
export 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 type ModalStateListener = (state: ModalInternalState | null, error?: Error) => void
export type ModalStateEqualityChecker = (
currentState: ModalInternalState ,
newState: ModalInternalState ,
) => boolean
export type ModalState = Omit<
ModalContextProvider ,
'currentModal' | 'stack' | 'openModal'
> & {
openModal: extends ModalContextProvider {
clearListeners: (hash: string) => void
eventListeners: ModalEventListeners
registerListener: (
hash: ModalStackItem ['hash'],
eventName: ModalEventName,
handler: ModalEventCallback,
) => ModalEventListener
removeClosingAction: ModalState ['removeClosingAction']
}
export type UsableModalProp = Pick<
ModalContextProvider ,
'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
extends Omit = 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 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 type ModalProps = ComponentType & {
modalOptions?: ModalOptions
}