[英]React-native Make image pop-up using lightbox
When using react native lightbox, the image pops up in the left side of the screen, but with the same size as defined in the image component.使用 react native lightbox 时,图像会在屏幕左侧弹出,但大小与图像组件中定义的大小相同。
I want the image to pop up in the center of the screen with a bigger size than before.我希望图像以比以前更大的尺寸在屏幕中央弹出。
Here is my code:这是我的代码:
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Pick an image from camera roll"
onPress={this._pickImage}
/>
<Lightbox onPress={() => this.enlargeImage(image)} >
{/* <TouchableOpacity onPress={() => this.enlargeImage(image)}> */}
<Image
source={{ uri: image }}
style={{ width: 200, height: 200 }}
/>
{/* </TouchableOpacity> */}
</Lightbox>
When i press the image i want to return the image in new size in the center of the screen:当我按下图像时,我想在屏幕中央以新尺寸返回图像:
enlargeImage = (image) => {
return (
<Lightbox>
<Image
source={{ uri: image }}
style={{ width: 500, height: 500 }}
resizeMode='center'
/>
</Lightbox>
)
}
You can use the renderContent
props of Lightbox ( docs ).您可以使用 Lightbox ( docs ) 的
renderContent
道具。 And doing something like that:并做这样的事情:
<Lightbox renderContent={()=> {
return(
<Image
source={require('./photo.png')}
style={{ width: 1000, height: 1000 }}
resizeMode='center'
/>
)
}}>
<Image
source={require('./photo.png')}
style={{ width: 500, height: 500 }}
resizeMode='center'
/>
</Lightbox>
I hope this will help somebody.我希望这会对某人有所帮助。
I think you should wrap the Lightbox
into a Button
.我认为您应该将
Lightbox
包装成Button
。 When you then size the container around it instead of the lightbox.然后当您围绕它而不是灯箱调整容器大小时。
<TouchableOpacity> style={{ margin: 5, width: width / 3 - 17, height: 110 }}
<Lightbox>
<Image
source={{ uri: image }}
style={{ width: 500, height: 500 }}
resizeMode='center'
/>
</Lightbox>
</TouchableOpacity>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.