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

Cha*_*had 11 javascript ios reactjs react-native expo

我正在将TouchableOpacity与嵌套在其中的图像进行映射.它适用于Android,但在iOS上,图像是不可见的.仍然有一个75x75可触摸的不透明度,我可以点击但图像在弹出的模式中是不可见的,一般来说.

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

例如: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>
))}
Run Code Online (Sandbox Code Playgroud)

莫代尔:

<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>
Run Code Online (Sandbox Code Playgroud)

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

小智 1

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