react-native-navbar: passProps seem doesn't work

I call this.props.navigator.push to the next scene, and pass some props to the next scene, and caught an error, the passed prop is undefined in the next view,it seems passProps doesn’t work,and code is below:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');
var Product = require('./product');
var Adapt = require('./adapt');

var mdskip = require('./data/mock-mdskip');
var context = require('./data/mock-context');
var NavigationBar = require('react-native-navbar');

var Detail = require("./ui/detail");
var styles = require("./ui/style");
var {
  Navigator,
  NavigatorIOS,
  AppRegistry,
  View,
  Text,
  StyleSheet,
  TouchableHighlight,
  ScrollView
} = React;

var product = new Product();
product.set("context", context.ModuleDatas);
product.set("config", context.TDetail);
product.set("mdskip", Adapt.transform(mdskip));
product.set("deviceType", "phone");

var RootComponent = React.createClass({
  getInitialState: function(){
    return {};
  },
  componentDidMount: function() {
    var self = this;
  },
  renderScene: function(route, navigator) {
    var product = this.state.product;

    var Component = route.component;
    var navBar = route.navigationBar;

    if (navBar) {
      navBar = React.addons.cloneWithProps(navBar, {
        navigator: navigator,
        route: route
      });
    }

    return (
      <View style={styles.navigator}>
        {navBar}
        <Component navigator={navigator} route={route} product={product} />
      </View>
    );
  },
  render: function() {

    if(context){
      return (
        <Navigator
        style={styles.navigator}
        renderScene={this.renderScene}
        initialRoute={{
          component: Entrance,
          navigationBar: <NavigationBar
            title="Initial View"
            onNext={this.handleNext}
          />
        }}
      />
      );
    }else{
      return (
        <View></View>
      )
    }
  }
});

var Entrance = React.createClass({
  render: function(){
    return (
      <View style={styles.clickMe}>
        <TouchableHighlight onPress={this.onPress} underlayColor="#B5B5B5">
          <Text style={styles.clickMeText}>点我看详情</Text>
        </TouchableHighlight>
      </View>
    );
  },
  componentDidMount(){
    var self = this;
    product.onLoad(["context", "config", "mdskip"], function(context, config, mdskip){
      self.setState({
        "context": context,
        "config": config,
        "mdskip": mdskip
      });
    })
  },
  onPress: function(){
    var context = this.state.context;
    var config = this.state.config;
    var mdskip = this.state.mdskip;
    var product = this.props.product;

    this.props.navigator.push({
      title: context.title.itemTitle,
      component: DetailMain,
      backButtonTitle: 'Back',
      passProps: { config: config, mdskip: mdskip, product: product, context: context}
    });
  }
});

var DetailMain = React.createClass({
  getInitialState: function(){
    return {
      loading: false
    };
  },
  render: function(){
    return (
      <Detail config={this.props.config} mdskip={this.props.mdskip} product={this.props.product} context={this.props.context} navigator={this.props.navigator}/>
    )
  }
})

AppRegistry.registerComponent('DetailNative', () => RootComponent);

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

那么,它(导航栏)改变了很多,因为在这里的最后一个注释。你使用哪种版本?你能为我们提供一个代码示例?@Yidada

P.S. Google translate FTW!

I solve this problem by rendering scenes this way <Component {...route.passProps} navigator={navigator} route={route} />

Solved the Problem though if pass props worked it could have been better feature request?