简体   繁体   中英

Why components gets shrinked when not wrapped in ScrollView in ReactNative?

I am creating a project following Stephen Grider tutorial but i really got stuck when my view shrinked when i didn't wrap with ScrollView.

Here is the code in github: https://github.com/jasonkoirala/Swipe

When I wrap my following code:

  render() {
  return (
  <ScrollView>
  <View>
      <Deck
        data={DATA}
        renderCard={this.renderCard.bind(this)}
      />
     </View>
  </ScrollView>
   );
 }
}

Here is the output I get when I wrap with ScrollView: 在此处输入图片说明

And, here is the output I get when I don't wrap with ScrollView: 在此处输入图片说明

I dont want to use ScrollView to wrap my content, instead I want with View , and I tried giving following style to the view but it didn't work.

`flex: 1,
backgroundColor: '#fffdff',
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0`

I have just started learning ReactNative can anyone help me with this and explain why it behaves this way. Thank You. PS: Please use react-native run-android or react-native run-ios in project folder whose download link is mentioned above.

I tried on your source code and found a solution.

I have removed flex:1 from image style (in App.js ) and from buttonStyle and it worked as expected.

Hope this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM