如何在React Navigation中有选择地显示模态?

时间:2018-06-29 14:47:04

标签: react-native react-navigation

我正在构建一个与iOS上的“日历”应用非常相似的应用。我有一个基于标签的应用,有时会根据显示的屏幕触发模态和其他时间卡片。在Apple的Google日历应用中,如果您单击某个事件,则将获得正常的(从侧面滑动或“卡片”)过渡,但是如果您单击“ +”按钮,则将获得模式(底部向上)过渡。我想实现类似的目标。现在的问题是我只能获得所有模态或所有卡的过渡。

const CalendarTab = createStackNavigator(
    {
        CalendarView: {screen: CalendarView},
        ViewEvent: {screen: ViewEvent}, // This should be a "card" transition
        AddEvent: {screen: AddEvent}, // This should be a "modal" transition
    },
    {
        mode: "modal", // This shouldn't be hard-coded
        initialRouteName: "CalendarView",
    }
);

const TabStack = createBottomTabNavigator({
    Calendar: CalendarTab,
    Settings: SettingsTab,
},
{
    initialRouteName: "Calendar",
    navigationOptions: ({ navigation }) => ({
        tabBarVisible: navigation.state.index === 0, // This should only apply to modals
    });
}

export default class App extends Component {
    render() {
        return <TabStack />;
    }
}

编辑:我确实在这里找到了部分解决方案:https://github.com/react-navigation/react-navigation/issues/707#issuecomment-299859578,但它会导致标头混乱,并且通常是一种脆弱的解决方案。

0 个答案:

没有答案