1.23.0 • Published 1 month ago

@shaquillehinds/smooth-modal v1.23.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

A Simple React Native Bottom Sheet That Just Works.

Works The Same On IOS & Android

P.S There are other components in this package such as:

  • SmoothBottomModal
  • SmoothBottomSheet
  • SmoothBottomFlatlist
  • SmoothBottomScrollView
  • SmoothNotificationProvider
  • useSmoothNotification

The documentation here only covers SmoothBottomModal and SmoothBottomSheet.

SmoothBottomModal & SmoothBottomSheet Documentation

The SmoothBottomModal & SmoothBottomSheet is a customizable, flexible bottom sheet component for React Native, supporting keyboard avoidance, drag behavior, and more.

UnlikeSmoothBottomModal,SmoothBottomSheet doesn't have a backdrop component, can optionally stay mounted when "close" is called and it can't use React Native's default Modal for rendering a new root view overlay.


Required Peer Dependencies

"react-native-gesture-handler": ">=2.7.0",
"react-native-reanimated": ">=3.0.0"

Installation

NPM

npm install @shaquillehinds/smooth-modal

Yarn

yarn add @shaquillehinds/smooth-modal

Basic Usage

import { SmoothBottomModal } from '@shaquillehinds/smooth-modal';
const [showModal, setShowModal] = useState(false);

<SmoothBottomModal showModal={showModal} setShowModal={setShowModal}>
  {/* Modal Content */}
</SmoothBottomModal>;

OR

const ref = useRef<BottomSheetModalController>(null);

<SmoothBottomModal ref={ref}>{/* Modal Content */}</SmoothBottomModal>;

Props

Core Props

Use Either ref or showModal, avoid using both as it can lead to unpredictable behavoir.
PropTypeDescription
refReact.Ref<BottomSheetModalController>Controls the modal's open, close and snap movements.
showModalbooleanControls whether the modal is visible.
setShowModalReact.Dispatch<React.SetStateAction<boolean>>Function to update the visibility of the modal.

Drag Behavior

PropTypeDescription
snapPoints(string\|number)[]Defines points based on a percentage of the screen's height that the modal can snap to. Example [25, "50", "75%"]
dragArea'full' \| 'bumper' \| 'none'Defines which part of the modal is draggable. Default: "bumper"
allowDragWhileKeyboardVisiblebooleanAllow dragging the modal even when the keyboard is visible. By default, dragging is disabled while the keyboard is open.
hideBumperbooleanHides the default bumper (drag handle) from the modal.
BumperComponent() => React.ReactNodeProvide a custom draggable bumper component, replacing the default bumper.

Keyboard Handling

PropTypeDescription
avoidKeyboardbooleanAutomatically adds bottom padding to prevent the keyboard from overlapping content.
inputsForKeyboardToAvoidReact.RefObject<TextInput>[]Specify input refs to selectively trigger keyboard avoidance padding when focused.

Mounting Behavior

PropTypeDescription
keepMounted (SmoothBottomSheet Only)booleanPrevents the modal from fully unmounting when closed. Useful with bottomOffset to keep the modal slightly visible when closed.
bottomOffsetnumberPushes the modal slightly up from the bottom when closed. Works best with keepMounted.
onModalShow() => Promise<void> \| voidFunction to run when the modal is shown (mounted).
onModalClose() => Promise<void> \| voidFunction to run when the modal is closed (unmounted).
disableAndroidBackButtonbooleanOnly valid when using 'useNativeModal' prop. Stops modal from closing when the hardware back button is pressed on android.

Overlay Behavior

PropTypeDescription
enableBackgroundContentPressbooleanIf true and there's no backdrop component, the background content that's below the modal will be touchable. Is always true on SmoothBottomSheet.
useNativeModal (SmoothBottomModal Only)booleanIf true, uses React Native's default modal to render a new root view to render them modal. Useful if you need the modal to be absolute on top of navigation and other content.

Content Delay

PropTypeDescription
showContentDelay{ type?: 'mount' \| 'opacity'; timeInMilliSecs: number }Delay content rendering for performance optimization. - "opacity": Delays showing the content with opacity transition. (Default) - "mount": Mounts the content after a delay.
When using type: "mount", set an explicit height or minHeight in contentContainerStyle to avoid layout shifts.

Styling

