【问题标题】:Adding navbar buttons to react-native-navigation while using react-native-meteor在使用 react-native-meteor 时将导航栏按钮添加到 react-native-navigation
【发布时间】:2017-01-16 19:21:59
【问题描述】:

我将react-native-navigationreact-native-meteor 结合使用。从 Meteor 1.3 开始,建议在使用 React 时使用 createContainer 方法。但是,如果我从类定义中删除“导出默认值”并将其移动到导出默认值 createContainer(params=>{...}, MyClass),我会丢失导航栏按钮的定义。我应该如何编写它以不松散我的导航栏按钮的定义?谢谢:)

这是我的组件的全部代码:

import React, {Component} from 'react';
import {
  Text,
  View,
  StyleSheet,
} from 'react-native';
import Meteor, { createContainer } from 'react-native-meteor';

class TestScreen extends Component {
    static navigatorButtons = {
        rightButtons: [{
            title: 'Reset',
            id: 'resetButton'
        }, {
            title: 'Submit',
            id: 'submitButton'
        }]
    };
    constructor(props) {
        super(props);
        this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(
            this));
    }
    render() {
        return ( < View > < Text > Some text < /Text>
      </View > );
    }
    onNavigatorEvent(event) {
        if (event.type == 'NavBarButtonPress') {
            if (event.id == 'resetButton') {
                // reset here
            }
            if (event.id == 'submitButton') {
                // submit here
            }
        }
    }
}
export default createContainer(params => {
    const handle = Meteor.subscribe('records');
    return {
        records: Meteor.collection('records').findOne(),
    };
}, TestScreen);

【问题讨论】:

  • 我对“静态”糖的了解有限,您确定要在这种情况下使用它吗?您可以只提供一个“get”方法来检索变量。
  • 这就是 react-native-navigation 文档的建议。还有其他方法可以定义导航栏按钮吗?

标签: javascript react-native


【解决方案1】:

您可以在导航器上动态设置它们:

this.props.navigator.setButtons({
  rightButtons: [
    { title: 'Reset', id: 'resetButton' },
    { title: 'Submit', id: 'submitButton' }
  ]
});

【讨论】:

    猜你喜欢
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多