import type { ComponentType } from 'react' import type { Animated, StyleProp, ViewStyle } from 'react-native' /* ======================== ======================== * * ======================== INTERNAL TYPES ======================== * * ======================== ======================== */ export type ModalfyParams = { [key: string]: any } 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 ModalOnCloseEventCallback = (closingAction: { type: ModalClosingActionName origin: ModalClosingActionOrigin }) => void export type ModalClosingActionName = 'closeModal' | 'closeModals' | 'closeAllModals' export type ModalClosingActionOrigin = 'default' | 'fling' | 'backdrop' 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 ModalStackItem
{
name: Exclude {
names: Array []
defaultOptions: ModalOptions
openedItems: Set , callback?: () => void) => void
closeModals: (modalName: M, callback?: () => void) => boolean
getParam: ['hash'],
paramName: N,
defaultValue?: D,
) => D extends P[M][N] ? P[M][N] : undefined
openModal:
}
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 extends ModalContextProvider {
clearListeners: (hash: string) => void
eventListeners: ModalEventListeners
registerListener: (
hash: ModalStackItem ['hash'],
eventName: ModalEventName,
handler: ModalEventCallback,
) => ModalEventListener
removeClosingAction: ModalState ['removeClosingAction']
rootStyle?: StyleProp = Pick<
ModalContextProvider ,
'closeAllModals' | 'closeModals' | 'currentModal' | 'openModal'
> & {
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 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.
*
* @see 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: Components that are not used from `createModalStack()`'s config should employ `ModalProp` instead.
*
* @see https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalcomponentprop
*/
modal: UsableModalComponentProp
}
/**
* 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 https://colorfy-software.gitbook.io/react-native-modalfy/guides/typing#modalcomponentwithoptions
*/
export type ModalComponentWithOptions = ComponentType & {
modalOptions?: ModalOptions
}