Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accordion does not fully close #137

Closed
sfratini opened this issue Jan 3, 2018 · 11 comments
Closed

Accordion does not fully close #137

sfratini opened this issue Jan 3, 2018 · 11 comments

Comments

@sfratini
Copy link

sfratini commented Jan 3, 2018

Hi! I am testing the Accordion with a series of Text, Buttons and Images in different configurations. For some reason, when I click on a button inside the accordion, it automatically tries to close the section but it does not fully does so, before actually following the action I have in a button.

I have tried putting a delay before the button does the action, in case the animation was cut short but is still the same issue. Any idea what could be happening?

accordion

My Accordion code:

_renderHeader = (section) => {
       return (
           <View style={this.getStyle(styles, ['header', 'width100', 'centered', 'primaryBackgroundColor'])}>
               <Text  style={this.getStyle(styles, ['font', 'fontPrimaryColor', 'materialFontHeading'])}>{section.header}</Text>
           </View>
       );
     }
   
     _renderContent = (section) => {

       let image, text, button, content = null;

       if (section.text && section.text.length > 0)
           text = <Text style={this.getStyle(styles, ['font', 'materialFontSubheading', 'accordionText'])}>{section.text}</Text>;

       if (section.image){
           if (section.image.type && section.image.type == 'internal')
               image = <Image style={this.getStyle(styles, ['image'])} source={this._IMAGES[section.image.uri]}/>;
           else 
               image = <Image style={this.getStyle(styles, ['image'])} source={{uri: section.image.uri}}/>;                
       }

       if (section.button){
          
          button = (<View style={{justifyContent: 'flex-end', flexDirection: 'row', width: '100%'}}><Nebula 
           component='ButtonComponent' 
               {...section.button}
               navigator={this.props.navigator}
               eventEmitter={this.props.eventEmitter}
           /></View>);
       }

       content = <View style={this.getStyle(styles, ['width100', 'content'])}>{image}{text}{button}</View>

       return content;
     }

   render(){

       let content, image, text, button, header = null;
       let accordion = [];

      if (this.props.items && this._helper.isArray(this.props.items) && this.props.items.length > 0){

       return( 
           <View style={this.getStyle(styles, ['width100'])}>
           <Accordion
           ref='acc'
           sections={this.props.items}
           renderHeader={this._renderHeader}
           renderContent={this._renderContent}
           />
           </View>
       );

      } else return null;
           
   }

There are some functions that I have because I have a "theme" system.

@sfratini
Copy link
Author

sfratini commented Jan 3, 2018

Alright, I have narrowed down to this function in Collapsible, which is triggering and setting the height of the content to 20dp. The only component I have that has that height is some margins.

_handleLayoutChange = event => {
    alert('_handleLayoutChange ' + JSON.stringify(event.nativeEvent));
    
    const contentHeight = event.nativeEvent.layout.height;
    if (
      this.state.animating ||
      this.props.collapsed ||
      this.state.measuring ||
      this.state.contentHeight === contentHeight
    ) {
      return;
    }
    this.state.height.setValue(contentHeight);
    this.setState({ contentHeight });
  };

Edit: The problem is the height returned by the event.nativeEvent.layout.height.

This is my renderContent stlye:

content: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'space-around',
      padding: 10
    },

The nativeEvent.layout.height is saying that my content is 20 in height when is not fully collapsing, which is consistent with the padding. But it should't be adding that into the layout. I'll try playing with the margin and see what happens.

@sfratini
Copy link
Author

sfratini commented Jan 3, 2018

Alright, making sure my content view (the wrapper for all the renderItem) does not have any margin or padding (AKA, moving the margin and padding to the children) made it collapse all the way.

The issue right now is that it is collapsing visually but it is not setting the accordion section as collapsed so I have to double click in order to open that section again.

Any workaround?

@sfratini
Copy link
Author

sfratini commented Jan 3, 2018

Solved!

The issue was that my content view, or wrapper for the renderContent had a flex style. I am not 100% sure why, but checking on the onLayout method of that content, it was saying that it had 0 height when I made an action or click inside that content.

Replacing the flex: 1 for height: '100%' did the trick.

Final style:

content: {
      height: '100%',
      alignItems: 'center',
      justifyContent: 'space-around',
    },

Weird issue. I am not closing this one yet since I think there are some other issues related to this and could be the same base problem. Feel free to close when ready.

@iRoachie
Copy link
Collaborator

iRoachie commented Jan 4, 2018

Glad to see that you resolved it @sfratini. I'll keep it open for a bit so others could see

@zwessels
Copy link

zwessels commented Jan 6, 2018

Maybe add it to the Wiki for future reference rather than keeping the issue open for a bit?

Will also help out people in future once the issue has been closed.

@iRoachie
Copy link
Collaborator

iRoachie commented Jan 7, 2018

@pokkie Would you mind adding a page to the Wiki?

@iRoachie iRoachie closed this as completed Jan 7, 2018
@zwessels
Copy link

zwessels commented Jan 7, 2018

@iRoachie added a page. bit lazy at the moment, but at least there is something there :)

@iRoachie
Copy link
Collaborator

iRoachie commented Jan 7, 2018

Looks good for now 🙂

@kishanbharda
Copy link

kishanbharda commented Aug 19, 2019

I didn't get it. Can anybody explain me how can I solve it.

I have one Collapsible, in this Collapsible view I have another Collapsible view. Now after opening parent Collapsible view if i am going to open child Collapsible view then It opening but it's hide behind the another component.

How Can I solve it @iRoachie ?

@jenipharachel
Copy link

Alright, making sure my content view (the wrapper for all the renderItem) does not have any margin or padding (AKA, moving the margin and padding to the children) made it collapse all the way.

The issue right now is that it is collapsing visually but it is not setting the accordion section as collapsed so I have to double click in order to open that section again.

Any workaround?

@sfratini Hey, Is there a way to keep the accordian open even after the click event? I got a couple of click events in my accordian content and after a click event, the accordian seems to close up but according to my state, they are still active.

@sfratini
Copy link
Author

Alright, making sure my content view (the wrapper for all the renderItem) does not have any margin or padding (AKA, moving the margin and padding to the children) made it collapse all the way.
The issue right now is that it is collapsing visually but it is not setting the accordion section as collapsed so I have to double click in order to open that section again.
Any workaround?

@sfratini Hey, Is there a way to keep the accordian open even after the click event? I got a couple of click events in my accordian content and after a click event, the accordian seems to close up but according to my state, they are still active.

@jenipharachel
mmm I'll have to assume that the state that is changing is not yours, but the internal state of the accordion and it is not re acting to your prop change, because yours actually did not change.

I dont remember the code, as I digged thought this like 2 years ago, but the Touchable in the accordion must be catching the touch before yours.

I would add some console or debugging into the accordion code (it is all JS) and see what is triggering it. Or you could try to see what happens is you toggle and reset the prop from your parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants