Wix RNN v3 Navigation.pop() 回调?

Wix RNN v3 Navigation.pop() callback?

我正在使用 Wix 的 react-native-navigation V3。我需要知道是否有办法在 Navigation.pop() 完成执行时调用函数。

我的具体案例场景如下。 我有 3 个堆栈选项卡按钮,我可以在其中推送一个新屏幕并弹出。 一切正常,除了我需要从那个推送的屏幕转到另一个选项卡的情况。如果我直接合并选项来更改 currentTabIndex,bottomTabs 将消失。发现我必须先 pop() 然后 mergeOptions。

有没有办法做到这一点?当我 运行 都在同一个函数中时,只有 pop() 被触发,我需要为此添加一些同步。

这是我当前的堆栈结构:

const startTabs = () => {
    Navigation.setRoot({
        root: {
            bottomTabs: {
                animate: true,
                visible: false,
                drawBehind: true,
                elevation: 8,
                waitForRender: true,
                children: [
                    {
                        stack: {
                            id: 'MainTabStack',
                            children: [
                                {
                                    component: {
                                        id: 'MainTab',
                                        name: 'app.MainTab'
                                    }
                                }
                            ],
                            options: {
                                bottomTab: {
                                    text: i18n.t('home'),
                                    icon: iconsMap['home-light'],
                                    selectedIcon: iconsMap['home-solid'],
                                    ...navigatorStyle
                                }
                            }
                        }
                    },
                    {
                        stack: {
                            id: 'MyProfileTabStack',
                            children: [
                                {
                                    component: {
                                        id: 'MyProfileTab',
                                        name: 'app.MyProfileTab'
                                    }
                                }
                            ],
                            options: {
                                bottomTab: {
                                    text: i18n.t('myProfile'),
                                    icon: iconsMap['user-light'],
                                    selectedIcon: iconsMap['user-solid'],
                                    ...navigatorStyle
                                }
                            }
                        }
                    },
                    {
                        stack: {
                            id: 'MessageTabStack',
                            children: [
                                {
                                    component: {
                                        id: 'MessageScreen',
                                        name: 'app.MessageScreen'
                                    }
                                }
                            ],
                            options: {
                                bottomTab: {
                                    text: i18n.t('messages'),
                                    icon: iconsMap['message-light'],
                                    selectedIcon: iconsMap['message-solid'],
                                    badgeColor: 'red',
                                    ...navigatorStyle
                                }
                            }
                        }
                    }
                ]
            }
        }
    });
}

所以我从 MainTab 开始,然后从这个 MainTab 推送一个新屏幕。我们将其命名为 SingleViewScreen。当我在 SingleViewScreen 中完成一些操作时,通过 onPress 函数我需要 pop() 当前屏幕并直接转到 MessageScreen。

有什么想法吗?难道我做错了什么?谢谢

您可以使用registerCommandCompletedListener

当命令(即 push、pop、showModal 等)在本机中完成执行时调用。如果命令包含动画,例如推送屏幕动画,则在动画结束后调用侦听器。

试试这个

// Subscribe
const commandCompletedListener = Navigation.events().registerCommandCompletedListener(({ commandId, completionTime, params }) => {

});
...
// Unsubscribe
commandCompletedListener.remove();