1.0.3 • Published 11 months ago

react-native-simple-sheet v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

react-native-simple-sheet

Simple & Customizable Bottom Sheet for React Native. This library is suitable for one-time action.

Preview

simple sheet

Features

  • Gesture control
  • Style customizable
  • Keyboard Avoiding Sheet

Installation

This library needs react-native-reanimated and react-native-gesture-handler.

Yarn

yarn add react-native-reanimated react-native-gesture-handler react-native-simple-sheet

Expo

npx expo install react-native-reanimated react-native-gesture-handler react-native-simple-sheet

Must be

  • Wrap your App with GestureHandlerRootView
  • Wrap your App with SimpleSheetProvider
export default function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <SimpleSheetProvider>
        <MyScreen />
      </SimpleSheetProvider>
    </GestureHandlerRootView>
  );
}

Usage

Basic

export default function MyScreen() {
  const sheet = useSimpleSheet();

  return (
    <Button
      title="Open Sheet"
      onPress={() =>
        sheet.open((props) => (
          <SimpleSheet {...props}>
            <View>...</View>
          </SimpleSheet>
        ))
      }
    />
  );
}

Async action

type Result = 'CONFIRM' | 'CANCEL' | 'DISMISS';

export default function MyScreen() {
  const sheet = useSimpleSheet();

  const openSelectSheet = (): Promise<Result> => {
    return await Promise<Result>(resolve => {
      sheet.open(props => (
        <MySheet
          {...props}
          onDismiss={() => props.close(() => resolve('DISMISS'))}
          onConfirm={() => props.close(() => resolve('CONFIRM'))}
          onCancel={() => {
            // Same with props.close(() => resolve('CANCEL'))
            props.close();
            resolve('CANCEL');
          }}
        />
      ));
    });
  }

  return (
    <Button
      title="Open Sheet"
      onPress={async () => {
        const result = await openSelectSheet();
        console.log(result); // CONFIRM | CANCEL | DISMISS
      }}
    />
  );
}

Parameters

nametyperequireddescriptiondefault
visiblebooleanOdetermines whether the bottom sheet is visible. The animation operates based on the visible value.-
closefunctionOtriggers the animation to close the bottom sheet.-
unmountfunctionOunmounts the bottom sheet from the root. It is typically called after the close animation finished.-
onDismissfunctionXcalled when the sheet is dismissed via a gesture or a scrim touch.-
dismissiblebooleanXdismiss when scrim tappedtrue
gestureEnablebooleanXdetermines whether the sheet will be animate when swipe gesture.true
avoidKeyboardbooleanXdetermines whether the bottom sheet will also move up when the keyboard is shown.true
sheetColorstringXcolor of bottom sheet.#FFFFFF
borderTopLeftRadiusnumberX-12
borderTopRightRadiusnumberX-12
maxHeightnumberXmax height of sheetscreen height * 0.8
scrimColorstringXcolor of scrim (backdrop)#11111188

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

1.0.3

11 months ago

0.7.2

1 year ago

0.7.1

1 year ago

0.6.2

1 year ago

0.7.0

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago