Code Monkey home page Code Monkey logo

react-native-collapsible's Introduction

react-native-collapsible

Animated collapsible component for React Native using the Animated API

Pure JavaScript, supports dynamic content heights and components that is aware of its collapsed state (good for toggling arrows etc).

Installation

npm install --save react-native-collapsible

Collapsible Usage

import Collapsible from 'react-native-collapsible';

() => (
  <Collapsible collapsed={isCollapsed}>
    <SomeCollapsedView />
  </Collapsible>
);

Properties

Prop Description Default
align Alignment of the content when transitioning, can be top, center or bottom top
collapsed Whether to show the child components or not true
collapsedHeight Which height should the component collapse to 0
enablePointerEvents Enable pointer events on collapsed view false
duration Duration of transition in milliseconds 300
easing Function or function name from Easing (or tween-functions if < RN 0.8). Collapsible will try to combine Easing functions for you if you name them like tween-functions. easeOutCubic
renderChildrenCollapsed Render children in collapsible even if not visible. true
style Optional styling for the container
onAnimationEnd Callback when the toggle animation is done. Useful to avoid heavy layouting work during the animation () => {}

Accordion Usage

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

import Accordion from 'react-native-collapsible/Accordion';

() => (
  <Accordion
    activeSections={[0]}
    sections={['Section 1', 'Section 2', 'Section 3']}
    renderSectionTitle={this._renderSectionTitle}
    renderHeader={this._renderHeader}
    renderContent={this._renderContent}
    onChange={this._updateSections}
  />
);

Properties

Prop Description
sections An array of sections passed to the render methods
renderHeader(content, index, isActive, sections) A function that should return a renderable representing the header
renderContent(content, index, isActive, sections) A function that should return a renderable representing the content
renderFooter(content, index, isActive, sections) A function that should return a renderable representing the footer
renderSectionTitle(content, index, isActive) A function that should return a renderable representing the title of the section outside the touchable element
onChange(indexes) A function that is called when the currently active section(s) are updated.
keyExtractor(item, index) Used to extract a unique key for a given item at the specified index.
activeSections Control which indices in the sections array are currently open. If empty, closes all sections.
underlayColor The color of the underlay that will show through when tapping on headers. Defaults to black.
touchableComponent The touchable component used in the Accordion. Defaults to TouchableHighlight
touchableProps Properties for the touchableComponent
disabled Set whether the user can interact with the Accordion
align See Collapsible
duration See Collapsible
easing See Collapsible
onAnimationEnd(key, index) See Collapsible.
expandFromBottom Expand content from the bottom instead of the top
expandMultiple Allow more than one section to be expanded. Defaults to false.
sectionContainerStyle Optional styling for the section container.
containerStyle Optional styling for the Accordion container.
renderAsFlatList Optional rendering as FlatList (defaults to false).

Demo

demo

Example

Check full example in the Example folder.

import React, { Component } from 'react';
import Accordion from 'react-native-collapsible/Accordion';

const SECTIONS = [
  {
    title: 'First',
    content: 'Lorem ipsum...',
  },
  {
    title: 'Second',
    content: 'Lorem ipsum...',
  },
];

class AccordionView extends Component {
  state = {
    activeSections: [],
  };

  _renderSectionTitle = (section) => {
    return (
      <View style={styles.content}>
        <Text>{section.content}</Text>
      </View>
    );
  };

  _renderHeader = (section) => {
    return (
      <View style={styles.header}>
        <Text style={styles.headerText}>{section.title}</Text>
      </View>
    );
  };

  _renderContent = (section) => {
    return (
      <View style={styles.content}>
        <Text>{section.content}</Text>
      </View>
    );
  };

  _updateSections = (activeSections) => {
    this.setState({ activeSections });
  };

  render() {
    return (
      <Accordion
        sections={SECTIONS}
        activeSections={this.state.activeSections}
        renderSectionTitle={this._renderSectionTitle}
        renderHeader={this._renderHeader}
        renderContent={this._renderContent}
        onChange={this._updateSections}
      />
    );
  }
}

Transition backgrounds

If you combine with the react-native-animatable library you can easily transition the background color between the active and inactive state or add animations.

Lets augment the example above with:

import * as Animatable from 'react-native-animatable';

