Content hidden behind TabBarIOS with React Native

3.2k views Asked by At

I'm building an iOS app with React Native and am implementing a TabBarIOS. The content on the tabs seems to flow behind and be obscured by the bar. In xcode I would have just unchecked the "extend edges" boxes but am not sure how to do this with React Native.

Here's an abbreviated version of what I'm trying to do. The <View> from CreateUser flows behind the tab bar. Is there an easy way to make sure content doesn't get obscured by the tab bar?

import React from 'react'
import {
  StyleSheet,
  Text,
  TextInput,
  View,
  TouchableHighlight,
} from 'react-native'

export default class TabBar extends React.Component {
  state = {
    selectedTab: 'list'
  }

  render() {
    return (
      <TabBarIOS selectedTab={this.state.selectedTab}
        unselectedTintColor="#ffffff"
        tintColor="#ffe429"
        barTintColor="#294163">

        <TabBarIOS.Item 
          title="My List"
          systemIcon="bookmarks"
          selected={this.state.selectedTab==='list'}
          onPress={() => {
              this.setState({
                  selectedTab: 'list',
              });
          }}
          >
          <CreateUser />
        </TabBarIOS.Item>
      </TabBarIOS>
    );
  }
}


var styles = StyleSheet.create({
  tabContent: {
    flex: 1,
    alignItems: 'center',
  },
  tabText: {
    color: 'darkslategrey',
    margin: 50,
  },
});



export default class CreateUser extends React.Component{

    render(){
        return (
                <View style={styles.container}>
                    <TouchableHighlight style={styles.button}>
                        <Text style={styles.buttonText}>LOG IN</Text>
                    </TouchableHighlight>
                </View>
            )
    }

}



var styles = StyleSheet.create({
    container: {
        flex: 1,
        flexDirection: "column",
        justifyContent: "flex-end",
        alignItems: 'center',
    },
    button: {
        backgroundColor: "#ffe429",
        borderRadius: 3,
        height: 60,
        width: 200,
        margin: 7,
        //flex: 1,
        alignItems: "center",
        justifyContent: "center",
    },
    buttonText: {
        color: "#294163",
    }

})
2

There are 2 answers

1
Mark On BEST ANSWER

This was a problem for me when using a NavigatorIOS component that then rendered it's initialRoute component which contained a TabBarIOS component.

If this is the case for your scenario, you can fix it by using a ScrollView:

  1. Add the flex layout style to your NavigatorIOS:

    <NavigatorIOS
    initialRoute={{
        component: MyView,
        title: 'My View',
    }}
    style={{flex: 1}}
    />
    
  2. Use a ScrollView:

    <TabBarIOS>
    <TabBarIOS.Item
      systemIcon="history"
      title="A Tab">
      <ScrollView>
        <Text>
          Hello World
        </Text>
      </ScrollView>
    </TabBarIOS.Item>
    </TabBarIOS>
    
0
blwinters On

In my case I needed to add flex: 1 to the style props for the top-level View of the screen.

RN Navigation docs

//MyScreen.tsx

export default () => (
  <View style={{ flex: 1 }}>
  ...
  </View>
)