探索React Native图像模态组件:react-native-image-modal
warning:
这篇文章距离上次修改已过194天,其中的内容可能已经有所变动。
import React from 'react';
import { View, Text, StyleSheet, Image } from 'react-native';
import Modal from 'react-native-modal';
const ImageModal = ({ image, visible, closeModal }) => {
return (
<Modal isVisible={visible} onBackdropPress={closeModal} backdropOpacity={0.9}>
<View style={styles.modalContainer}>
<Image style={styles.modalImage} source={image} />
</View>
</Modal>
);
};
const styles = StyleSheet.create({
modalContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modalImage: {
width: '90%',
height: '90%',
resizeMode: 'contain',
},
});
export default ImageModal;
这个代码实例展示了如何在React Native应用中使用react-native-modal
库来创建一个图片模态。它定义了一个ImageModal
组件,该组件接收image
、visible
和closeModal
三个props。visible
控制模态是否可见,而closeModal
是关闭模态的回调函数。模态中包含一个居中的图片,并且在点击背景时关闭模态。
评论已关闭