PropTypeDescription
styleStyleProp<ViewStyle>Styles the modal sheet itself.
contentContainerStyleStyleProp<ViewStyle>Styles the modal’s internal content container.
bumperStyleStyleProp<ViewStyle>Styles the bumper (drag handle) itself.
bumperContainerStyleStyleProp<ViewStyle>Styles the container around the bumper.
backgroundColorstringSets the background color of the modal and bumper container.

Backdrop (SmoothBottomModal Only)

PropTypeDescription
BackdropComponentReact.ReactNodeProvide a custom backdrop component instead of the default BlurView.
disableCloseOnBackdropPressbooleanIf true, tapping on the backdrop will not close the modal.
blurBackdrop'ios' \| 'android' \| trueUses expo blur view as the modal backdrop to blur content underneath the modal.
disableBlurWarningbooleanDisables the Android warning for using blur view.

Tips

  • Use keepMounted + bottomOffset on SmoothBottomSheet if you want the modal to stay slightly "peeking" when not fully open. This won't work on SmoothBottomModal only SmoothBottomSheet.
  • Set a minHeight on the contentContainerStyle if using showContentDelay.type: 'mount' to avoid abrupt height changes.
  • Use inputsForKeyboardToAvoid for finer control of when padding should be added for the keyboard.
  • Provide a custom BackdropComponent if you want to personalize the modal background or add animations.

Examples

Modal with Keyboard Avoidance

const [showModal, setShowModal] = useState(false);
const inputRef = useRef<TextInput>(null);

<SmoothBottomModal
  showModal={showModal}
  setShowModal={setShowModal}
  avoidKeyboard
  inputsForKeyboardToAvoid={[inputRef]}
>
  <TextInput ref={inputRef} placeholder="Type here" />
</SmoothBottomModal>;

Draggable Modal With ScrollView Or Flatlist

If you need the modal to be draggable when scrollable content is at the beginning (scroll offset at 0).

import {
  SmoothBottomModal,
  SmoothBottomScrollView,
} from '@shaquillehinds/smooth-modal';
const [showModal, setShowModal] = useState(false);

<SmoothBottomModal showModal={showModal} setShowModal={setShowModal}>
  <SmoothBottomScrollView>{/* ScrollView Content */}</SmoothBottomScrollView>
</SmoothBottomModal>;
1.23.0

1 month ago

1.22.3

2 months ago

1.22.2

2 months ago

1.22.1

2 months ago

1.22.0

2 months ago

1.21.0

2 months ago

1.20.1

2 months ago

1.20.0

2 months ago

1.19.0

2 months ago

1.18.0

2 months ago

1.17.2

2 months ago

1.17.1

2 months ago

1.17.0

2 months ago

1.16.2

2 months ago

1.16.1

2 months ago

1.16.0

2 months ago

1.15.5

3 months ago

1.15.4

3 months ago

1.15.3

3 months ago

1.15.2

3 months ago

1.15.1

3 months ago

1.15.0

3 months ago

1.14.0

3 months ago

1.13.2

3 months ago

1.13.1

3 months ago

1.13.0

3 months ago

1.12.3

3 months ago

1.12.2

3 months ago

1.12.1

3 months ago

1.12.0

3 months ago

1.11.6

3 months ago

1.11.5

3 months ago

1.11.4

3 months ago

1.11.3

3 months ago

1.11.2

3 months ago

1.11.1

3 months ago

1.11.0

3 months ago

1.10.0

3 months ago

1.9.0

3 months ago

1.8.1

3 months ago

1.8.0

3 months ago

1.7.0

3 months ago

1.6.9

3 months ago

1.6.8

4 months ago

1.6.7

4 months ago

1.6.6

4 months ago

1.6.5

4 months ago

1.6.4

4 months ago

1.6.3

4 months ago

1.6.2

4 months ago

1.6.1

4 months ago

1.6.0

4 months ago

1.5.2

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.4.0

4 months ago

1.3.4

4 months ago

1.3.3

4 months ago

1.3.2

4 months ago

1.3.1

4 months ago

1.3.0

4 months ago

1.2.0

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.0

4 months ago

0.1.7

4 months ago

0.1.6

4 months ago

0.1.5

4 months ago

0.1.4

4 months ago

0.1.3

4 months ago

0.1.1

4 months ago