1.2.0 • Published 4 months ago

react-native-animated-accordion v1.2.0

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

react-native-animated-accordion

Animated accordion and collapsible using react-native-reanimated

Supports dynamic content heights and components.

Demo

https://user-images.githubusercontent.com/50287765/187772673-45f73f77-1bd4-4317-827b-4c6e449e5e6b.mp4

Installation

Using npm

npm install --save react-native-animated-accordion react-native-reanimated react-native-svg

Using yarn

yarn add react-native-animated-accordion react-native-reanimated react-native-svg

Before using the package setup packages on your project

For react-native-reanimated follow this documentation

Usage

import { Accordion } from 'react-native-animated-accordion';

<Accordion headerText="Light Theme">
  <View style={{ padding: 10 }}>
    <Text style={{ color: '#000000' }}>Accordion</Text>
  </View>
</Accordion>;

Properties

PropDescriptionDefault
isOpenif you want to control the collapsed state yourselfnull
headerTextName of header""
parentContainerStylesStyles for main container of accordiondefault styles
bodyContainerStylesStyles for content body of accordiondefault styles
headerStylesStyles for header of accordiondefault styles
headerTextStylesStyles for header text of accordiondefault styles
headerIconStylesStyles for header arrow icon of accordiondefault styles
headerIconColorIcon color of header#000000
headerIconSizeIcon size of header20
onPressFunction triggered when user clicks on headernull
durationDuration of animation in milliseconds300

Accordion Usage Examples

This is a convenience component for a common use case, see below.

import React, { useState } from 'react';
import { View, Text, StyleSheet, ScrollView } from 'react-native';
import { Accordion } from 'react-native-animated-accordion';

const App = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <ScrollView contentContainerStyle={styles.mainContainer}>
      <Text style={{ color: '#000000', marginVertical: 20 }}>Light Theme</Text>
      <Accordion headerText="Light Theme">
        <View style={{ padding: 10 }}>
          <Text style={{ color: '#000000' }}>Light Theme</Text>
          <Text style={{ color: '#000000' }}>Light Theme</Text>
          <Text style={{ color: '#000000' }}>Light Theme</Text>
          <Text style={{ color: '#000000' }}>Light Theme</Text>
          <Text style={{ color: '#000000' }}>Light Theme</Text>
        </View>
      </Accordion>

      <Text style={{ color: '#000000', marginVertical: 20 }}>Dark Theme</Text>
      <Accordion
        bodyStyles={{
          backgroundColor: 'black',
        }}
        headerText="Dark Theme"
        headerStyles={{ paddingVertical: 15, backgroundColor: '#000000' }}
        headerTextStyles={{ color: '#ffffff' }}
        headerIconStyles={{ fontSize: 15, color: '#ffffff' }}
      >
        <View style={{ padding: 10 }}>
          <Text style={{ color: '#ffffff' }}>Dark Theme</Text>
          <Text style={{ color: '#ffffff' }}>Dark Theme</Text>
          <Text style={{ color: '#ffffff' }}>Dark Theme</Text>
          <Text style={{ color: '#ffffff' }}>Dark Theme</Text>
          <Text style={{ color: '#ffffff' }}>Dark Theme</Text>
        </View>
      </Accordion>

      <Text style={{ color: '#000000', marginVertical: 20 }}>Props Intro</Text>
      <Accordion
        parentContainerStyles={{
          marginTop: 20,
        }}
        bodyStyles={{
          backgroundColor: 'yellow',
        }}
        headerText="Header"
        headerStyles={{ paddingVertical: 20 }}
        headerTextStyles={{ fontStyle: 'italic' }}
        headerIconStyles={{ fontSize: 15 }}
        isOpen={isOpen}
        onPress={() => setIsOpen(!isOpen)}
      >
        <View style={{ padding: 10 }}>
          <Text style={{ color: '#000000' }}>Header</Text>
          <Text style={{ color: '#000000' }}>Header</Text>
          <Text style={{ color: '#000000' }}>Header</Text>
          <Text style={{ color: '#000000' }}>Header</Text>
          <Text style={{ color: '#000000' }}>Header</Text>
        </View>
      </Accordion>
    </ScrollView>
  );
};

const styles = StyleSheet.create({
  mainContainer: {
    backgroundColor: '#ffffff',
    padding: 20,
    flexGrow: 1,
  },
});

export default App;

Maintainers

License

MIT License. © Waseem Munir