From 7684f8d4cefa679aec04b5097acf7b36692623f6 Mon Sep 17 00:00:00 2001 From: Jordan Hayashi Date: Wed, 10 Aug 2022 05:26:42 -0400 Subject: [PATCH] feat: export useModalize from the root of the library (#441) --- docs/HOOKS.md | 18 +++++++++++++++--- src/index.tsx | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/HOOKS.md b/docs/HOOKS.md index 7afd159c..af35cb03 100644 --- a/docs/HOOKS.md +++ b/docs/HOOKS.md @@ -1,10 +1,22 @@ # Available hooks -There is a hook available to quickly access Modalize. +There is a hook available to quickly access Modalize. It returns an object with +three keys: + +- `ref`: a ref object to pass to the `Modalize` component +- `open`: a function that opens the `Modalize` component. If you are using + `snapPoint` prop, you can supply a `dest` argument to the `open` + function, to open it to the top directly `open('top')`. You don't have + to provide anything if you want the default behavior. +- `close`: a function that closes the `Modalize` component. You don't need to call + it to dismiss the modal, since you can swipe down to dismiss. + If you are using `alwaysOpen` prop, you can supply a `dest` argument + to the `close` function to reset it to the initial position + `close('alwaysOpen')`, and avoiding to close it completely. ```tsx -import React, { useRef } from 'react'; -import { Modalize } from 'react-native-modalize'; +import React from 'react'; +import { Modalize, useModalize } from 'react-native-modalize'; export const App = () => { const { ref, open, close } = useModalize(); diff --git a/src/index.tsx b/src/index.tsx index 62eaa830..d478d413 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -37,6 +37,7 @@ import { import { IProps, TOpen, TClose, TStyle, IHandles, TPosition } from './options'; import { useDimensions } from './utils/use-dimensions'; +import { useModalize } from './utils/use-modalize'; import { getSpringConfig } from './utils/get-spring-config'; import { isIphoneX, isIos, isAndroid } from './utils/devices'; import { isBelowRN65, isRNGH2 } from './utils/libraries'; @@ -1000,4 +1001,5 @@ const ModalizeBase = ( export type ModalizeProps = IProps; export type Modalize = IHandles; -export const Modalize = React.forwardRef(ModalizeBase); +const Modalize = React.forwardRef(ModalizeBase); +export { Modalize, useModalize };