最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Inline backgroundColor Not Applying to <View> - Stack Overflow

programmeradmin3浏览0评论

I'm working on a React-Native project where I need to dynamically change the backgroundColor of a <View>. However, the inline style does not seem to apply, even when using a fixed color like "blue".

Here is my component code:

<View
  style={[
    styles.fullHeightRedBar,
    { backgroundColor: item?.MemberProductColorCode || "blue" }
  ]}
/>

And my stylesheet:

const styles = StyleSheet.create({
  fullHeightRedBar: {
    width: 16,
    position: "absolute",
    left: 0,
    top: 0,
    bottom: 0,
    borderTopLeftRadius: 10,
    borderBottomLeftRadius: 10,
    // backgroundColor: "red",  // (Removed to allow dynamic override)
  },
});
  1. Checked the value of MemberProductColorCode:

    console.log(item?.MemberProductColorCode); correctly prints values like "#FF0000" and "green", but the color still doesn’t apply.

  2. Tested a fixed color:

    Even backgroundColor: "blue" does not change the <View>.

  3. Checked parent styles:

    • No display: "none", overflow: "hidden", or opacity: 0.
    • Other child components render fine.
  4. Checked for position: "absolute" issues:

    Removing position: "absolute" didn’t help.

发布评论

评论列表(0)

  1. 暂无评论