我尝试在Image组件上使用pointerEvents={'none'}
,但在Android上不起作用。 在iOS上有效。
React Native Environment Info:
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 141.91 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.1.0 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 24, 26, 27, 28
Build Tools: 26.0.2, 27.0.3, 28.0.2, 28.0.3
System Images: android-24 | Google APIs Intel x86 Atom, android-27 | Intel x86 Atom_64, android-28 | Intel x86 Atom_64
IDEs:
Android Studio: 3.0 AI-171.4443003
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.9 => 0.59.9
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
export default class GeneralBackground extends PureComponent {
render() {
return (
<View style={styles.container}>
{this.props.children}
<Image
source={myImage}
style={styles.image}
pointerEvents={'none'} // Does not work on Android.
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.theme
},
image: {
width: 160,
resizeMode: 'stretch',
alignSelf: 'center',
position: 'absolute'
}
});
我希望像Button组件那样的this.props.children
可以工作,但上面的Image不能。 但是它可以通过测试在iOS上运行,Android失败了。 我是否误用了它? 我认为这可能是一个错误。
有人知道吗? 非常感谢。
嗨@ Amos729 ,
似乎pointerEvents
道具在Image
组件上不可用:在https://facebook.github.io/react-native/docs/image上搜索pointerEvents
没有。
我相信它仅适用于View
组件: https :
做这样的事情
<View style={styles2.image} pointerEvents={'none'}>
<Image source={myImage} />
</View>
让一个孩子Button
在Android上可点击。
希望有帮助!
@RobinCsl我尝试了您刚才所说的内容。 Android和iOS平台都非常有用。
非常感谢。
最有用的评论
嗨@ Amos729 ,
似乎
pointerEvents
道具在Image
组件上不可用:在https://facebook.github.io/react-native/docs/image上搜索pointerEvents
没有。我相信它仅适用于
View
组件: https :做这样的事情
让一个孩子
Button
在Android上可点击。希望有帮助!