npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dooboo-ui/snackbar

v0.0.1

Published

> Simple snackbar for react-native.

Downloads

3

Readme

Snackbar

Simple snackbar for react-native.

Installation

At this point, this component has not yet been published, and after it has been published, it may be installed with the command below.

yarn add @dooboo-ui

or

yarn add @dooboo-ui/snackbar

Usage

Types

export enum Timer {
  SHORT = 1500,
  LONG = 3000,
}

export interface SnackbarProps {
  testID?: string;
  ref: React.MutableRefObject<SnackbarRef>;
}

export interface SnackbarRef {
  show(content: Content): void;
}

export interface Content {
  text: string;
  actionText?: string;
  timer?: Timer;
  actionStyle?: TextStyle;
  containerStyle?: ViewStyle;
  messageStyle?: TextStyle;
  onPressAction?: () => void;
}
  • SnackbarProps

| | necessary | types | default | info | | ------- | :-------: | ----------------------- | --------- | ------------ | | ref | v | MutableRefObject | undefined | | | testID | | string | undefined | |

  • Content

An object of this type is needed to show an Snackbar.

| | necessary | types | default | info | | -------------- | :-------: | ---------------- | ------------------ | ------------------ | | text | v | string | undefined | | | timer | | number | 1500 (Timer.SHORT) | Closing time | | messageStyle | | TextStyle | undefined | Message text style | | containerStyle | | ViewStyle | undefined | | | actionText | | string | undefined | | | actionStyle | | TextStyle | undefined | Action text style | | onPressAction | | function | undefined | |

Getting started

  • Import

    import Snackbar from '@dooboo-ui/snackbar';
  • Using Component

    
    function Container(): React.ReactElement {
      const snackbar = useRef<SnackbarRef>(null);
      const onPress = (): void => {
        snackbar.current && snackbar.current.show({
          text: 'Simple Snackbar is opened',
        });
      };
      return (
        <SafeAreaView style={{ flex: 1 }}>
          <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            <TouchableOpacity onPress={onPress} style={{ borderWidth: 1, padding: 10 }}>
              <Text>Show Snackbar</Text>
            </TouchableOpacity>
            <Snackbar ref={snackbar}/>
          </View>
        </SafeAreaView>
      );
    }
    

To show a Snackbar component, just provide ref props to the component and call the show function (with a Content type parameter) of it. This component will appear at the bottom of the parent view, not at the bottom of the screen.

Feb-25-2020 00-12-07

  • Using Provider

You can also set SnackbarProvider to use Snackbar component.

  function Container(): React.ReactElement {
    const snackbar = useSnackbarContext();
    const onPress = (): void => {
      snackbar.show({
        text: 'Simple Snackbar is opened',
      });
    };
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <TouchableOpacity onPress={onPress} style={{ borderWidth: 1, padding: 10 }}>
          <Text>Show Snackbar</Text>
        </TouchableOpacity>
      </View>
    );
  }

  function Provider(): React.ReactElement {
    return (
      <SnackbarProvider>
        <Container/>
      </SnackbarProvider>
    );
  }

For versions after iPhone x, Snackbar will overlap with the gesture bar. Previously, Snackbar was put in SafeAreaView, but this could be a problem and changed to use View. We recommend that using 'defaultContent' like below.

  function Provider(): React.ReactElement {
    return (
      <SnackbarProvider
        defaultContent={{ containerStyle: { bottom: safeAreaBottom + 10 }}}
      >
        <Container/>
      </SnackbarProvider>
    );
  }
  • Using some Action

To add some action to the Snackbar, just add options about the action to the show function.

    snackbar.show({
      text: 'Simple Snackbar is opened',
      actionText: 'Some action',
      onPressAction: () => Alert.alert('Some action occurs!!'),
    });

Feb-25-2020 00-16-47

  • More Complex Examples

You can find more complex usages on this storybook codes.