gpt4 book ai didi

javascript - React Native - iOS - 本地镜像不可见(适用于 android)

转载 作者:可可西里 更新时间:2023-11-01 03:00:10 30 4
gpt4 key购买 nike

我正在映射 TouchableOpacity,其中嵌套了一个图像。它在 Android 上运行良好,但在 iOS 上图像是不可见的。我仍然可以点击 75x75 的可触摸不透明度,但图像在弹出的模态中是不可见的,而且通常是不可见的。

这是如何运作的?我正在使用 Expo SDK FileSystem 获取每个图像的路径。

例如:file://path/to/container/progress/myfilehash.jpg

我将其推送到我的状态并将其映射到组件中。 require() 函数将无法按照我这样做的方式工作。我认为这纯粹是渲染的问题。

map 代码:

{this.state.images.map((val, key) => (
<TouchableOpacity
key={key}
onPress={() => this.setState({active: val, modal: true})}
>
<Image
style={{width: 75, height: 75}}
source={{isStatic: true, uri: val}}
/>
</TouchableOpacity>
))}

模态:

<Container style={Colors.Backdrop}>
<Header style={Colors.Navbar}>
<Left>
<TouchableHighlight
onPress={() => {
this.setState({modal: false})
}}>
<Icon
name="arrow-back"
style={{color: 'white'}}
/>
</TouchableHighlight>
</Left>
<Body></Body>
<Right>
<TouchableOpacity
onPress={() => {
this._deleteImage(this.state.active);
}}>
<Text
style={[
Colors.ErrorText, {
fontSize: 24,
marginRight: 10
}
]}>&times;</Text>
</TouchableOpacity>
</Right>
</Header>
<Content>
<View
style={{flex: 1}}
>
<FitImage
source={{uri: this.state.active}}
/>
</View>
</Content>
</Container>

获取图片路径的代码。 (注意:我尝试不 chop 来自 ios 的“file://”,结果完全相同)

_getAllImagesInDirectory = async() => {
let dir = await FileSystem.readDirectoryAsync(FileSystem.documentDirectory + 'progress');

dir.forEach((val) => {
this.state.images.push(Platform.OS === 'ios' ? FileSystem.documentDirectory.substring(7, FileSystem.documentDirectory.length) : FileSystem.documentDirectory + 'progress/' + val);
});

await this.setState({images: this.state.images, loading: false});
}

最佳答案

我也遇到过一次这个问题,我通过将图像粘贴到根文件夹中然后在图像标记的源中使用该路径来解决它。

关于javascript - React Native - iOS - 本地镜像不可见(适用于 android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52009251/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com