首页 > 解决方案 > 升级到 react-native 0.61.0 后,图像会覆盖元素的 backgroundColor

问题描述

将我的应用程序中的 react-native 库从版本 0.59.9 升级到 0.61.0 后,我遇到了非常奇怪的问题。该问题仅发生在 Android(模拟器和设备)上

首先,我应该提一下,自从第一次打开应用程序以来,这个问题就没有发生过。登录到应用程序后最常出现。处理完数据后,应用程序中元素的呈现会发生意外变化。

问题看起来像:

在此处输入图像描述

在此处输入图像描述

如您所见,图像覆盖了背景颜色,但奇怪的是它没有覆盖里面的铭文。大家有遇到过这样的问题吗?如何解决?可能是什么原因造成的?

我把代码片段放在下面。我再次强调:在应用程序初始化时不会出现问题,并且在升级库之前一切正常。

const ProfileHead = () => (
   <View>
      <LinearGradient
        colors={["rgba(3, 7, 20, 0)", "#030714"]}
        style={styles.backgroundGradient}
        start={{ x: 0.0, y: 0.0 }}
        end={{ x: 0.0, y: 1.0 }}
        locations={[0, 1]}
      />
      <Image
        source={require("../../assets/images/focusly_08.jpg")}
        style={styles.imageBackground}
      />
 </View>
);

<MainContainer style={{ paddingTop: 0 }} navbarHidden={true}>
  <StretchScroll
    stretchHeight={300}
    stretchComponent={<ProfileHead />}
    style={styles.scroll}
  >
    <View style={styles.userProfile}>
      <ProfileOval title={user.name ? user.name.charAt(0) : ""} />
      <Header style={styles.header}>{user.name}</Header>
    </View>
 ...
backgroundGradient: {
   position: "absolute",
   width: Dimensions.get("window").width,
   height: 200,
   zIndex: 2,
},
imageBackground: {
   width: Dimensions.get("window").width,
   position: "absolute",
   height: 200,
},
scroll: {
   zIndex: 3,
},
userProfile: {
   alignItems: "center",
   marginTop: 130,
},

标签: androidreactjsreact-native

解决方案


尝试升级到v0.61.2

根据变更日志:

此版本修复了 Android 上发生的阴影问题,并改进了 StatusBar API 以更好地支持 iOS 13 暗模式。


推荐阅读