oblador / react-native-collapsible

Animated collapsible component for React Native, good for accordions, toggles etc
MIT License
2.46k stars 452 forks source link

integrate Collapsible buttons #237

Closed JerinBaby closed 6 years ago

JerinBaby commented 6 years ago

How to integrate collapsible buttons to collapsible header? collapsible

emurigar commented 6 years ago

Is it possible?

ThomasLarge commented 6 years ago

@emurigar @JerinBaby This is possible as I have used this the other day. There is a "isActive" prop that is used. below is the code I used. it needs to be the 3rd one in the function

_renderHeader(section, id, isActive) {
    return (
        <View style={listView.main}>
            {isActive ? (
                <View style={listView.innerActive}>
                    <Text style={listView.text}>{section.region}</Text>
                    <IconDown fontSize={10} color={colors.darkGreen} />
                </View>
            ) : (
                <View style={listView.inner}>
                    <Text style={listView.text}>{section.region}</Text>
                    <IconRight fontSize={16} color={colors.darkGreen} />
                </View>
            )}
        </View>
    );
}

You need to pass the prop into the renderHeader here is the component

<Accordion
   sections={this.state.data}
    renderHeader={this._renderHeader}
    renderContent={this._renderContent}
    touchableComponent={TouchableOpacity}
/>

I'm just switching the icon on the active prop. Let me know if you need a hand 👍

emurigar commented 6 years ago

@ThomasLarge thanks very much for your help!! I made it! Thanks again

ThomasLarge commented 6 years ago

@emurigar not a problem :)