Giter VIP home page Giter VIP logo

react-native-accordion's Introduction

React Native Accordion

npm npm downloads Code Climate

react-native-accordion is an easy to use Accordion component for React Native app.

accordion

Install

npm i --save react-native-accordion

Usage

Using an Accordion in your app will usually look like this:

var Accordion = require('react-native-accordion');

var YourComponent = React.createClass({
  getInitialState() {
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    return {
      dataSource: ds.cloneWithRows(_.range(25)),
    };
  },

  render() {
    return (
      <ListView
        dataSource={this.state.dataSource}
        renderRow={this._renderRow}
      />
    );
  },

  _renderRow() {
    var header = (
      <View style={...}>
        <Text>Click to Expand</Text>
      </View>
    );

    var content = (
      <View style={...}>
        <Text>This content is hidden in the accordion</Text>
      </View>
    );

    return (
      <Accordion
        header={header}
        content={content}
        easing="easeOutCubic"
      />
    );
  }
});

Examples

Here are a few examples of how you can use an accordion in your app:

Transit App Tweetbot
accordion-transit accordion-tweetbot

Props

The following props can be used to modify the Accordion's style and/or behaviour:

Prop Type Opt/Required Default Note
activeOpacity Number Optional 1 The active opacity of the TouchableHighlight.
animationDuration Number Optional 300 The duration of the animation.
content Element Required N/A The content you want hidden in the collapse accordion.
easing String Optional linear A tweening function from tween-functions.
expanded Boolean Optional false If the accordion is expanded by default when mounted.
header Element Required N/A The element that will expand the accordion when pressed.
onPress Function Optional N/A A function that will be called when the accordion is pressed.
underlayColor String Optional #000 The underlay color of the TouchableHighlight.
style Object Optional {} The styles you want to set on the accordion element.

Methods

The following methods can be used to open and close the accordion:

Method Parameters Note
open N/A Open the accordion.
close N/A Close the accordion.
toggle N/A Toggle the accordion.

License

Copyright (c) 2015, Naoufal Kadhom

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

react-native-accordion's People

Contributors

alexrabarts avatar dennyferra avatar mvayngrib avatar naoufal 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

react-native-accordion's Issues

Signed apk crash in android device

hi,
I am facing some issue. I am using "react-native-accordion": "0.2.4" library for my project. This is working fine in IOS. when I run my app in android device in debugging mode. Then app is running fine. But if I used signed apk in same device then it is give this error. here I paste my application crash report log which are shown in android monitor. Error given below.

FATAL EXCEPTION: mqt_native_modules
Process: com.ampsmobile, PID: 2139
com.facebook.react.modules.core.JavascriptException: Requiring unknown module "react-native-accordion", stack:
t@2:387
i@2:177
@451:139
t@2:511
i@2:177
@449:139
t@2:511
i@2:177
@448:203
t@2:511
i@2:177
@447:212
t@2:511
t@2:240
i@2:177
component@44:489
u@44:130
o@44:48
createScene@44:1781
_renderScene@244:15724
@244:16158
render@244:16032
_renderValidatedComponentWithoutOwnerOrContext@152:5072
_renderValidatedComponent@152:5200
_updateRenderedComponent@152:4595
_performComponentUpdate@152:4395
updateComponent@152:3672
performUpdateIfNecessary@152:3193
performUpdateIfNecessary@132:667
r@130:571
perform@135:494
perform@135:494
perform@130:1539
P@130:1711
closeAll@135:1131
perform@135:581
batchedUpdates@129:456
s@130:761
a@149:69
enqueueSetState@149:917
setState@29:339
push@244:13537
onPressRow@429:2254
onPress@437:2706
touchableHandlePress@295:1171
_performSideEffectsForTransition@219:8188
_receiveSignal@219:6697
touchableHandleResponderRelease@219:4183
a@113:72
o@111:392
a@111:583
f@109:163
g@109:266
i@115:88
processEventQueue@109:1386
s@163:92
handleTopLevel@163:182
_receiveRootNodeIDEvent@162:617
receiveTouches@162:999
value@60:3582
@60:1801
k@60:436
value@60:1773

Text component with dynamic content inside Accordion

Do I need to do anything special for a with dynamic content (.children) inside an ?

I have something like this:

{this.props.stateVar}

Where stateVar is a dynamic string set by a Redux reducer. If is outside the it updates as expected. If it is inside it doesn't get triggered for an update. I've tried adding dummy props, wrapping the with another component that uses a prop to set the content string, and forcing re-render of the via a ref, but can't seem to get it to update the contents. Doesn't seem to matter if the Accordion is open or closed. Any help is appreciated.

As an aside, I'm new to Github - is this the right place to ask questions or is 'issues' only for bugs?

Warning thrown for styling with StyleSheet.create

  propTypes: {
    activeOpacity: React.PropTypes.number,
    animationDuration: React.PropTypes.number,
    content: React.PropTypes.element.isRequired,
    easing: React.PropTypes.string,
    expanded: React.PropTypes.bool,
    header: React.PropTypes.element.isRequired,
    onPress: React.PropTypes.func,
    underlayColor: React.PropTypes.string,
    style: React.PropTypes.object
  },```

In propTypes, style is expecting a raw object instead of compiled stylesheets.

Perhaps remove that propType?

Empty view after pop -> rotation -> back to view

Hello to all,
i hope that i can explain my problem.

I see the ListView plus the Accordion and all works fine, but if a go to the next page (Navigation pop), rotate the iPhone and go back to the ListView with the Accordion elements, the ListView is empty.

When i don't use the Accordion, i can see all ListView entities.

How can i fixed?

Thanks for support
Marcel

Feature: nested accordion

I already got the code for this working. do U want a PR? :)

basically, this is the implementation:

export default class AccordionNav extends Component {

  static propTypes = {
    data: PropTypes.array.isRequired,
  }

  render () {
    return (
      <View style={ styles.container }>
        { this.props.data.map(this.renderRecursion) }
      </View>
    )
  }

  renderRecursion = ({ children, title }) => {
    if (!children) {
      return (
        <Text key={ title }>{ title }</Text>
      )
    }
    return (
      <Accordion
        header={ <Text>{ title }</Text> }
        content={
          <View>
            { children.map(this.renderRecursion) }
          </View>
        }
        easing='easeOutCubic'
        key={ title }
      />
    )
  }

}

View does not auto-adjust based on expansion

If I click on a cell and it expands, the view should auto-adjust to the bottom border of the content that just opened, correct? It doesn't seems to do that. How can I implement this?

Displaying Multiple Contents

I'm trying to display a ListView of parent categories and multiple subcategories for each parent category, and displaying them out in expanded view is waste of screen space, so I came across your component and thought was neat, but it seems like react-native-accordion only allows to display one content per header.

I have data formatted in the following way.

{[
'Restaurant': ['Hamburgers', 'Pizza', 'Chicken', 'Sushi']
...
]}

With react-native-accordion, is there a way to make 'Restaurant' be the header of the accordion and be expanded for view of the sub-categories?

Animations not working in Android

Following is my code for a component in my react native android app. Everything is working fine but the animation. Did I do something wrong? Or anyone else facing this issue?

export default class Home extends Component {
  constructor(props){
    super(props);
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state={dataSource:ds.cloneWithRows(['row 1', 'row 2'])}
  }
  render() {
    return (
      <ListView
        dataSource={this.state.dataSource}
        renderRow={this._renderRow}
      />
    );
  }

  _renderRow() {
    var header = (
      <View style={{height:80}}>
        <Text>Click to Expand</Text>
      </View>
    );

    var content = (
      <View style={{height:80}}>
        <Text>This content is hidden in the accordion</Text>
      </View>
    );

    return (
      <Accordion
        header={header}
        content={content}
        duration={3000}
        easing="easeInBounce"
      />
    );
  }

Shadow doesn't work on header

If you set a shadow in the header component it doesn't work as a component shadow, accordion draws it in each subcomponent:

issue accordioon

Unmeet peer dependency

UNMET PEER DEPENDENCY [email protected]
└─┬ [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"
}

[question] how to use with inverted scroll view

i have a component with an inverted scroll view and i'm using your accordion implementation there, but I find that because it's inverted, the accordion opens upwards instead of downwards, which is very unintuitive for the eye. Obviously this isn't your component's problem, but I was wondering if you've already solved this in any of your projects using scrollTo or otherwise. Thanks!

Unable to expand view in iOS

Your sample code works well in Android. But, It does not work in iOS. It load the list, When taps on it, it does not expand in iOS. I am using Xcode 8 and iOS 10 simulator to test it.

Footer

Is it possible (or can you suggest how) to add a footer to the accordion? I'd like the content to be sandwiched between the header and proposed footer. Thanks!

not an issue, a question

Hello,

My Code is down bellow. its working but i got two warnings :

Warning: Failed propType: Invalid prop content supplied to Accordion, expected a single ReactElement. Check the render method of StaticRenderer.

Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of Accordion. It was passed a child from StaticRenderer. See https://fb.me/react-warning-keys for more information.

Any idea how to fix it? or any better way to have multiple contents for each header?

class Courses extends Component {

  constructor(props) {
        super(props);
        this.state = {
          dataSource: new ListView.DataSource({
            rowHasChanged: (row1, row2) => row1 !== row2,
          }),
          loaded: false,
        };
        this.rowPressed = this.rowPressed.bind(this);
    }
  rowPressed(data) {
    console.log('row press');
  }

  fetchData() {
/// fetching data .....
  }

  componentDidMount() {
    this.fetchData();
  }

  render() {
    if (!this.state.loaded) {
      return this.renderLoadingView();
    }

    return (
      <View style={{ flex: 1 }}>
      <ListView
        dataSource={this.state.dataSource}
        renderRow={this.renderRow}
        style={styles.listView}
      />
      </View>
    );
  }

  renderRow(data) {
    var header = (
      <View>
          <View style={styles.rowContainer}>
            <View  style={styles.textContainer}>
              <Text style={styles.title}>{data.nid}</Text>
              <Text style={styles.description} numberOfLines={0}>{data.title}</Text>
            </View>
          </View>
          <View style={styles.separator}/>
        </View>
    );
///////////
    var content = [];
    for(var x=0; x < Object.keys(data.course).length; x++){
      content.push(
        <View style={styles.rowContainer}>
        <TouchableHighlight onPress={() => this.rowPressed(data.course[x].course_id).bind(this)} underlayColor='#e3e0d7'>
        <Text style={styles.child}>{data.course[x].title}</Text>
        </TouchableHighlight>
        </View>
      );
    }
////////////
    return (
      <Accordion
        header={header}
        content={content}
        easing="easeOutCubic"
      />
    );
  }

  renderLoadingView() {
    return (
      <View style={styles.loading}>
        <Text style={styles.loading}>
          Fetching Courses, please wait...
        </Text>
      </View>
    );
  }
}

module.exports = Courses;

Thanks in Advance!

Does not close previously opened row

I created a simple accordian with the information given. I was able to implement the accordian , but it does not close the previous row when i click on the next row, any advice ?

Expanded Prop doesn´t work on Android

Like the title says, the expanded prop won´t effect on Android device. On my iOS Version everything works fine.

_Update_
When debugging the src/index.js i figured out, that i never get into the function of _getContentHeight

 componentDidMount() {
   // Gets content height when component mounts
   // without setTimeout, measure returns 0 for every value.
   // See https://github.com/facebook/react-native/issues/953
   setTimeout(this._getContentHeight);
},

When i remove the setTimeout, i can jump into the function, but every value of measure return 0 for every value. So this might be the issue!?

Any ideas?

Set style for active/expanded?

Is is possible to set different styles on the header, depending on whether the accordion is expanded or not?

Also, it is possible to only allow one accordion to be expanded at a time?

Warning: Accordion: isMounted is deprecated.

When using an accordion in React Native (using Create React Native App) I get this warning as soon as I open the accordion:

Warning: Accordion: isMounted is deprecated. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.

No working in react 16

This package does not work for react 16, for the following reasons:

  • PropTypes does not belongs to the react package anymore.
  • React.createClass does not exist in react 16.
  • Does not support mixins

Data loss [Android]

I have added Text Fields within accordion, When I entered some text in text fields collapse accordion then again reopen/expand accordion fields showing empty on android platform.

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.