Skip to main content

Bottom Sheet

Bottom sheets are surfaces containing supplementary content, anchored to the bottom of the screen. They can provide users with quick access to contextual information, actions, or settings without interrupting their current workflow.

The Bottom Sheet Package is part of FlexNative for React Native, and is available under the @flexnative/bottom-sheet NPM package.

A performant interactive bottom sheet with fully configurable options.

Dependencies

Installation

You can installing FlexNative Bottom Sheet packages using npm:

npm i @flexnative/bottom-sheet

API

import BottomSheet from "@flexnative/bottom-sheet";

Component

BottomSheet

Type: React.PureComponent<BottomSheetProps, BottomSheetStateProps>

Properties

NameTypeRequiredDefault ValueDescription
animationType'none' | 'slide' | 'fade'falsefadeAnimation type when BottomSheet it is open.
heightnumberfalse260BottomSheet height.
minClosingHeightnumberfalse0Min height value to close the BottomSheet when drag down. minClosingHeight has effect only when closeOnDragDown it is true
openDurationnumberfalse300Animation duration on open ButtonSheet.
closeDurationnumberfalse300Animation duration on close ButtonSheet.
closeOnDragDownbooleanfalsefalseBoolean value indicating whether to close or not the BottomSheet on OnDragDown.
closeOnPressMaskbooleanfalsetrueBoolean value indicating whether to close or not the BottomSheet on OnPressMask.
dragFromTopOnlybooleanfalsefalseBoolean value indicating whether to Drag FromTopOnly.
closeOnPressBackbooleanfalsefalseBoolean value indicating whether to close or not the BottomSheet on background overlay.
maskModeBlurTintfalseisDark ? dark : lightA tint mode which will be applied to background overlay.
behaviorheight, padding, positionfalsepaddingbehavior for KeyboardAvoidingView.
keyboardAvoidingViewEnabledbooleanfalseDefault is true of iOSEnables or disables the KeyboardAvoidingView.
onClosefunction of type voidfalseundefinedfunction to call on close event.
onOpenfunction of type voidfalseundefinedfunction to call on onOpen event.
childrenReact.ReactNodetrueundefinedReact.ReactNode to render on BottomSheet.
wrapperStyleStyleProp<ViewStyle>falseundefinedViewStyle to apply on BottomSheet wrapper.
containerStyleStyleProp<ViewStyle>falseundefinedViewStyle to apply on BottomSheet container.
draggableIconStyleStyleProp<ViewStyle>falseundefinedViewStyle to apply on draggable icon.

Usecase Examples

The following example demonstrates the BottomSheet in action.

BottomSheet With action onOpen & onClose

Animation Type

Behavior

CloseOnDragDown

Height

MaskMode

MinClosingHeight

Styles with StyleSheet

Playground

Live Editor

type Props = {
  children?: React.ReactNode;
  close?: () => void;
}

const MockContainer = (props: Props) => (
  <div style={styles.container}>
    <p style={styles.text}>Bottom Sheet mock content</p>
    { props.children ?? props.children }

    <Button text='Close' color='error' onPress={props.close}/>
  </div>
);

const styles = {
  container: {
    backgroundColor: '#f9c2ff',
    padding: 20,
    marginVertical: 8,
    marginHorizontal: 16,
    borderRadius: 4
  },
  text: {
    fontSize: 32,
    paddingVertical: 15,
    color: 'black'
  }
};

const BottomSheetExample = () => {
  const refBottomSheet = React.useRef<BottomSheetModal>(null);
  const open = () => refBottomSheet.current.open();
  const close = () => refBottomSheet?.current?.close();
  const showAlert = (title: string, content: string) => console.log(title, '\n', content);

  console.log('refBottomSheet: ', refBottomSheet)

  return (
    <>
      <Button color='primary' text='Test BottomSheet' onPress={open}/>

      {/*Play with BottomSheet props to see live changes;*/}

      <BottomSheet ref={refBottomSheet}
                  onOpen={() => showAlert('Modal Open', 'Modal is opened.')}
                  onClose={() => showAlert('Modal Closed', 'Modal is closed.')} >
        <MockContainer close={close} />
      </BottomSheet>
    </>
  )
}

render(
  <BottomSheetExample />
);
Result
Loading...