React Native - iOS - 本地图像不可见(适用于安卓)



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

这是如何工作的? 我正在使用世博SDK文件系统来获取每个图像的路径。

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

我将其推送到我的状态并将其映射到组件中。 require(( 函数不适用于我这样做的方式。我认为这纯粹是渲染的问题。

地图代码:

{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>

用于获取图像路径的代码。(注意:我尝试不从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});
}

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

最新更新