2.0.4 • Published 3 years ago

@dev-event/react-native-accordion v2.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Thanks

Table of Contents

Installation

$ yarn add @dev-event/react-native-accordion

Features

  • Supported Reanimated 2;
  • Fully supported on React Native and Expo;
  • Simple API but fully customizable;
  • Arrow animation indicating whether the collapsible is expanded or not;
  • Property which unmount the collapsible when it is not expanded(very useful for performance! use wisely(Beta);

Usage

For more complete example open App.tsx

import React, { useState, useRef, useCallback } from "react";
import { StyleSheet, View, Text,  StatusBar} from "react-native";
import AnimatedAccordion from "@dev-event/react-native-accordion";


const App: React.FC = () => {
  const accordionRef = useRef<AnimatedAccordion>(null);

  const [show, setShow] = useState<boolean>(false);

  const handleContentTouchable = useCallback(() => {
    return <Text style={styles.title}>Sample header</Text>
  }, [])

  const handleContent = useCallback(() => {
    return <Text style={styles.message}>Sample content</Text>
  }, [])

  const handleOpenAccordion = useCallback(() => {
    accordionRef.current?.openAccordion();
  }, []);

  return (
    <>
      <StatusBar barStyle="dark-content" />
      <View style={styles.content}>
          <TouchableOpacity style={styles.button} onPress={handleOpenAccordion}>
            <Text>Open Accordion</Text>
          </TouchableOpacity>
          <AnimatedAccordion
            ref={accordionRef}
            sizeIcon={16}
            styleChevron={styles.icon}
            renderContent={handleContent}
            onChangeState={(isShow) => setShow(isShow)}
            styleTouchable={styles.touchable}
            activeBackgroundIcon={theme.light_gray}
            inactiveBackgroundIcon={theme.light_gray}
            handleContentTouchable={handleContentTouchable}
          />
      </View>
    </>
  );
};


const styles = StyleSheet.create({
  content:{
    flex: 1,
    backgroundColor: "#FFFFFF"
  },
  touchable: {
    backgroundColor: '#181829',
    height: 50,
  },
  title: {
    fontSize: 14,
    color: '#FFFFFF',
    fontWeight: '500',
  },
  message: {
    fontSize: 16,
    color: '#FFFFFF',
    fontWeight: '500',
  },
  icon: {
    height: 24,
    width: 24,
  },
  button: {
    padding: 16,
  },
});

Props

namedescriptionrequiredtypedefault
refRef to get access to the Accordion ViewNOref
isArrowIf set to false the arrow indicating whether the collapsible-view is expanded or not will not be displayed.NObooleantrue
disabledEnabled/disabled of clicks header(with arrow)NObooleanfalse
initExpandIf true then the collapsible will be expanded on mounting content(For example: with api)NObooleanfalse
colorIconColor tint icon arrowNOstring#16182B
sizeIconSize icon arrowNOnumber16
otherPropertyConfiguration TouchableWithoutFeedbackNOViewProps
isStatusFetchingDisplays an indicator if the content is loaded from the API.NObooleanfalse
initialMountedContentStart mounted content (Memory optimization)YESbooleanfalse
isUnmountedContentif true then the collapsible will unmount when closing animation ends. (Memory optimization)NObooleanfalse
activeBackgroundIconExpanded background color arrowNOstring#E5f6FF
inactiveBackgroundIconInExpanded background color arrowNOstring#FFF0E4
contentHeightDefault height content (optimization)NOnumber0
handleIconRender custom iconNOJSX.Element
onAnimatedEndExpandedCallback closed AccordionNOvoidNO
onAnimatedEndCollapsedCallback opened AccordionNOvoid
handleCustomTouchableRender custom headerNObooleanfalse
handleContentTouchableRender content headerNOJSX.Element
handleIndicatorFetchingRender JSX.Element(Progress). Default - ActivityIndicatorNOJSX.Element
renderContentRender contentNOJSX.Element
configExpandedConfiguration withTiming.NOAnimated.WithTimingConfig
configCollapsedConfiguration withTiming.NOAnimated.WithTimingConfig
styleChevronStyle Animated.ViewNOAnimated.AnimateStyle
styleTouchableStyle Animated.ViewNOAnimated.AnimateStyle
styleContainerStyle ViewNOViewStyle
onChangeStateCallback onChange state Accordion(open/close)NOvoid
openAccordionAvailable at ref linkNOvoid

🎉 Example

Checkout the example here.

✌️ Contributing

Pull requests are always welcome! Feel free to open a new GitHub issue for any changes that can be made.

Author

Reach out to me at one of the following places!

  • E-mail effectwaater@gmail.com
  • Medium at https://medium.com/@effectwaaters
  • Instagram at https://www.instagram.com/dev_event/

License

License