(...)

  _renderHeader(section, index, isActive, sections) {
    return (
      <Animatable.View
        duration={300}
        transition="backgroundColor"
        style={{ backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)') }}>
        <Text style={styles.headerText}>{section.title}</Text>
      </Animatable.View>
    );
  }

  _renderContent(section, i, isActive, sections) {
    return (
      <Animatable.View
        duration={300}
        transition="backgroundColor"
        style={{ backgroundColor: (isActive ? 'rgba(255,255,255,1)' : 'rgba(245,252,255,1)') }}>
        <Animatable.Text
          duration={300}
          easing="ease-out"
          animation={isActive ? 'zoomIn' : false}>
          {section.content}
        </Animatable.Text>
      </Animatable.View>
    );
  }

(...)

To produce this (slowed down for visibility):

accordion-demo

Contributing

Interested in contributing to this repo? Have a look at our Contributing Guide

Maintainers


Joel Arvidsson

Author

License

MIT License. © Joel Arvidsson and contributors 2015-2021

react-native-collapsible's People

Contributors

aburdiss avatar andriichernenko avatar dakaz avatar dependabot[bot] avatar eduardomoroni avatar ehtisham-ali-emumba avatar eymaddis avatar freakinruben avatar greyvugrin avatar gwmccull avatar ikevin127 avatar iroachie avatar j-mendez avatar jdonald avatar joevo2 avatar jozan avatar juangl avatar marcorm avatar mcajben avatar michielhegemans avatar oblador avatar okb1100 avatar paulpopiel avatar peacechen avatar pkruzlics avatar slorber avatar svbutko avatar tigershen23 avatar timhagn avatar xiqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-collapsible's Issues

ListView within collapsible

Hey how's it going? Love the library but I'm having a little trouble putting a ListView within a collapsible component.

Whenever I put a ListView into a Collapsible, it seems to lose the screen border, and renders the rest of the list off page with no scrolling (But collapsing works fine!). If I remove Collapsible, it flex's to the edge of screen and allows scroll.

If I give the ListView a static height, it renders and scrolls fine, but needs to be precise, and feels wrong. I think something about collapsible is losing the screen dimensions? I'm sure I'm missing a React trick somewhere, I've just started playing around with this.

So essentially:
Parent Class:

  renderPage: function(){
    return (
      <View style={styles.main} >
        <TouchableOpacity onPress={this.toggleRoster} >
          <KkToolbar title={"Roster"} />
        </TouchableOpacity>
        <Collapsible collapsed={!this.state.rosterToggle} style={styles.roster}>
          <Child id={this.props.id} navigator={this.props.navigator} />
        </Collapsible>
        <KkToolbar title={"Team Matches"}/>
      </View>
    );
  },

Child Class:

 renderChild: function(){
    return (
      <View style={styles.main} >
        <TouchableOpacity onPress={this.grabTeamHistory.bind(this,this.state.team_id)}>
            <KkToolbar title={this.state.team} style={[this.props.style]} />         
          </TouchableOpacity>
        <ListView
            dataSource={this.state.dataSource}
            renderRow={this.renderPlayer}
            style={[styles.roster]}  />
      </View>
    );
  },

and, the styles:

  main: {
    flex: 1,
    flexDirection: 'column',
    //alignItems: 'center',
    backgroundColor: '#000',
  },
  roster: {
    flexDirection: 'column',
    flex:1,
    // height: windowSize.height-269,
  },

Can't click the item in the renderContent for Accordion.

When i click an item from the renderContent to navigate somewhere, I got this 'undefined is not a function' which is weird. Even the method is empty.

`renderContent(section) {

return (
  <List
    dataArray={section.serviceList}
    renderRow={(item) =>
      <ListItem
        button
        onPress={() => this.bread(')}
        style={styles.subListView}>
        <View style={styles.subView}>
          <Text style={styles.childText}>{item.serviceName}</Text>
        </View>
      </ListItem>
    }>
  </List>
);

}`

bread() { console.log('press'); }

@oblador

Allow each Collapsible to open/close individually independent from other Collapsibles

renderSections(sections){ return( sections.map(function(section, i){ return ( <View> <TouchableHighlight onPress={???}> <View style={styles.header}> <Text style={styles.headerText}>{section.chapter}</Text> </View> </TouchableHighlight> <Collapsible collapsed={this.state.collapsed} align="center"> <View style={styles.content}> <HTMLView value={section.text} stylesheet={styles} onLinkPress={(url) => this.getDetailsFromLink(url)}/> </View> </Collapsible> </View> ) }.bind(this)) ) }

Unmeet peer dependency

UNMET PEER DEPENDENCY [email protected]
└── [email protected]

react-native version
react-native-cli: 1.0.0
react-native: 0.27.2

Package.json
"dependencies": {
"@remobile/react-native-action-sheet": "^1.0.1",
"alt": "^0.18.5",
"lodash": "^3.10.0",
"react": "^15.1.0",
"react-native": "0.27.2",
"react-native-android-share": "0.0.4",
"react-native-bottom-sheet": "^0.1.1",
"react-native-button": "^1.6.0",
"react-native-collapsible": "^0.7.0",
"react-native-custom-action-sheet": "0.0.11",
"react-native-drawer": "^2.2.3",
"react-native-gifted-spinner": "0.0.4",
"react-native-lazyload": "^1.1.0",
"react-native-parallax-scroll-view": "^0.19.0",
"react-native-scrollable-tab-view": "^0.5.4",
"react-native-scrollview-lazyload": "^1.0.5",
"react-native-share": "^1.0.13",
"react-native-storage": "^0.1.2",
"react-native-swiper2": "^2.0.7",
"react-native-viewpager": "^0.2.11",
"superagent": "^2.1.0"
}

[Accordion][RN29][iOS] ListView in active Collapsible content would not show up until get swiped

Just record here to help others.
If you render a ListView in renderContent(content, idx, isActive){} for <Accordion /> , even if you have clicked the header to activate the Collapsible section and render the section with correct contentHeight, the ListView is invisible unless you swipe vertically or horizontally.

removeClippedSubviews={false} needs to be applied to ListView to prevent this.

Refs:
Fixed removeClippedSubviews
ListView (or perhaps ScrollView) disappears after running in background for several minutes

Not showing on RN39

Not showing on RN39 on iOS.
Collapsible
sections={[1,2,3,4,5]}
renderHeader={this._renderHeader}
renderContent={this._renderContent}

_renderHeader(){
return(General Introduction to Animal Farm)}
_renderContent(){
return(123)}what causes this issue?

Question regarding performance

Say I have a very large ListView and I use this library to collapse all the items in the ListView. Theoretically this should improve the performance significantly since the items in the ListView are hidden and not rendered, is this correct?

The other thing that I noticed is that collapsing a ListView doesn't re-render new items that are now supposed to be pushed up into the view since there is more space. I have to scroll down for new items to render. See screencast:

screencast

Background Image in Header

Trying to make the image file header accordion adaptive on all platforms, it is impossible.
What's the matter?
simulator screen shot 24 2016 20 24 35

<Image style={styles.header} source={section.pic}><Text style={styles.headerText}>{section.title}</Text></Image>

StyleSheet:

const styles = StyleSheet.create({
  header: {
    flex: 1,
    padding: 30,
    alignItems: 'stretch'
  },
  headerText: {
    textAlign: 'center',
    fontSize: 30,
    alignItems: 'center',
    color: '#f9f6fb',
    fontWeight: '200'
  },
  content: {
    paddingTop: 30,
    backgroundColor: '#fff',
  },
  textContent: {
    paddingTop: 10,
    paddingLeft: 10,
    paddingRight: 10,
    paddingBottom: 10
  }
});

The complete code here:
https://github.com/gHashTag/iSoulClub/blob/master/index.ios.js

leave the content open

Is there anyone to just leave the content and header open? For example if the user clicks on the header, it remains open until the user chooses to close it rather than it disappearing when another header is clicked on?

How to handle dynamic accordion content

Thanks for this useful component,

I'm having a trouble while trying to create an accordion.

When user clicks a submenu under a menu, content of the accordion is changed and it is rerendered with a different content.

This is how i use activeSection in accordion
activeSection={this.state.activeSection}
In my header content every view's structure is

View
View (image)
View (text)
View (image)
View

assuming that if i have 4 rows in old content and i click 2nd item which is index 1 in new content 2nd head (index1)view's text is changed but images are not changed. I'm having this issue only with iOS. Code works well with Android images are changed properly.

note: images's sources and logs controlled several times.

Can't open the panel which is be collapsed if has not set height style to Collapsible

RN Version: 0.38.0
collapsible Version: 0.7.0
If I haven't set height or minHeight style to Collapsible, the collapsed panel can't be opened.

<Button
  onPress={this.togglePanel}
  title="切换Panel"
/>
<Collapsible collapsed={this.state.isCollapsed} style={{ minHeight: 100 }}>
  <Text>我是面板</Text>
</Collapsible>
togglePanel() {
  this.setState({ isCollapsed: !this.state.isCollapsed })
}

Animated On Open but Not Close?

Some content animates nicely when it opens. For example, I have an icon that is set to center vertically so when the content opens it slides nicely down to stay center. However when closing the collapsible container it jumps to the top immediately rather than animating. Any way to resolve?

Also any way to have size also animate? So if an icon or text were to get larger it would automatically show it animate as it gets larger? Think that may require your Animatable

Not collapsing

Somehow after awhile, it stop working and not collapsing anymore. Which is weird.

SUB COLLAPSING
toggleDocuments = () => { console.log('triggered'); this.setState({ collapsed: !this.state.collapsed }); }

render(){ return( <View style={{backgroundColor:'white'}}> <SubBody isCollapse={this.toggleDocuments} /> <Collapsible collapsed={this.state.collapsed} align="center" > <SubDocuments /> </Collapsible> </View> ); }

SubBody
render() { return ( <View> <List> <ListItem iconLeft iconRight style={{ borderColor: 'transparent', padding: (Platform.OS === 'ios') ? 6 : 16, }} button onPress={this.props.isCollapse}> <Icon name='ios-folder' style={{ fontSize: 20, color: '#B3B3B3', padding: 6, }} /> <Text style={{ fontSize: 14, color: '#686868', padding: 6, fontWeight: 'bold' }}>Documents to bring</Text> <Icon name='ios-arrow-down' style={{ fontSize: 20, color: '#00964B', padding: 6 }} /> </ListItem> </List> </View> ); } }

