reactNative中如何让TouchableOpacity包裹的TouchableOpacity不触发事件
要让一个包裹在TouchableOpacity中的TouchableOpacity不触发事件,可以通过设置其disabled属性为true来禁用它。
例如,下面的代码中,第二个TouchableOpacity不会触发事件,因为它的disabled属性被设置为true:
import React from 'react';
import { TouchableOpacity, Text } from 'react-native';
const App = () => {
return (
<TouchableOpacity onPress={() => console.log('Outer TouchableOpacity pressed')}>
<Text>Outer TouchableOpacity</Text>
<TouchableOpacity onPress={() => console.log('Inner TouchableOpacity pressed')} disabled={true}>
<Text>Inner TouchableOpacity</Text>
</TouchableOpacity>
</TouchableOpacity>
);
};
export default App;
在上面的例子中,当点击"Inner TouchableOpacity"时,不会触发任何事件。
原文地址: https://www.cveoy.top/t/topic/icEt 著作权归作者所有。请勿转载和采集!