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

ScrollView: overflow style is getting overridden #1427

Open
z0al opened this issue Aug 31, 2019 · 8 comments
Open

ScrollView: overflow style is getting overridden #1427

z0al opened this issue Aug 31, 2019 · 8 comments
Labels
priority: low project:react-native-web Issue associated with react-native-web

Comments

@z0al
Copy link

z0al commented Aug 31, 2019

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.
@giuseppeg
Copy link
Contributor

giuseppeg commented Sep 1, 2019

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.

@swyxio
Copy link

swyxio commented Sep 1, 2019

interesting. would you accept a PR to fix?

@giuseppeg
Copy link
Contributor

giuseppeg commented Sep 1, 2019

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*)

@swyxio
Copy link

swyxio commented Sep 1, 2019

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

@necolas necolas added this to the 0.12.0 milestone Oct 7, 2019
@necolas necolas changed the title StyleSheet: overflow style using StyleSheet.create is getting overridden ScrollView: overflow style is getting overridden Nov 19, 2019
@necolas
Copy link
Owner

necolas commented Nov 19, 2019

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).

@necolas necolas removed this from the 0.12.0 milestone Nov 19, 2019
@fadak0828
Copy link

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😂

@avlonder
Copy link

avlonder commented Oct 1, 2020

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

@necolas necolas added this to the 0.18 milestone Mar 29, 2021
@necolas necolas added the project:react-native-web Issue associated with react-native-web label Jul 2, 2022
@necolas necolas modified the milestones: 0.20: Image, 0.21: ScrollView Aug 24, 2022
@stuckj
Copy link

stuckj commented Feb 8, 2024

@avlonder, I don't know what use case you're having problems with. But, in my case, I had a margin on my scroll view and wanted a small icon that overlaps the margin (via negative margin) to not get clipped. My only workaround was to wrap the contents with another view, take the margin out of the scrollview and put it on this wrapper view, and set its overflow to be visible. This achieved the same visual affect.

Not sure if that helps you in your case, but thought I'd share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low project:react-native-web Issue associated with react-native-web
Projects
None yet
Development

No branches or pull requests

7 participants