在自定义反应导航标题中获取导航道具

时间:2018-02-18 03:38:50

标签: javascript reactjs react-native react-navigation

我的(简单)React Navigation StackNavigator中有一个自定义标题,如下所示:

module.exports.myFunction = function() {
    const myFnEventEmitter = new(require('events').EventEmitter)();
    var job = new CronJob('00 0-59 * * * *', function() {
            var a = 5;
            var b = 2;

            myFnEventEmitter.emit('started', a + b)

        }, function() {},
        true
    );
    return myFnEventEmitter;
}

但这会返回const myFnEventEmitter = Tester.myFunction(); myFnEventEmitter.on('started', data => { console.log("Done!"); console.log(data); req.flash('success', "You have successfully started the software!"); res.render('dashboard'); })

如何将视图的唯一标题传递给自定义标题?

1 个答案:

答案 0 :(得分:0)

根据文档,您需要navigationOptions作为访问navigation的函数:

navigationOptions: ({ navigation }) => ({
       headerTitle: <GradientHeader title={navigation.state.params.title} />,
    }),