D
D
Denis Sokolov2021-07-24 12:21:47
React Native
Denis Sokolov, 2021-07-24 12:21:47

Why doesn't the button work?

For some reason, in the modal, the button does not work, but in other places it works everywhere

// Компонент modal где не работает кнопка
interface IModalSelect {
    modalVisible: boolean;
    setModalVisible: React.Dispatch<React.SetStateAction<boolean>>;
}

export const ModalSelect = ({ modalVisible, setModalVisible }: IModalSelect) => {
    function test() {
        setModalVisible(!modalVisible);
    }
    return (
        <Modal
            transparent={false}
            animationType="slide"
            visible={modalVisible}
            style={styles.modal}
            onRequestClose={() => {
                setModalVisible(!modalVisible);
            }}>
            <Text style={styles.title}>Выберите категорию</Text>
            <View style={styles.body}>
                <ModalItem title="TEST1" />
                <ModalItem title="TEST2" />
                <ModalItem title="TEST3" />
                <ModalItem title="TEST4" />
                <ModalItem title="TEST5" />
                <ModalItem title="TEST6" />
            </View>
            <View style={styles.footer}>
                <ButtonBold title="Выбрать" style={styles.button} onPress={test} /> ?/ Эта кнопка не работает
                <Button title="test" onPress={test} /> // Эта кнопка работает
            </View>
        </Modal>
    );
};

// Компонент кнопки которая не работает
interface IButtonBold {
    style: any;
    title: string;
    onPress: any;
}

export const ButtonBold = ({ style, title, onPress }: IButtonBold) => {
    return (
        <TouchableOpacity style={[styles.button, style]} activeOpacity={0.8} onPress={onPress}>
            <View>
                <Text style={styles.text}>{title}</Text>
            </View>
        </TouchableOpacity>
    );
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question