简体   繁体   English

升级本机版本后图像未呈现

[英]Image not rendering after upgrading react native version

I created a new project in react-native 0.61.5 .我在 react-native 0.61.5 中创建了一个新项目。 My old project was runnning on 0.49.5 .我的旧项目在0.49.5运行

My images in my view are no longer rendering, this is what I'm getting:我视图中的图像不再呈现,这就是我得到的:

android模拟器的图像,在应该有图片的地方没有渲染图片

After porting all my code from my old project to my new project and installing the necessary dependencies everything worked as expected with the exception of the rendering of the image.将旧项目中的所有代码移植到新项目并安装必要的依赖项后,除图像渲染外,一切都按预期工作。 The image I'm using comes from a URI ( URI still working in browser ), and I'm fetching a new image every time an event is executing (swiping right)我正在使用的图像来自 URI( URI 仍在浏览器中工作),并且每次执行事件时我都会获取新图像(向右滑动)

Here is the code in question:这是有问题的代码:

  renderCard = (card, index) => {
    // https://source.unsplash.com/featured/?{dog}
    return (
      <View style={styles.card}>
        <Text style={styles.text}>card: {card} index: {index}</Text>
        <Image style={{width: 400, height: 400}} source={{uri: 'https://source.unsplash.com/400x400/?dog/' + index}}/>
      </View>
    )
  };

Here is my render method that makes the call to the renderCard method above:这是我的渲染方法,它调用上面的 renderCard 方法:

  render () {
    return (

      <View style={styles.container}>
        <View style={[styles.swiper]}>
        <Swiper
          ref={swiper => {
            this.swiper = swiper
          }}
          onSwiped={() => this.onSwiped('general')}
          onSwipedLeft={() => this.onSwiped('left')}
          onSwipedRight={() => this.onSwiped('right')}
          onSwipedTop={() => this.onSwiped('top')}
          onSwipedBottom={() => this.onSwiped('bottom')}
          onTapCard={this.swipeLeft}
          cards={this.state.cards}
          cardIndex={this.state.cardIndex}
          cardVerticalMargin     = {100}
          renderCard={this.renderCard}
          onSwipedAll={this.onSwipedAllCards}
          useViewOverflow    = {false}
          stackSize={3}
          stackSeparation={15}

          overlayLabels={{
            bottom: {
              title: 'BLEAH',
              style: {
                label: {
                  backgroundColor: 'black',
                  borderColor: 'black',
                  color: 'white',
                  borderWidth: 1
                },
                wrapper: {
                  flexDirection: 'column',
                  alignItems: 'center',
                  justifyContent: 'center'
                }
              }
            },
            left: {
              title: 'NOPEE',
              style: {
                label: {
                  backgroundColor: 'black',
                  borderColor: 'black',
                  color: 'white',
                  borderWidth: 1
                },
                wrapper: {
                  flexDirection: 'column',
                  alignItems: 'flex-end',
                  justifyContent: 'flex-start',
                  marginTop: 30,
                  marginLeft: -30
                }
              }
            },
            right: {
              title: 'LIKE',
              style: {
                label: {
                  backgroundColor: 'black',
                  borderColor: 'black',
                  color: 'white',
                  borderWidth: 1
                },
                wrapper: {
                  flexDirection: 'column',
                  alignItems: 'flex-start',
                  justifyContent: 'flex-start',
                  marginTop: 30,
                  marginLeft: 30
                }
              }
            },
            top: {
              title: 'SUPER LIKE',
              style: {
                label: {
                  backgroundColor: 'black',
                  borderColor: 'black',
                  color: 'white',
                  borderWidth: 1
                },
                wrapper: {
                  flexDirection: 'column',
                  alignItems: 'center',
                  justifyContent: 'center'
                }
              }
            }
          }}
          animateOverlayLabelsOpacity
          animateCardOpacity
          swipeBackCard
        >


        </Swiper>
        </View>
        <View style={[styles.rateBoxes]}>
          <Slider
            style={{width: 200, height: 40}}
            minimumValue={5}
            maximumValue={10}
          />
        </View>
      </View>
    )
  }
}

Update 1更新 1

I modified my code to try and render an image outside the Swiper method as such:我修改了我的代码以尝试在 Swiper 方法之外渲染图像,如下所示:

render () {
    return (

      <View style={styles.container}>
        <View style={styles.card}>
        <Text style={styles.text}>card:</Text>
        <Image style={{width: 400, height: 400}} source={{uri: 'https://source.unsplash.com/400x400/?dog/' + "1"}}/>
      </View>
      </View>
    )
  }
}

Interestingly enough, no image was rendered , This was what I got:有趣的是,没有渲染图像,这就是我得到的: android模拟器的图像,在应该有图片的地方没有渲染图片

And here is my stylesheet :这是我的样式表

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#4FD0E9'
  },
  swiper:{
    flex:1,
  },
  rateBoxes:{
    alignItems: 'center',
    padding: 10
  },
  card: {
    flex: 1,
    borderRadius: 4,
    borderWidth: 2,
    borderColor: '#E8E8E8',
    justifyContent: 'center',
    backgroundColor: 'white'
  },
  text: {
    textAlign: 'center',
    fontSize: 50,
    backgroundColor: 'transparent'
  },
  done: {
    textAlign: 'center',
    fontSize: 30,
    color: 'white',
    backgroundColor: 'transparent'
  }
})

Update 2更新 2

The package I am using for swiper is called react-native-deck-swiper.我用于 swiper 的包称为 react-native-deck-swiper。 Here is my package.json:这是我的 package.json:

{
  "name": "DogTinder",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-deck-swiper": "^1.6.7",
    "react-native-view-overflow": "0.0.4"
  },
  "devDependencies": {
    "@babel/core": "^7.7.4",
    "@babel/runtime": "^7.7.4",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.7.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.57.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

Try to replace the code with尝试将代码替换为

renderCard = (card, index) => {
  const imageUri = 'https://source.unsplash.com/400x400/?dog/' + index;
  return (
    <View style={styles.card}>
      <Text style={styles.text}>card: {card} index: {index}</Text>
      <Image style={{width: 400, height: 400}} source={{uri: imageUri }}/>
    </View>
  )
};

It appears your emulator is not connected to the internet:您的模拟器似乎未连接到互联网: 带有未连接互联网图标的模拟器的屏幕截图

To double check your emulator is connected to the internet, open a browser and try to go to Google.要仔细检查您的模拟器是否已连接到互联网,请打开浏览器并尝试访问 Google。

If no webpage is diplayed try the following to solve your issue:如果没有显示网页,请尝试以下操作来解决您的问题:

  1. On your emulator go to settings -> turn off wifi and turn off data and turn on again and it will fix in some cases在您的模拟器上转到设置 -> 关闭 wifi 并关闭数据并再次打开,它会在某些情况下修复

  2. Completely close out of your emulator and re-start it.完全关闭模拟器并重新启动它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM