Gabotronix's avatar

React Native: Issue when rendering with map and index

Hi everybody, I have a multi-step form and in the top header I want to show some kind if breadcumbs, I'm trying to make it so between each breadcumb there's a line but currently I can only show a line for the last case in my condition (in this case, between 3 and 4, when it should look something like:

1 - 2 - 3- 4

while currently I have:

1 2 3 - 4

Have a look at my image to know what I'm talking about:

https://i.imgur.com/EUqL9Q4.jpg

My code is as follows:

const [ steps, setSteps ] = useState([ { title:'Detalles' }, { title:'Horario' }, { title:'Fotos' }, { title:'Menu' } ]);

<View style={{ width:'100%', backgroundColor:'white',flexDirection:'row', alignItems:'center', justifyContent:'space-around', position:'relative' }}>
        {steps.map((step,index) => {return (
            <>
            <View style={{ flexDirection:'column',alignItems:'center',justifyContent:'center' }}>
            <TouchableOpacity onPress={ ()=>{ onStepPressed(index+1) } } style={{ width:30,height:30,borderRadius:30/2, ...venueStore.currentStep == index+1 ? { backgroundColor:'rgb(3,91,150)' } : { backgroundColor:'rgb(150,150,150)' }, alignItems:'center',justifyContent:'center' }}>
                <Text style={{ fontSize:14, color:'white' }}>{index+1}</Text>
            </TouchableOpacity>
            {/*<Text style={{ fontSize:14, color:'rgb(68,68,68)' }}>{step.title}</Text>*/}
            </View>
            { index == 0 || index == 1 || index == 2 && (<View style={{ width:45,height:2,backgroundColor:'rgb(68,68,68)' }}></View>)}
            </>
        )})}
        </View>

Any idea how I can achieve my desired result

0 likes
1 reply

Please or to participate in this conversation.