Someone please point out where my mistake is.

Broken with latest react-native (0.36)

Upgraded from 0.34 to 0.36 and all my collapsible elements stay collapsed all the time. Tested also with example from this projects and saw the same behaviour or lack of it.

Didn't have too much time to investigate yet but with limited testing it seems that height is always zero in onLayout callback.

Question on "collapsed property"

We are using react react-native-collapsible component.
We have several collapsible elements in the navigation page we are building.

In the beginning collapsed property is set to true. When one of the navigation elements is clicked, we are setting the collapsed property to false. This opens up ALL the navigation elements on the navigation page.

Is there any way we can restrict the opening of the sub-nav elements only to the nav elements we clicked on?

Trouble using a Collapsible within a List View.

I have no idea what my problem is, but after hours of playing with it I found out, that if I create my custom element with collapsible set to true, all works well.

Full code here:

    import {Colors} from '../../../config/constants';
    import React from 'react';
    import {StyleSheet, Text, View, TouchableOpacity, ListView} from 'react-native';
    import {getCorrectFontSizeForScreen} from '../../../lib/Utils/multiResolution'
    import Dimensions from 'Dimensions';
    const {height:h, width:w} = Dimensions.get('window'); // Screen dimensions in current orientation

    import {createIconSetFromIcoMoon} from 'react-native-vector-icons';
    import icomoonConfig from '../../../../assets/fonts/icomoon.json';
    const PavIcon = createIconSetFromIcoMoon(icomoonConfig);
    import Collapsible from 'react-native-collapsible';
    import SubcommentContainerListCard from './SubcommentContainerListCard';
    import getStyles from './accordionStyles'

    class AccordionBillCommentCardContainer extends React.Component {
      constructor(props) {
        super(props);
        this.state={
          isCollapsed:true
        }
      }

      expandCard(){
        this.setState({isCollapsed:false});
      }

      collapseCard(){
        this.setState({isCollapsed:true});
      }

      onHeaderClick(){
        // alert("Render accordion content");
          this.setState({
            isCollapsed:!this.state.isCollapsed
          })
      }

      renderAccordionHeader(styles){
        return (
          <TouchableOpacity onPress={this.onHeaderClick.bind(this)} style={styles.headerContainer}>
            <View style={styles.repliesBoxTextContainer}>
              <Text style={styles.repliesBoxText}>{this.props.replies.length>1?this.props.replies.length+" Replies ":"1 Reply"}  {this.state.isCollapsed==true?"(Tap to expand)":"(Tap to collapse)"}</Text>
            </View>
            <PavIcon name={this.state.isCollapsed==true?"arrow-down":"arrow-up"} size={15} style={styles.repliesBoxIcon}/>
          </TouchableOpacity>
        );
      }




      render() {
        let isPortrait = (this.props.device.orientation!="LANDSCAPE");
        // console.log("@@@@ IS PORTRAIT : "+isPortrait);
        let styles= isPortrait?getStyles().getPortraitStyles(this):getStyles().getLandscapeStyles(this);
        console.log("this.state.isCollapsed"+this.state.isCollapsed);
        return(
          <View style={[styles.cardContainer,this.props.style]}>
            {this.renderAccordionHeader(styles)}
            <Collapsible collapsed={this.state.isCollapsed}>
              <View style={{backgroundColor:'red', flex:1,}}>
                <Text>Hello world
                </Text>
              </View>
            </Collapsible>
          </View>
        );
      }


      shouldComponentUpdate(nextProps, nextState) {
        return(
          (nextProps.device.orientation !== this.props.device.orientation)
          ||
          (nextProps.replies !== this.props.replies)
          ||
          (nextState.isCollapsed !==this.state.isCollapsed)
        );
      }

    }

