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

React v15: inline styles with fallbacks (eg: display: flex) do not work #131

Closed
MoOx opened this issue Apr 28, 2016 · 6 comments
Closed

Comments

@MoOx
Copy link
Contributor

MoOx commented Apr 28, 2016

Hi,

I am just starting with react-native-web and I am not using (yet?) the AppRegistry.
I just configured the react-native alias to be able to start using some component.
I made a simple test with a View with childrens. This view is a navigation bar and I want to use flexbox.

/* @flow */

import { Element } from "react"
import React, { StyleSheet, View, Text } from "react-native"

import * as colors from "../colors.js"

type Props = {
  styles: Object,
  leftChildren: ReactClass,
  children: Element,
  rightChildren: ReactClass,
}

const NavigationBar = (props: Props): Element => {
  const {
    leftChildren: Left,
    rightChildren: Right,
  } = props

  return (
    <View
      style={ {
        ...styles.bar,
        ...props.styles,
      } }
      accessibilityRole={ "menubar" }
    >
      <View style={ styles.left }>
        { Left && <Left /> }
        <Text>{ "logo" }</Text>
      </View>
      <View style={ styles.center }>
        { props.children }
      </View>
      <View style={ styles.right }>
        { Right && <Right /> }
      </View>
    </View>
  )
}

NavigationBar.defaultProps = {
  styles: {},
  leftChildren: null,
  children: null,
  rightChildren: null,
}

const styles = StyleSheet.create({
  bar: {
    display: "flex",
    flexGrow: 1,
    flexDirection: "row",
    justifyContent: "space-between",
    padding: "1rem",

    color: colors.white.toString(),
    backgroundColor: colors.blue.toString(),
  },
  left: {
    display: "flex",
    justifyContent: "flex-start",
  },
  center: {
    display: "flex",
    justifyContent: "center",
  },
  right: {
    display: "flex",
    justifyContent: "flex-end",
  },
})

export default NavigationBar

As you might notice, I specified display: "flex" for styles.bar since I was thinking it's missing. You mentioned in the doc that it should be the default (just like for facebook/css-layout), but I tried just in case. And even when adding this property, it was "ignored". I tried on Chrome and Firefox, same thing.

Am I missing the "global" default css somehow?

@MoOx
Copy link
Contributor Author

MoOx commented Apr 28, 2016

I want to add that I am checking the missing "display: flex" using DOM dev tools, and if I add it by hand using inline styles element, it "works" (yeah it's weird to say "it works" for this case).

@MoOx
Copy link
Contributor Author

MoOx commented Apr 29, 2016

screen shot 2016-04-29 at 11 47 57

After some digging, I found that the "bug" came from inline-style-prefix-all.
Well it doesn't seems to be a real bug. "Just" an incompatibility with React v15 (which now use createElement and not innerHTML anymore).

A change has just been pushed recently to inline-style-prefix-all robinweser/inline-style-prefix-all#7 (following robinweser/inline-style-prefixer#78)

Not sure why I am getting inline styles and not CSS tho. I didn't find anything clear enough in to "trigger" CSS (which should help in my case).

@MoOx MoOx changed the title View doesn't add (ignore?) display: "flex" to the element styles React v15: styles with fallbacks (eg: display: flex) do not work Apr 29, 2016
@MoOx MoOx changed the title React v15: styles with fallbacks (eg: display: flex) do not work React v15: inline styles with fallbacks (eg: display: flex) do not work Apr 29, 2016
@necolas
Copy link
Owner

necolas commented Jun 14, 2016

I think this is ok in 0.0.25. When I upgrade the prefixer I'll check that things are handled correctly.

@bmcmahen
Copy link

bmcmahen commented Jun 19, 2016

I'm running into the same issue. display: flex is not being added to any of my view elements when using inline-styles. It works fine when using AppRegistry, however.

@necolas
Copy link
Owner

necolas commented Jun 20, 2016

Don't use React 15 with [email protected]. It requires a peer dependency of React 0.0.14.

@necolas
Copy link
Owner

necolas commented Jun 22, 2016

This issue is pretty bad because React 15 has no way to handle fallback values now. It was an undocumented feature, but used by many styling libraries, and there is no alternative API yet. To unblock most browsers I'm going to drop all fallbacks and render with the standard value. Can work out how to extend browser support after that.

@necolas necolas closed this as completed Jun 22, 2016
@necolas necolas reopened this Jun 22, 2016
jeduden pushed a commit to jeduden/react-native-web that referenced this issue Jul 8, 2016
React 15 has no way to handle fallback CSS values (for example, vendor
prefixed 'display:flex' values) in inline styles. This patch drops all
fallback values for inline styles at the cost of regressing browser
support (those without standard flexbox support will not layout React
Native components correctly).

Fix necolas#131

Conflicts:
	package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants