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)
},
});
Checked the value of
MemberProductColorCode
:console.log(item?.MemberProductColorCode);
correctly prints values like"#FF0000"
and"green"
, but the color still doesn’t apply.Tested a fixed color:
Even backgroundColor: "blue" does not change the
<View>
.Checked parent styles:
- No
display: "none"
,overflow: "hidden"
, oropacity: 0
. - Other child components render fine.
- No
Checked for
position: "absolute"
issues:Removing
position: "absolute"
didn’t help.