Accordion Index [pt2]
Issue Description
I am also trying to figure out how to get the index of the opened accordion. I'm trying to add a switch within the renderContent, but I would need to target that content's index for the onValueChange.
node, npm, react-native, react and native-base version, expo version if used, xcode version
"@expo/vector-icons": "^9.0.0", "expo": "^32.0.0", "native-base": "^2.10.0", "react": "16.5.0", "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
Expected behaviour
Be able to grab the index of the opened accordion
Actual behaviour
Steps to reproduce
const PropertyQRCodes = (props) => {
const _renderHeader = (item, expanded) => {
console.log(expanded)
return (
<View style={{
flexDirection: "row",
padding: 10,
alignItems: "center" ,
backgroundColor: expanded ? 'rgba(209, 208, 221, 0.6)' : "white" }}
>
{expanded ?
<Icon style={{ fontSize: 18 }} name="remove" />
:
<Icon style={{ fontSize: 18 }} name="add" />
}
<Text style={{ fontFamily: 'KarlaReg', color: '#43425D', marginLeft: 15, width: 100, marginRight: 60 }}>
{item.type}
</Text>
<Text style={{ fontFamily: 'KarlaReg', color: '#43425D' }}>
{item.building}
</Text>
<Text style={{ fontFamily: 'KarlaReg', color: '#43425D' }}>
{item.floor}
</Text>
</View>
);
}
const _renderContent = (item, i) => {
return (
<View style={{ backgroundColor: "rgba(209, 208, 221, 0.2)", padding: 10}} >
<View style={{flexDirection: 'row', marginBottom: 15}}>
<Text style={{ color: 'rgba(67, 66, 93, 0.54)', fontSize: 16, fontFamily: 'KarlaReg', width: 75, marginRight: 20}}>
CUSTOM INFO
</Text>
<Text style={{ fontFamily: 'KarlaReg'}}>
{item.content.customInfo}
</Text>
</View>
<View style={{flexDirection: 'row', marginBottom: 15}}>
<Text style={{ color: 'rgba(67, 66, 93, 0.54)', fontSize: 16, fontFamily: 'KarlaReg', width: 75, marginRight: 20}}>
REQUIRED?
</Text>
<Switch
value={item.content.required}
onValueChange={ () => props.handleToggle(i) }
/>
</View>
</View>
);
}
const { QRCodeData } = props
return (
<View>
<View>
<Text>TYPE</Text>
<Text>BLDG.</Text>
<Text>FLR.</Text>
</View>
<Accordion
dataArray={QRCodeData}
animation={true}
expanded={1}
renderHeader={_renderHeader}
renderContent={_renderContent}
/>
</View>
)
}
export default PropertyQRCodes
See docs: https://docs.nativebase.io/Components.html#accordion-def-headref
Hi @jacobjohn90 , you can use index = dataArray.findIndex(x => x.title === item.title); in _renderContent(item) function to get index of opened accordian. dataArray is nothing but your variable QRCodeData.
_renderContent(item) {
index = dataArray.findIndex(x => x.title === item.title);
console.log(index)
return (
<Text
style={{
backgroundColor: "#e3f1f1",
padding: 10,
fontStyle: "italic",
}}
>
{item.content}
</Text>
);
}
Hello everyone, I have created a PR adding the feature of getting Header index and Content index Here is the PR Link
https://github.com/GeekyAnts/NativeBase/pull/3182
and Here is the PR Link in native-base-docs
https://github.com/GeekyAnts/native-base-docs/pull/254
Hope for support of you guys, It is going to be my First Open source Contribution @hanykumar @Srishti-Sharma
Hi @iamadityaaz, thanks for your contribution. We are looking into #3182 .