screen shot 2016-05-26 at 02 12 36

If on the other hand collapsible is set to false, the Collapsible never gets to work.

screen shot 2016-05-26 at 02 11 17

I really wanna use the Collapsible, but I've got great trouble using it within the ListView.
What to do?

issues with listview

I wanted to use this component as part of a listview's row.
I had an issue when collapsing or expanding: the collapsible component simply doesnt get updated for some reason. Is there any solution for this?

Scroll To Bottom (need help)

Hi,

I've been using your Accordion component inside a scrollview and I'm wondering if there's a way I can scroll to the bottom of the scrollview when a section is active.

I gave a ref to the scrollview so I'm thinking I could use 'this.refs.scrollviewRef.scrollTo' inside the 'onChange' callback but I don't know how to get the full height of the scrollview...

can you help me?

Thanks in advance

renderSeparator a la ListView?

Does there exist a way of adding a separator to Accordion as one would with ListView (rendered below the contents of renderContent)? If there is no such feature, is there a workaround or plans to add it?

Also, this library's been a life saver, so thanks for developing it!

Close all active sections

Hello there!

First, thanks for this amazing component. It is really awesome!

Is there a way to close all active collapsible? In my case, as an accordion, it will always have just one, but when I delete one of the sections, it automatically rearrange the accordion and it indexes, but it keeps the index opened. So I have a new section occupying the same accordion index, which is active.

