Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set auto height for View with Navigator inside?

Tags:

react-native

I use the default components View and Navigator. Wrapping the Navigator inside a View, I want it to automatically get the height of the content (Navigator), but if I don't set an explicit height for the View component - the Navigator does not show, as if it had position: absolute.

If I add a Text component inside a View - the View automatically gets the height from the child Text component. But if I set 'height: auto' for View - this property doesn't work.

render() {
  return (
    <View style={{height: 'auto', backgroundColor: 'powderblue'}}>
      <Navigator
        initialRoute={{ title: 'My Initial Scene', index: 0 }}
        renderScene={(route, navigator) => {
          return (
            <MyScene title={route.title} />
          )
        }}
      />
    </View>
  )
}
like image 408
slava_slava Avatar asked Sep 18 '16 15:09

slava_slava


People also ask

How to add height flag in viewpager?

ViewPager found in the support library. If you are using ViewPager for flipping static height layouts then you can simply add height flag as hardcoded like: If you want to use ViewPager for flipping the layouts having different heights then this blog will be helpful to you.

Is there an auto-height option for the gallery?

05-02-2017 11:30 AM There is no auto-height for the gallery itself - the height of the gallery control is fixed. However, you can use what we call a gallery with flexible height, where the template (that is replicated for all items) can have different heights.

How to set the height of a column in a gallery?

1. Use custom gallery - Flexible Height 2. Use following expression for control's height - Len (ThisItem.Column)/N a. N - Try different denominators to set the height

How do I add a flexible height template to a gallery?

You need to create a gallery that has that property, once the gallery is added you cannot change whether it has a flexible height template or not. To add one, choose the last option in the gallery menu in the Insert tab: When you have that, you can add controls that have the AutoHeight property (text box, HTML Text) to the gallery template.


1 Answers

style={{height:'auto'}} will not work. You must use an integer or use flex. Here you can see an example of the options.

https://facebook.github.io/react-native/docs/height-and-width.html

Your code will look like this:

render() {
        return (
            <View style={{flex:1, backgroundColor: 'powderblue'}}>
                <Navigator
                    style={{flex:1}}
                    initialRoute={{ title: 'My Initial Scene', index: 0 }}
                    renderScene={(route, navigator) => {
                        return (
                            <MyScene
                                title={route.title}
                            />
                        )
                    }

                    }
                />
            </View>
        )
    }
like image 77
leo7r Avatar answered Oct 21 '22 08:10

leo7r