diff --git a/doric-Qt/example/app/main.qml b/doric-Qt/example/app/main.qml index 1797c900..453dc8bb 100644 --- a/doric-Qt/example/app/main.qml +++ b/doric-Qt/example/app/main.qml @@ -175,4 +175,16 @@ ApplicationWindow { navbar.visible = false } } + + function navigatorPopToRoot() { + while (stack.depth > 1) { + stack.pop() + } + + if (stack.depth > 1) { + navbar.visible = true + } else { + navbar.visible = false + } + } } diff --git a/doric-Qt/example/doric/plugin/DoricNavigatorPlugin.cpp b/doric-Qt/example/doric/plugin/DoricNavigatorPlugin.cpp index 65c2a182..7f5b23e2 100644 --- a/doric-Qt/example/doric/plugin/DoricNavigatorPlugin.cpp +++ b/doric-Qt/example/doric/plugin/DoricNavigatorPlugin.cpp @@ -92,6 +92,20 @@ void DoricNavigatorPlugin::popSelf(QString jsValueString, QString callbackId) { } void DoricNavigatorPlugin::popToRoot(QString jsValueString, - QString callbackId) {} + QString callbackId) { + getContext()->getDriver()->asyncCall( + [this] { + QObject *window = getContext()->getQmlEngine()->rootObjects().at(0); + QMetaObject::invokeMethod(window, "navigatorPopToRoot"); + }, + DoricThreadMode::UI); + + getContext()->getDriver()->asyncCall( + [this, callbackId] { + QVariantList args; + DoricPromise::resolve(getContext(), callbackId, args); + }, + DoricThreadMode::JS); +} void DoricNavigatorPlugin::openUrl(QString jsValueString, QString callbackId) {}