question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScrollView child layout must be applied through the contentContainerStyle prop

See original GitHub issue

Version

1.4.6

Reproduction

import styled from 'styled-components/native';

const Scroll = styled.ScrollView`
  align-items: 'center';
`;

this code throws an error

ScrollView child layout (["alignItems"]) must be applied through the contentContainerStyle prop.

Expected Behavior

I’d expect styled components would apply the property to the correct element.

Actual Behavior

I ended up writing

const styles = StyleSheet.create({
  center: {
    alignItems: 'center',
  },
});

<ScrollView contentContainerStyle={styles.center}>
    {children}
</Scroll>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:41
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

51reactions
xsokevcommented, Jul 14, 2017

I was able to perform this using the following:

const Scroll = styled.ScrollView.attrs({
  contentContainerStyle: props => {
    return {
      alignItems: 'center',
      justifyContent: 'center'
    }
  }
})``
34reactions
kolkol69commented, Sep 29, 2019

If you are using react native with typescript, you can use it like this

const StyledScrollView = styled.ScrollView.attrs(() => ({
  contentContainerStyle: {
    alignItems: 'center',
  },
}))``;
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - ScrollView child layout must be applied through ...
Use contentContainerStyle props instead of style props. contentContainerStyle={styles.wrapper}.
Read more >
[Solved]-ScrollView child layout must be applied through the ...
Coding example for the question ScrollView child layout must be applied through the contentContainerStyle prop-Reactjs.
Read more >
scrollview child layout justifycontent must be applied
scrollview child layout ( justifycontent ) must be applied through the contentcontainerstyle prop ; 1. //change your style prop in the scrollview ......
Read more >
ScrollView child layout must be applied through the ... - iTecNote
Javascript – ScrollView child layout must be applied through the contentContainerStyle prop ... I am using react native swiper. and this error was...
Read more >
Developers - ScrollView child layout must be applied through ...
ScrollView child layout must be applied through the contentContainerStyle prop. css-components. 11 May 2017 Posted by piuccio ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found