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

react-native-fast-collapsible

v1.1.2

Published

Pure Javascript library for React Native with super-fast collapsible component using Reanimated v3 API.

Downloads

602

Readme

Title

Pure Javascript library for React Native with super-fast collapsible component using Reanimated API. It works with Expo.

  • 🎙️ Works with Expo
  • 🪽 Easy usage
  • ⚠️ react-native-reanimated required

Motivation

There are currently many libraries available for Collapsible components, but they are either no longer supported or do not implement the latest innovations in the React Native architecture. Hence the need for a library that works with the new architecture based on the React Native Reanimated API V3 and allow to have always native performance.

Installation

yarn install react-native-fast-collapsible

This library has a peer dependency on react-native-reanimated has to be installed, linked and configured into your project. Follow react-native-reanimated to install the dependency.

Usage / API

Collapsible component

A simple component that enables an animated action to hide and show content.

https://github.com/user-attachments/assets/e74700c5-d1b9-4559-9b9b-940bd02d684f

Example

import React, { useState } from 'react';

import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { Collapsible } from 'react-native-fast-collapsible';

export default function SimpleCollapsible() {
  const [isVisible, setVisibility] = useState(false);

  const toggleVisibility = () => {
    setVisibility((previous) => !previous);
  };

  return (
    <View style={styles.container}>
      <TouchableOpacity onPress={toggleVisibility}>
        <Text>Expand / Collapse</Text>
      </TouchableOpacity>

      <Collapsible isVisible={isVisible}>
        <Text>Lorem ipsum....</Text>
      </Collapsible>
    </View>
  );
}

Properties

| Property | Type | Description | Default | | ------------------ | ----------- | ------------------------------------------- | --------------- | | isVisible | boolean | Whether to show the child components or not | top | | heightOffset | number | Offset of collapsed children visible | 0 | | duration | number | Time in ms of animation | 300 | | easing | Easing | Type of animation from Reanimated | Easing.linear | | children | ReactNode | Children to show or hide | – |

useCollapsible hook

Headless hook to create your own collapsible components.

https://github.com/user-attachments/assets/aef8cf7a-bbb0-4d1d-96ea-452e3e3be2f2

Example

import React, { useState } from 'react';

import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useCollapsible } from 'react-native-fast-collapsible';
import Animated, {
  Easing,
  interpolate,
  useAnimatedStyle,
} from 'react-native-reanimated';

export default function HeadlessCollapsible() {
  const [isVisible, setVisibility] = useState(false);

  const { animatedStyles, onLayout, height, maxHeight } = useCollapsible({
    isVisible,
    easing: Easing.bounce,
    duration: 1000,
  });

  const toggleVisibility = () => {
    setVisibility((previous) => !previous);
  };

  const arrowStyles = useAnimatedStyle(() => {
    const degree = interpolate(height.value, [0, maxHeight], [0, 180]);

    return {
      transform: [{ rotate: `${degree}deg` }],
    };
  });

  return (
    <View style={styles.container}>
      <TouchableOpacity
        onPress={toggleVisibility}
        style={styles.buttonContainer}
      >
        <Text>Expand / Collapse</Text>
        <Animated.Text style={arrowStyles}>↓</Animated.Text>
      </TouchableOpacity>

      <Animated.View
        style={[animatedStyles, styles.overflowHidden]}
        pointerEvents={isVisible ? 'auto' : 'none'}
      >
        <View onLayout={onLayout} style={styles.collapsibleContainer}>
          <Text>Lorem ipsum...</Text>
        </View>
      </Animated.View>
    </View>
  );
}

Config object options

| Property | Type | Description | Default | | ------------------ | --------- | ------------------------------------------- | --------------- | | isVisible | boolean | Whether to show the child components or not | top | | heightOffset | number | Offset of collapsed children visible | 0 | | duration | number | Time in ms of animation | 300 | | easing | Easing | Type of animation from Reanimated | Easing.linear |

Hook returned object

| Property | Type | Description | | -------------------- | ------------------------------------ | ---------------------------------------------- | | onLayout | (event: LayoutChangeEvent) => void | Function need to be used on children container | | height | SharedValue<number> | Reanimated shared value with current height | | animatedStyles | number | Styles of children container | | maxHeight | number | Children max height |

Contributing

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

License

MIT © 2023-2024 Lukasz Kurant