I'm trying to pass the currently clicked item to the React-Native's own Modal component with props, but without success. Now it will only show the same item in all the modals regardless of what item was pressed.
Homepage that renders content and passes the data for Modal component:
<HomepageDataView>
{habitData !== null &&
Object.values(habitData).map((item, index) => (
<HomepageDataBox
key={index.toString()}
onPress={() => {
setModalVisible(true);
haptics.selection();
}}
style={{ borderBottomWidth: 7, borderBottomColor: `${item.color}` }}
>
<Image style={{ height: 50, width: 50 }} source={item.icon} />
<Text fontFamily="SemiBold" marginLeft="5px">
{item.name}
</Text>
<ShowHabitModal
data={item}
modalVisible={modalVisible}
setModalVisible={setModalVisible}
/>
</HomepageDataBox>
))}
</HomepageDataView>
Modal component:
export default function ShowHabitModal({ modalVisible, setModalVisible, data }) {
return (
<Modal animationType="slide" presentationStyle="pageSheet" visible={modalVisible}>
<ModalContent>
<HomeheaderContainer>
<TouchableOpacity
style={{ marginLeft: 10, marginTop: 10 }}
onPress={() => setModalVisible(false)}
>
<Ionicons name="close-circle-sharp" size={34} color="gray" />
</TouchableOpacity>
<TouchableOpacity>
<Text marginRight="15px" color={colors.mainGreen} fontFamily="SemiBold">
Edit
</Text>
</TouchableOpacity>
</HomeheaderContainer>
<ShowHabitDataContainer>
<View style={showHabitImageBackground}>
<Image style={{ width: 90, height: 90 }} source={data.icon} />
</View>
{data.description !== '' && <Text>{data.description}</Text>}
<Text fontFamily="SemiBold" marginTop="15px" twentyEight>
{data.name}
</Text>
<Text>{data.days}</Text>
<Text>{data.times}</Text>
</ShowHabitDataContainer>
</ModalContent>
</Modal>
);
}
modalVisiblein the parent component. I think multiple modals are being opened one after the another in your case, one behind the other.