Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

react native - style Vs contentContainerStyle in ScrollView?

When I apply {alignItems: 'center', justifyContent: 'center'} to style prop, got following error,

ScrollView child layout must be applied through the contentContainerStyle prop

then applied same styling to contentContainerStyle and worked fine. I am unable to understand the basic difference between style and contentContainerStyle and when to use them.

I am assuming that when ScrollView is called, two views are called. style applicable to parent View and contentContainerStyle applicable to child View.

Please correct me if I am wrong. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're correct, think of it like this, ScrollView is a special kind of View, ScrollView has two parts:

  1. Container (the grey box), it's the outside View, its height can't exceed 100% of the window height

  2. Content (marked in blue) is the inner part, it can be higher than the window height, it's what's moving inside the container.

enter image description here

ScrollView style defines the outer container of the ScrollView, e.g its height and relations to siblings elements

ScrollView contentContainerStyle defines the inner container of it, e.g items alignments, padding, etc


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...