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

标签 javascript ios reactjs react-native expo

我正在映射 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/

相关文章:

javascript - css - bootstrap carousel 依赖项,需要导入哪些文件才能工作

javascript - AngularJS Controller 函数最佳实践

ios - 更少的 Storyboard序列和更多的代码是否会使应用程序更快/更小?

iPhone iOS 如何将 Class 对象与另一个类对象进行比较?

ios - Swift 和来自父类(super class)的属性继承

javascript - react : Conditional Rendering Of Components And Arrays

javascript - 一切都很好,除了标签。 (HTML,CSS,JS)

javascript - 为什么不在 Backbone.js 中设置集合?

html - 缺少有效的YouTube API key

reactjs - 在next.js中获取客户端当前的url