使用MobX商店值动态设置React Navigation屏幕标题的方法?

时间:2017-12-23 00:32:42

标签: react-native react-navigation mobx

在我的默认“React Navigation”选项卡屏幕上,我想将屏幕标题设置为MobX商店中的值。我的理解是,唯一的方法是通过参数传递值 - 所以我不能只将MobX值放在'title:'字段中......但是因为这是'默认'屏幕我我没有传递任何东西。

默认屏幕:

<?php if( $featured_restaurants ): ?>
<?php foreach ( $featured_restaurants as $featured_restaurant ): ?>

<div class="card__inputs"> <!-- Featured card specific icons start -->

<?php
    if(in_array('alcohol', $restaurant_features)):
        $feature_icon = "Alcohol";
    endif;

    if(in_array('family_friendly', $restaurant_features)):
        $feature_icon = "Family-Friendly";
    endif;

    if(in_array('open_late', $restaurant_features)):
        $feature_icon = "Open-Late";
    endif;

    if(in_array('parking', $restaurant_features)):
        $feature_icon = "Parking";
    endif;
?>

    <div class="details u-float-left"> <!-- Featured card specific icons container start -->
    <span class="icon icon--medium icon--Italian"></span>
    <?php if($restaurant_features): ?>
        <?php foreach($restaurant_features as $restaurant_feature): ?>
            <span class="icon icon--medium icon--<?php echo $feature_icon; ?>"></span>
        <?php endforeach; ?>
    <?php endif; ?>

    </div> <!-- Featured card specific icons container end -->

    </div> <!-- Featured card specific icons end -->

<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>

我试图在componentWillMount期间使用setParams,但是console.log告诉我它必须发生得太晚,所以我在标题中得到一个空对象。

知道怎么做吗?

1 个答案:

答案 0 :(得分:0)

今天遇到了同样的问题并且弄清楚了。

只需将InteractiveShell.ast_node_interactivity = "last_expr" 更改为函数而不是对象,这样就会重新评估状态更改。如https://reactnavigation.org/docs/intro/headers#Header-interaction-with-screen-component手册

所述,这是您的修复方法
navigationOptions