0.0.2 • Published 5 years ago

react-native-collapsing v0.0.2

Weekly downloads
8
License
Apache License 2....
Repository
github
Last release
5 years ago

React Native: react-native-collapsing

GitHub package version github home platforms github home npm

github issues github closed issues Issue Stats github license

PNG

📖 Getting started

$ npm install react-native-collapsing --save

$ react-native link react-native-vector-icons

💻 Usage

import * as React from 'react';
import { StyleSheet, View } from 'react-native';

import Collapsing from 'react-native-collapsing';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selected: '',
    };
  }

  render() {
    return (
      <View style={styles.container}>
        <Collapsing
          selected={this.state.selected}
          title="Primo gruppo"
          background="#22252A"
          backgroundBarNormal="#2D3035"
          backgroundBarFocus="#2D3035"
          iconBarNameNormal="videogame-asset"
          iconBarNameFocus="book"
          iconBarColorNormal="#1194ff"
          iconBarColorFocus="#ffb600"
          textBarColorNormal="#1194ff"
          textBarColorFocus="#ffb600"
          iconBarSize={25}
          showOnStart={true}
          animateIconNameNormal="chevron-down"
          animateIconNameFocus="chevron-up"
          animateIconColorNormal="#1194ff"
          animateIconColorFocus="#ffb600"
          badgeText="100"
          badgeColor="#fff"
          badgeBackground="#1194ff"
          badgeRadius={4}
          badgeFunction={e => {
            return e > 99 ? '99+' : e;
          }}
          onPress={e => {
            this.setState({ selected: e.name });
            console.log('1)' + this.state.selected);
          }}
          menu={[
            {
              name: 'sub0',
              title: 'Home page',
              icon: 'home',
              colorText: '#fff',
              colorTextFocus: '#f2a307',
              colorIcon: '#c1c1c1',
              colorIconFocus: '#0480CB',
              background: 'transparent',
              backgroundFocus: '#1E2125',
              badgeText: '1000',
              badgeColor: '#fff',
              badgeBackground: '#1194ff',
              badgeRadius: 4,
            },
            {
              name: 'sub1',
              title: 'Book',
              icon: 'book',
              colorText: '#fff',
              colorTextFocus: '#f9041d',
              colorIcon: '#fff',
              colorIconFocus: '#f9041d',
              //background: '#1194ff',
              backgroundFocus: '#1E2125',
            },
            {
              type: 'menu',
              name: 'sub11',
              title: 'Movie',
              icon: 'film',
              colorText: '#fff',
              colorTextFocus: '#0480CB',
              colorIcon: '#fff',
              colorIconFocus: '#0480CB',
              //background: '#1194ff',
              backgroundFocus: '#1E2125',
            },
          ]}
        />
        <Collapsing
          selected={this.state.selected}
          iconBarNameNormal="videogame-asset"
          iconBarNameFocus="videogame-asset"
          iconBarColorNormal="#0480CB"
          title="Secondo gruppo"
          color="#4CAF50"
          showOnStart={false}
          animateIconNameNormal="chevron-down"
          animateIconNameFocus="chevron-up"
          onPress={e => {
            this.setState({ selected: e.name });
            console.log('2)' + this.state.selected);
          }}
          menu={[
            {
              name: 'sub2',
              title: 'Movie',
              icon: 'home',
            },
            {
              name: 'sub3',
              title: 'Tv',
              icon: 'film',
            },
          ]}
        />
        <Collapsing
          selected={this.state.selected}
          title="Terzo gruppo"
          showOnStart={true}
          onPress={e => {
            this.setState({ selected: e.name });
            console.log('2)' + this.state.selected);
          }}
          menu={[
            {
              name: 'sub4',
              title: 'Theater',
            },
            {
              name: 'sub5',
              title: 'Opera',
              icon: 'film',
            },
          ]}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ecf0f1',
    marginTop: 24,
  },
});

💡 Props

PropTypeDefaultNote
selectedstringIndicates the selected item.
titlestringMenu title.
backgroundstringMenu background color.
backgroundBarNormalstringBackground color of the menu title, when the menu is in normal state.
backgroundBarFocusstringBackground color of the menu title, when the menu is in focus state.
iconBarNameNormalMaterialIconsMenu name icon, when the menu is in normal state.
iconBarNameFocusMaterialIconsMenu name icon, when the menu is in focus state.
iconBarColorNormalstringMenu color icon, when the menu is in normal state.
iconBarColorFocusstringMenu color icon, when the menu is in focus state.
iconBarSizenumberIcon size.
textBarColorNormalstringMenu color text, when the menu is in normal state.
textBarColorFocusstringMenu color text, when the menu is in focus state.
showOnStartboolfalseIndicates whether the menu is normal or focus.
animateIconNameNormalFontAwesomeMenu name animate icon, when the menu is in normal state.
animateIconNameFocusFontAwesomeMenu name animate icon, when the menu is in focus state.
animateIconColorNormalstringMenu color animate icon, when the menu is in normal state.
animateIconSizenumberAnimated icon size.
iconBarSizenumberMenu title icon, when the menu is in normal state.
badgeTextstringBadge text.
badgeColorstringColor of the badge text.
badgeBackgroundstringBackground color of the badge.
badgeRadiusnumberBadge radius.
badgeFunctionfunctionUse in case you want to define a function, for the badgeText attribute.
onPressfunctionIt is used to recover the pressure event.
rippleColorstringRipple color.
menuarrayIt is used to define the menu.

Menu

PropTypeDefaultNote
namestringUnique name to assign to the item.
titlestringTitle of the element.
iconstringFontAwesomeIcon name.
colorTextstring#000000Text color.
colorTextFocusstring#607D8BText color status focus.
colorIconstring#000000Icon color.
colorIconFocusstring#607D8BIcon color status focus.
backgroundstringtransparentBackground element.
backgroundFocusstring#e8e8e8Background element status focus.
badgeTextstringText badge.
badgeColorstringText color badge.
badgeBackgroundstringBackground badge.
badgeRadiusnumberBadge radius.

📜 License

This library is provided under the Apache License.