Hope I made it clear!

Thanks a lot

Flexbox limitation - unexpected behaviour

Great Plugin. Love it. But I found a big bug!
I am using the <Accordion> to swap 2/3 of the page. There should be a 1/3 fixed Action Footer.

My problem is that if I assign a (pixel) height via StyleSheet to the accordion it works properly.
When I assign flex: 1 to the accordion then the collapsable will no longer appear.
When nothing is assigned then the accordion is only the required height, but is not filling the space (which I think is the expected behaviour).
Within the _renderContent I am using a ScrollView in case the content gets too long, which is the point I guess of an accordion.

The code looks very similar to this:

<View style={flex: 1}>
    <View style={flex: 2}>
         <Accordion
              sections={['Section 1', 'Section 2', 'Section 3']}
              renderHeader={this._renderHeader.bind(this)}
              renderContent={this._renderContent.bind(this)}
              style={flex: 1} /* <- THIS DOES NOT WORK, 
                              {height: 200} will work, but is not responsive
                              */ 
         />
     <View style={flex: 1, backgroundColor: 'gray'}>
           <Text>Action Footer</Text>
     </View>
</View>

How to make Accordion/Collapsible to take all available height

I would like to put a ScrollView inside a collapsible/accordion, so when expanded it will take all available space.
It works only when I specify exect height, so I got a height from onLayout of Accordion's parent and put it to Accordion style height. but then this height sent direclty to inner collapsible without calculating accordion headers.
What Im doing wrong?

Expanding elements

On our project we are using the collapsible to create an expandable pop-down comments section under boxes of content. Is there a way to ensure that the uncollapsed content pushes other items out of it's way? Perhaps this is out of the scope of the "collapsible" component - just thought I'd double check here. For example: the first screenshot represents the collapsed view. The second screenshot is the uncollapsed view. The red box represents the uncollapsed content: note that it is being displayed BEHIND the following item box.
screen shot 2015-08-24 at 3 20 44 pm
screen shot 2015-08-24 at 3 20 58 pm

Appreciate your time and the resource you have built for the community! Peace.

Collapsible within ListView within ViewPagerAndroid

In my project I got a ListView with this row layout:

<TouchableWithoutFeedback onPress={this.props.setExpandedProduct}>
        <View style={[s.container]}>
          <ProductInfoComponent product={this.props.product}/>
          <Collapsible collapsed={this.props.isCollapsed}>
            <View style={s.productPriceContainer}>
              {productPrices && productPrices.map((id) =>
                <ProductPriceContainer key={id} productPriceId={id} onAdd={this.handleAdd}/>
              )}
            </View>
          </Collapsible>
        </View>
      </TouchableWithoutFeedback>

