GithubHelp home page GithubHelp logo

ilz5753 / react-native-swipe-picker Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.63 MB

`react-native-swipe-picker` is a useful library for creating a modern and user-friendly inline picker component in your React Native applications.

License: MIT License

JavaScript 1.10% Ruby 25.91% TypeScript 72.99%

react-native-swipe-picker's Introduction

react-native-swipe-picker

@ilz5753/react-native-swipe-picker is a React Native library that provides an inline picker component with a swipe-to-select-an-item interaction. It is similar to the input mechanism used in apps like SHealth, where users can swipe left or right to select a value from a list of options. This library allows you to create a user-friendly and intuitive picker component for your React Native applications, making it easier for users to input data or make selections without the need for traditional dropdown menus or modal pickers.

Demo

Screen_Recording_20240222_113538_SwipePickerExample.mp4

Note

The @ilz5753/react-native-swipe-picker package relies on react-native-reanimated and react-native-gesture-handler to provide smooth animations and gestures. These dependencies must be installed and properly configured in your React Native project for the swipe picker component to function correctly.

Installation

npm install @ilz5753/react-native-swipe-picker
# yarn
yarn add @ilz5753/react-native-swipe-picker
# bun
bun add @ilz5753/react-native-swipe-picker

Usage

import SwipePicker, {
  type ISwipePickerId,
  type ISwipePickerItem,
} from "@ilz5753/react-native-swipe-picker";

//

const itemHeight = 90;

interface Account extends ISwipePickerId {
  fullName: string;
  address: string;
  uri: string;
}

const JennieNichols: Account = {
  id: "0",
  fullName: "Jennie Nichols",
  address: "Valwood Pkwy",
  uri: "https://randomuser.me/api/portraits/women/1.jpg",
};

const accounts: Account[] = [JennieNichols];

function RenderAccount({ item, itemHeight }: ISwipePickerItem<Account>) {
  let imgSize = useMemo(() => itemHeight * 0.75, [itemHeight]);
  return (
    <View
      style={[
        styles.fdr,
        styles.aic,
        styles.jcsb,
        styles.ph8,
        { height: itemHeight },
      ]}
    >
      <View style={[styles.fdr, styles.aic, styles.gap8]}>
        <Image
          style={[
            { width: imgSize, height: imgSize, borderRadius: imgSize / 2 },
          ]}
          source={{ uri: item.uri }}
        />
        <View style={[styles.gap8]}>
          <Text>{item.fullName}</Text>
          <Text>{item.address}</Text>
        </View>
      </View>
    </View>
  );
}

export default function Example() {
  const [activeAccount, setActiveAccount] = useState(JennieNichols);
  let onSelectItem = useCallback((acc: Account) => setActiveAccount(acc), []);
  return (
    <View style={[styles.f1, styles.aic, styles.jcc, styles.gap8]}>
      <SwipePicker
        {...{
          items: accounts,
          renderItem: RenderAccount,
          itemHeight,
          onSelectItem,
        }}
      />
      {activeAccount && (
        <Animated.View
          entering={FadeInUp}
          exiting={FadeOutUp}
          layout={LinearTransition}
        >
          <RenderAccount
            {...{
              item: activeAccount,
              itemHeight,
              index: 0,
            }}
          />
        </Animated.View>
      )}
    </View>
  );
}

Features

The @ilz5753/react-native-swipe-picker library offers several features to help you create a customizable and accessible inline picker component for your React Native applications:

  1. Swipe-to-select interaction: Users can easily swipe left or right to select a value from a list of options, providing a more intuitive and engaging experience compared to traditional dropdown menus or modal pickers.
  2. Customizable appearance: You can customize various aspects of the picker component, such as the text color, background color, font size, and item padding. This allows you to match the component's appearance to your app's theme and branding.
  3. Lightweight and performant: The component is lightweight and designed to have minimal impact on the performance of your React Native applications, ensuring a smooth and responsive user experience.
  4. Cross-platform support: The library works well on both iOS and Android platforms, enabling you to create consistent user experiences across different devices and operating systems.

License

This project Licensed under the MIT License.


Made with create-react-native-library

react-native-swipe-picker's People

Contributors

ilz5753 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.