Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image nested views inherit backgroundColor style from Image #763

Closed
aliaksandr-kazarez opened this issue Apr 8, 2015 · 5 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@aliaksandr-kazarez
Copy link

In following code snippet, if i set backgroundColor for Image, Text inherits it's value and covers section of image

var view = React.createClass({
    render: function() {
        return (
            <Image
                source={require("image!image")}
                style={{width: 300, height: 400, backgroundColor: "#FFDDCC"}}
                >
            <Text>TSDGFSDF</Text>
            </Image>
        )
    }
});

"react-native": "~0.3.8"

@brentvatne
Copy link
Collaborator

@kozorezal - What is the expected behaviour? What happens if you do this for an <img> tag in the browser?

@aliaksandr-kazarez aliaksandr-kazarez changed the title Image is not working with backgroundColor style set Image nested views inherit backgroundColor style from Image Apr 8, 2015
@aliaksandr-kazarez
Copy link
Author

@brentvatne initial issue was renamed, since it's related to style inheritance.

Answering your question, in browser I use background-image instead of nesting html inside image tag.

@frantic
Copy link
Contributor

frantic commented Apr 8, 2015

For performance, instead of having all elements background color transparent, we propagate it from parent to child. I think you can explicitly set background color on <Text>. cc @sahrens

@aliaksandr-kazarez
Copy link
Author

Thanks @frantic your answer helped, besides it's possible to wrap <Image> with <View> and set backgroundColor: "#FFDDCC" to it and "transparent" to <Image>

@mtrabelsi
Copy link

So reading the some bugs here and there and checking CSS doc again, then yeah react-native advertise that it supporting CSS but that is not true, this is different implementation :
In the standard https://developer.mozilla.org/en-US/docs/Web/CSS/background-color it is NOT inheritable by child - and W3C did that decision for a reason ;)
React native did another implementation and this is quite annoying to manually reset the child background to avoid any unwanted inheritance :)

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants