首页 > 解决方案 > 当我将它嵌套在 Modal 中时,TouchableHighlight 不起作用

问题描述

我在其他屏幕(不是模态)中使用了touchablehighlight,它们工作正常。但我不明白为什么当我把它放在模态时它不能正常工作。如果我把按钮,它的作品。这是我的代码的一部分:请帮助我!

import React,{useState} from 'react'
import {
    View,
    Text,
    Modal,
    Button
    } from 'react-native';

 import { TouchableHighlight } from 'react-native-gesture-handler';
 const Icons = () => {
    const [modalVisible, setModalVisible] = useState(true);
    console.log(modalVisible)
    return (    
        <View >
            <TouchableHighlight 
            onPress={()=>setModalVisible(!modalVisible) }
            >
                <Text>Son</Text>
            </TouchableHighlight>
            <Modal
            visible={modalVisible}
            >
        <View >
            <View style={{marginBottom: 100, }}>
            <Text style={{fontSize:30}} >Hoşgeldiniz</Text>
            </View>
            <View style={''}>
                
            <TouchableHighlight 
            onPress={ () => setModalVisible(!modalVisible) }
            >
                <Text>Sağol</Text>
            </TouchableHighlight>
            </View>
            </View>
            </Modal>
        </View>
    )
}

标签: react-native-androidtouchablehighlight

解决方案


我也有同样的问题。从“react-native”导入 TouchableHighlight。但我不知道为什么当我从手势导入时它不起作用。


推荐阅读