React-native-web: ScrollView: overflow style is getting overridden

Created on 31 Aug 2019  路  7Comments  路  Source: necolas/react-native-web

The problem

I have a simple ScrollView component that looks like this:

function Scrollable(props) {
    return (
        <ScrollView
            style={styles.view}
        ></ScrollView>
    );
}

const styles = StyleSheet.create({
    view: {
        // This style is getting overridden by "overflow-y: auto; overflow-x: hidden"
        overflow: 'scroll'
    }
});

However, my style is getting overridden by other classes:

Screenshot from 2019-08-31 11-36-38

How to reproduce

Simplified test case: https://codesandbox.io/s/react-native-kxit2

Steps to reproduce: Use the same sample above and check the stylesheet output

Expected behavior

I'm expecting the styles passed to the style attribute should always take precedence (unless the component internally does override s) to internal styles.

Environment (include versions). Did this work in previous versions?

  • Did this work in previous versions? I don't know.
  • React Native for Web (version): 0.11.7
  • React (version): 16.9.0
  • Browser: Any

Notes:

  • To work around this I have to pass {overflow: 'scroll'} directly to the <ScrollView> component (i.e without using StyleSheet.create API).
  • Or use overflowY instead of overflow but TypeScript will complain.
  • Also, I'm not sure if this is actually the intended behavior of <ScrollView> or not, suggestions are welcome.
low

Most helpful comment

This could be avoided if I change how ScrollView is built, but you probably shouldn't be using overflow at all on ScrollView, as it's not support in React Native and the ScrollView has the horizontal prop for configuring the scroll direction (doesn't support both directions at once).

All 7 comments

This behavior is correct, longhand properties are more specific than shorthand. Probably react native for web could use the shorthand for the defaults overflow: hidden auto.

interesting. would you accept a PR to fix?

I think that the shorthand form is discouraged because of this resolution mechanism.

longhand properties are more specific than shorthand

Imagine if we fix the primitive by switching to the shorthand form and then we create a wrapper which sets overflowY: 'scroll' and accepts a style prop for overrides. The consumer passes style={{ overflow: 'hidden' }} and all of the sudden we have the same issue that the OP reported.

Eventually it is @necolas' call because he has more context (iirc the old resolution mechanism was a bit different and probably wouldn't result in this *bug*)

i see. in what situations would RNW create such a wrapper? is this a common scenario?

This could be avoided if I change how ScrollView is built, but you probably shouldn't be using overflow at all on ScrollView, as it's not support in React Native and the ScrollView has the horizontal prop for configuring the scroll direction (doesn't support both directions at once).

I met same issue.
In my case, using a styled component solved it.

function Scrollable(props) {
    return (
        <StyledScrollView/>
    );
}

const StyledScrollView = styled.ScrollView`
        overflow-x: scroll;
        overflow-y: scroll;
`;

I don't know why this works馃槀

I met same issue.
In my case, using a styled component solved it.

function Scrollable(props) {
  return (
      <StyledScrollView/>
  );
}

const StyledScrollView = styled.ScrollView`
        overflow-x: scroll;
        overflow-y: scroll;
`;

I don't know why this works

Thanks!
Unfortunately, I tried this for a horizontal FlatList, but it doesn't work. Also, explicitly appending {overflow: 'visible'} to the style property did not work. Any ideas?

edit: I'm talking about react-native, not react-native-web

Was this page helpful?
0 / 5 - 0 ratings