Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigatorIOS component not visible when used within TabBarIOS #759

Closed
hacksparrow opened this issue Apr 8, 2015 · 12 comments
Closed

NavigatorIOS component not visible when used within TabBarIOS #759

hacksparrow opened this issue Apr 8, 2015 · 12 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@hacksparrow
Copy link

The NavigatorIOS component is rendered but not visible when used within TabBarIOS. However, it is visible in the Chrome and Xcode debuggers.

Rendered App

app

Chrome Debugger View

chrome debugger view

Xcode Captured View Hierarchy
capture view hierarchy

App Code

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TabBarIOS,
  NavigatorIOS
} = React;

var ApplePage = React.createClass({
  render: function () {
    return (
      <View style={styles.view}>
        <Text style={styles.text}>Hello</Text>
        <Text style={styles.text}>World</Text>
      </View>
    )
  }
})

var MainView = React.createClass({

  getInitialState: function() {
    return {
      selectedTab: 'appleTab',
      notifCount: 0,
      presses: 0,
    };
  },

  render: function () {
    return (

      <TabBarIOS>
        <TabBarIOS.Item
          title="Apple Tab"
          icon={_icon('more')}
          selected={this.state.selectedTab === 'appleTab'}
          onPress={() => {
            this.setState({
              selectedTab: 'appleTab',
            });
          }}>

          <NavigatorIOS
            initialRoute={{
              title: 'Apple',
              component: ApplePage,
            }}
          />

        </TabBarIOS.Item>
      </TabBarIOS>
    )
  }
})

function _icon(imageUri) {
  return {
    uri: imageUri,
    isStatic: true
  };
}

var styles = React.StyleSheet.create({
  text: {
    color: 'black',
    backgroundColor: 'white',
    fontSize: 50,
    marginTop: 100
  },
  container: {
    flex: 1
  }
})

AppRegistry.registerComponent('MartialApp', () => MainView)
@angeloashmore
Copy link

I think this may be an issue with your styles as I have been able to implement what you are trying.

Try this out and see if it comes into view:

var styles = StyleSheet.create({

  // ...

  view: {
    alignItems: 'center',
    flex: 1,
    justifyContent: 'center',
  }

  // ...

});

@hacksparrow
Copy link
Author

Thanks for the suggestion, but it didn't have any effect. Maybe share a simplified version of your implementation?

@kennydee
Copy link
Contributor

kennydee commented Apr 9, 2015

Got the same problem here with a simpler version maybe :
Just replace the index.ios.js of a new project by this :

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  TabBarIOS,
  NavigatorIOS,
  View,
  Text,
} = React;

var myPage = React.createClass({
  render: function () {
    return (
      <View>
        <Text>Hello</Text>
        <Text>World</Text>
      </View>
    )
  }
})

var tabBar = React.createClass({
  render: function() {
    return (
       <TabBarIOS>
        <TabBarIOS.Item title="React Native" selected={true}>
          <NavigatorIOS initialRoute={{ title: 'React Native', component: myPage }} />
        </TabBarIOS.Item>
      </TabBarIOS>
    );
  }
});

AppRegistry.registerComponent('tabBar', () => tabBar);

Thanks

@nickhudkins
Copy link
Contributor

The View that NavigatorIOS creates has no dimensions, toss a style that has {flex: 1} on it, and paddingTop: 64, flex: 1 on the myPage View and you'll be all set :)

var styles = StyleSheet.create({
  nav: {
    flex: 1
  },
  myPage: {
    flex: 1,
    backgroundColor: 'orange',
    paddingTop: 64
  }
});

@meetwudi
Copy link
Contributor

@nickhudkins Good solution, thanks! I am facing this issue too. But the paddingTop: 64 appears to be a magic number, somehow. Is there any way to automatically inset view inside NavigatorIOS?

@kennydee
Copy link
Contributor

@nickhudkins Good catch. Thanks !
Now this works :

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  TabBarIOS,
  NavigatorIOS,
  View,
  Text,
  StyleSheet
} = React;

var myPage = React.createClass({
  render: function () {
    return (
      <View style={styles.myPage}>
        <Text>Hello</Text>
        <Text>World</Text>
      </View>
    )
  }
})

var tabBar = React.createClass({
  render: function() {
    return (
       <TabBarIOS>
        <TabBarIOS.Item title="React Native" selected={true}>
          <NavigatorIOS style={styles.nav} initialRoute={{ title: 'React Native', component: myPage }} />
        </TabBarIOS.Item>
      </TabBarIOS>
    );
  }
});

var styles = StyleSheet.create({
  nav: {
    flex: 1
  },
  myPage: {
    flex: 1,
    backgroundColor: 'orange',
    paddingTop: 64
  }
});

AppRegistry.registerComponent('tabBar', () => tabBar);

I think this is a little tricky anyway, and before closing this issue, maybe we can improve this ?
Maybe with a little bit of clarification in the docs ? or better, maybe do something in NavigatorIOS as what @tjwudi said ?

This is problematic i think for new users, because, this is basically the first example of React Native code you will see on the http://facebook.github.io/react-native/ website :) !

thanks all

@hacksparrow
Copy link
Author

This is clearly a documentation issue; #504 is also related to this.

As of now, the flex property is always required for NavigatorIOS to display its content. I will find the relevant doc file and send a PR.

Closing this.

@elado
Copy link

elado commented Apr 20, 2015

@hacksparrow Aside from the docs issue, @tjwudi has a good point about paddingTop: 64 being a magic number.

@nickhudkins
Copy link
Contributor

@elado, 64 may be a magic number in this case, but, the ability to place content under the header (since translucency is now a thing) is a feature and therefore the developer should be responsible for ensuring what content should display unobstructed by the header. It is a documented number, and not one that is worth querying for unless apple plans on releasing a new nav bar height sometime soon. (In my personal opinion). If this number COULD vary I would say let's do something different but I believe it can be treated effectively as a constant. That is, until apple releases iOS 12 and all of this goes out the window ;)

@bigparksh
Copy link

64 is just a magic number. It'll probably cause problems in future cases. You could solve the issue by wrapping the View within ScrollView in the render function.

<ScrollView>
    <View>
    </View>
</ScrollView>

@hzhu
Copy link

hzhu commented Oct 5, 2015

👍 @nickhudkins

@jerry-sjtu
Copy link

@nickhudkins Thanks for saving my time.

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

10 participants