NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Accordion Index [pt2]

Open jacobjohn90 opened this issue 7 years ago • 4 comments

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

jacobjohn90 avatar Feb 05 '19 19:02 jacobjohn90

See docs: https://docs.nativebase.io/Components.html#accordion-def-headref

Srishti-Sharma avatar Jul 30 '19 11:07 Srishti-Sharma

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> ); }

hanykumar avatar Mar 05 '20 07:03 hanykumar

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

iamadityaaz avatar Jul 10 '20 05:07 iamadityaaz

Hi @iamadityaaz, thanks for your contribution. We are looking into #3182 .

hanykumar avatar Aug 17 '20 10:08 hanykumar