This is working fine in iOS. In Android it is working fine too until I wrap my ListView in a ViewPagerAndroid. It will not expand OR collapse anymore.

This version (without Collapsible) still works like expected.

<TouchableWithoutFeedback onPress={this.props.setExpandedProduct}>
        <View style={[s.container]}>
          <ProductInfoComponent product={this.props.product}/>
          {!this.props.isCollapsed && (
               <View style={s.productPriceContainer}>
                  {productPrices && productPrices.map((id) =>
                     <ProductPriceContainer key={id} productPriceId={id} onAdd={this.handleAdd}/>
                   )}
                </View>
            )}
        </View>
      </TouchableWithoutFeedback>

I tested some more (before posting this issue):

It does work on my device (Android 4.4) and on my other Emulator devices. Only the S6 (Android 6.0) does not work!

image

The question is, if this is a real issue with Android 6.0 or if it is only an emulator bug?

Can't run examples

I went into Example and did "npm install", do I need to do anything else?

$ react-native run-ios
module.js:327
throw err;
^

Error: Cannot find module './packager/babelRegisterOnly'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/Users/webfreelance10/react-native-collapsible/Example/node_modules/react-native/cli.js:11:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)

Load content when accordion is pressed

Is it possible to show accordion content when it is pressed? I want to load some dynamic data on content. It seems its calling header and content every time when I press to any tab. Pls help @oblador

Error Loading module

Upgrading from React Native 0.5.0 to 0.7.1 led to this module not being recognized. With 0.5.0, using require("Accordion") worked just fine. The module couldn't be recognized after upgrading to 0.7.1, and the command require("react-native-collapsible/Accordion") also didn't work.

I have also restarted Xcode, the terminal, and Chrome Ive also restarted my laptop 2x just to be sure.

I was able to solve a similar problem with react-native-vector-icons. As I was originally using its FontAwesome module, I only needed to use require("FontAwesome") in 0.5.0; but using require("react-native-vector-icons/FontAwesome") fixed the problem with 0.7.1.
collapsible

No ListView on Android

When using this library, passing a ListView to the accordion, on iOS it works as expected, although on Android, I get no scrolling. Any ideas what may be causing this? I have made sure that the ListView has flex:1, and its rowComponents as well.

activeHeaderStyle

Hey Oblador,
As discussed on Discord, would be cool to have an option for "activeHeaderStyle" on the Accordion. This would allow a separate style to be applied internally when an item is opened.

Extra credit for adding a transition to it. Would be cool if it animated for example if you change background color - but i have never done all that yet so not sure how complex that gets!

Thanks for the package!

Black underlay

Thanks for this project, it has been very helpful!

I'm using the accordion component and have noticed that there is a black underlay on the headers when you tap them to open a section. Is there a way to change the color of the black underlay?

Unhandled JS Exception

when I click faster will get below error

image

above error can't appear when I click slowly :(

any idea?

thanks for you time.

Unable to expand view in iOS on RN39

It load the list, When taps on it, it does not expand in iOS on RN 0.39. I am using Xcode 8 and iOS 10 simulator to test it.And your example code has the same problem.

What am I doing wrong?

Follow the instructions connected
npm install --save react-native-collapsible
After add Example code in my project:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import Collapsible from 'react-native-collapsible';
import Accordion from 'react-native-collapsible/Accordion';
const SECTIONS = [
  {
    title: 'First',
    content: 'Lorem ipsum...',
  },
  {
    title: 'Second',
    content: 'Lorem ipsum...',
  }
];

class AccordionView extends Component {
  _renderHeader(section) {
    return (
      <View style={styles.header}>
        <Text style={styles.headerText}>{section.title}</Text>
      </View>
    );
  }

  _renderContent(section) {
    return (
      <View style={styles.content}>
        <Text>{section.content}</Text>
      </View>
    );
  }

  render {
    return (
      <Accordion
        sections={SECTIONS}
        renderHeader={this._renderHeader}
        renderContent={this._renderContent}
      />
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('AccordionView', () => AccordionView);

Simulator:
simulator screen shot 18 2016 16 46 02

Collapsible not working.

It appears that the Collapsible View is not working in ios. I've tried updating to the latest version ("react-native-collapsible": "^0.8.0") and I am still having issues.

Seems this remains hidden regardless.

<Collapsible collapsed={false}>
      <Text> Yo </Text>
</Collapsible>

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.