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:

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?
Notes:
{overflow: 'scroll'} directly to the <ScrollView> component (i.e without using StyleSheet.create API). overflowY instead of overflow but TypeScript will complain.<ScrollView> or not, suggestions are welcome.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
Most helpful comment
This could be avoided if I change how ScrollView is built, but you probably shouldn't be using
overflowat all onScrollView, as it's not support in React Native and theScrollViewhas thehorizontalprop for configuring the scroll direction (doesn't support both directions at once).