navigator plugin implement push
This commit is contained in:
parent
6134937c48
commit
23522c6416
@ -83,9 +83,11 @@ QObject *DoricContext::obtainPlugin(QString name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricContext::setQmlEngine(QQmlEngine *engine) { mQmlEngine = engine; }
|
void DoricContext::setQmlEngine(QQmlApplicationEngine *engine) {
|
||||||
|
mQmlEngine = engine;
|
||||||
|
}
|
||||||
|
|
||||||
QQmlEngine *DoricContext::getQmlEngine() { return mQmlEngine; }
|
QQmlApplicationEngine *DoricContext::getQmlEngine() { return mQmlEngine; }
|
||||||
|
|
||||||
DoricViewNode *DoricContext::targetViewNode(QString id) {
|
DoricViewNode *DoricContext::targetViewNode(QString id) {
|
||||||
if (id == mRootNode->getId()) {
|
if (id == mRootNode->getId()) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef CONTEXT_H
|
#ifndef CONTEXT_H
|
||||||
#define CONTEXT_H
|
#define CONTEXT_H
|
||||||
|
|
||||||
#include <QQmlEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "DoricExport.h"
|
#include "DoricExport.h"
|
||||||
@ -21,7 +21,7 @@ private:
|
|||||||
QString extra;
|
QString extra;
|
||||||
QVariant initParams;
|
QVariant initParams;
|
||||||
DoricInterfaceDriver *driver = NULL;
|
DoricInterfaceDriver *driver = NULL;
|
||||||
QQmlEngine *mQmlEngine;
|
QQmlApplicationEngine *mQmlEngine;
|
||||||
|
|
||||||
QMap<QString, QMap<QString, DoricViewNode *>> mHeadNodes;
|
QMap<QString, QMap<QString, DoricViewNode *>> mHeadNodes;
|
||||||
|
|
||||||
@ -45,9 +45,9 @@ public:
|
|||||||
|
|
||||||
QObject *obtainPlugin(QString name);
|
QObject *obtainPlugin(QString name);
|
||||||
|
|
||||||
void setQmlEngine(QQmlEngine *engine);
|
void setQmlEngine(QQmlApplicationEngine *engine);
|
||||||
|
|
||||||
QQmlEngine *getQmlEngine();
|
QQmlApplicationEngine *getQmlEngine();
|
||||||
|
|
||||||
DoricViewNode *targetViewNode(QString id);
|
DoricViewNode *targetViewNode(QString id);
|
||||||
|
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
#include "DoricPanel.h"
|
#include "DoricPanel.h"
|
||||||
#include "shader/DoricRootNode.h"
|
#include "shader/DoricRootNode.h"
|
||||||
|
|
||||||
DoricPanel::DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem) {
|
DoricPanel::DoricPanel(QQmlApplicationEngine *qmlEngine,
|
||||||
|
QQuickItem *quickItem) {
|
||||||
mQmlEngine = qmlEngine;
|
mQmlEngine = qmlEngine;
|
||||||
mQuickItem = quickItem;
|
mQuickItem = quickItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
DoricPanel::~DoricPanel() {
|
DoricPanel::~DoricPanel() { delete mContext; }
|
||||||
delete mContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DoricPanel::config(QString script, QString alias, QString extra) {
|
void DoricPanel::config(QString script, QString alias, QString extra) {
|
||||||
DoricContext *context = DoricContext::create(script, alias, extra);
|
DoricContext *context = DoricContext::create(script, alias, extra);
|
||||||
|
@ -13,11 +13,11 @@ private:
|
|||||||
int renderedWidth = -1;
|
int renderedWidth = -1;
|
||||||
int renderedHeight = -1;
|
int renderedHeight = -1;
|
||||||
|
|
||||||
QQmlEngine *mQmlEngine;
|
QQmlApplicationEngine *mQmlEngine;
|
||||||
QQuickItem *mQuickItem;
|
QQuickItem *mQuickItem;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem);
|
DoricPanel(QQmlApplicationEngine *qmlEngine, QQuickItem *quickItem);
|
||||||
|
|
||||||
~DoricPanel();
|
~DoricPanel();
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "DoricLibrary.h"
|
#include "DoricLibrary.h"
|
||||||
|
|
||||||
#include "plugin/DoricModalPlugin.h"
|
#include "plugin/DoricModalPlugin.h"
|
||||||
|
#include "plugin/DoricNavigatorPlugin.h"
|
||||||
#include "plugin/DoricNetworkPlugin.h"
|
#include "plugin/DoricNetworkPlugin.h"
|
||||||
#include "plugin/DoricNotificationPlugin.h"
|
#include "plugin/DoricNotificationPlugin.h"
|
||||||
#include "plugin/DoricPopoverPlugin.h"
|
#include "plugin/DoricPopoverPlugin.h"
|
||||||
@ -31,6 +32,7 @@ DoricRegistry::DoricRegistry() {
|
|||||||
registerNativePlugin<DoricNetworkPlugin>("network");
|
registerNativePlugin<DoricNetworkPlugin>("network");
|
||||||
registerNativePlugin<DoricStoragePlugin>("storage");
|
registerNativePlugin<DoricStoragePlugin>("storage");
|
||||||
registerNativePlugin<DoricNotificationPlugin>("notification");
|
registerNativePlugin<DoricNotificationPlugin>("notification");
|
||||||
|
registerNativePlugin<DoricNavigatorPlugin>("navigator");
|
||||||
|
|
||||||
registerViewNode<DoricRootNode>("Root");
|
registerViewNode<DoricRootNode>("Root");
|
||||||
registerViewNode<DoricStackNode>("Stack");
|
registerViewNode<DoricStackNode>("Stack");
|
||||||
|
@ -37,6 +37,7 @@ SOURCES += \
|
|||||||
engine/v8/JSValueHelper.cpp \
|
engine/v8/JSValueHelper.cpp \
|
||||||
engine/v8/V8Executor.cpp \
|
engine/v8/V8Executor.cpp \
|
||||||
plugin/DoricModalPlugin.cpp \
|
plugin/DoricModalPlugin.cpp \
|
||||||
|
plugin/DoricNavigatorPlugin.cpp \
|
||||||
plugin/DoricNetworkPlugin.cpp \
|
plugin/DoricNetworkPlugin.cpp \
|
||||||
plugin/DoricNotificationPlugin.cpp \
|
plugin/DoricNotificationPlugin.cpp \
|
||||||
plugin/DoricPopoverPlugin.cpp \
|
plugin/DoricPopoverPlugin.cpp \
|
||||||
@ -125,6 +126,7 @@ HEADERS += \
|
|||||||
engine/v8/V8Executor.h \
|
engine/v8/V8Executor.h \
|
||||||
plugin/DoricModalPlugin.h \
|
plugin/DoricModalPlugin.h \
|
||||||
plugin/DoricNativePlugin.h \
|
plugin/DoricNativePlugin.h \
|
||||||
|
plugin/DoricNavigatorPlugin.h \
|
||||||
plugin/DoricNetworkPlugin.h \
|
plugin/DoricNetworkPlugin.h \
|
||||||
plugin/DoricNotificationPlugin.h \
|
plugin/DoricNotificationPlugin.h \
|
||||||
plugin/DoricPopoverPlugin.h \
|
plugin/DoricPopoverPlugin.h \
|
||||||
|
66
doric-Qt/example/doric/plugin/DoricNavigatorPlugin.cpp
Normal file
66
doric-Qt/example/doric/plugin/DoricNavigatorPlugin.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "DoricNavigatorPlugin.h"
|
||||||
|
|
||||||
|
#include "DoricPanel.h"
|
||||||
|
#include "engine/DoricPromise.h"
|
||||||
|
#include "utils/DoricUtils.h"
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQmlComponent>
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
void DoricNavigatorPlugin::push(QString jsValueString, QString callbackId) {
|
||||||
|
|
||||||
|
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||||
|
QJsonValue jsValue = document.object();
|
||||||
|
|
||||||
|
bool animated = true;
|
||||||
|
QString source = jsValue["source"].toString();
|
||||||
|
QString alias = source;
|
||||||
|
QJsonValue config = jsValue["config"];
|
||||||
|
|
||||||
|
if (config.isObject()) {
|
||||||
|
animated = config["animated"].toBool();
|
||||||
|
alias = config["alias"].toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
getContext()->getDriver()->asyncCall(
|
||||||
|
[this, alias] {
|
||||||
|
QString name = alias;
|
||||||
|
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||||
|
|
||||||
|
QQmlComponent component(getContext()->getQmlEngine());
|
||||||
|
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
|
||||||
|
component.loadUrl(url);
|
||||||
|
QObject *object = component.create();
|
||||||
|
QQuickItem *quickItem = qobject_cast<QQuickItem *>(object);
|
||||||
|
DoricPanel *panel =
|
||||||
|
new DoricPanel(getContext()->getQmlEngine(), quickItem);
|
||||||
|
quickItem->setWidth(600);
|
||||||
|
quickItem->setHeight(800);
|
||||||
|
panel->config(script, name, NULL);
|
||||||
|
|
||||||
|
QObject *window = getContext()->getQmlEngine()->rootObjects().at(0);
|
||||||
|
QVariant arg = QVariant::fromValue(object);
|
||||||
|
QMetaObject::invokeMethod(window, "navigatorPush",
|
||||||
|
Q_ARG(QVariant, arg));
|
||||||
|
},
|
||||||
|
DoricThreadMode::UI);
|
||||||
|
|
||||||
|
getContext()->getDriver()->asyncCall(
|
||||||
|
[this, callbackId] {
|
||||||
|
QVariantList args;
|
||||||
|
DoricPromise::resolve(getContext(), callbackId, args);
|
||||||
|
},
|
||||||
|
DoricThreadMode::JS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoricNavigatorPlugin::pop(QString jsValueString, QString callbackId) {}
|
||||||
|
|
||||||
|
void DoricNavigatorPlugin::popSelf(QString jsValueString, QString callbackId) {}
|
||||||
|
|
||||||
|
void DoricNavigatorPlugin::popToRoot(QString jsValueString,
|
||||||
|
QString callbackId) {}
|
||||||
|
|
||||||
|
void DoricNavigatorPlugin::openUrl(QString jsValueString, QString callbackId) {}
|
25
doric-Qt/example/doric/plugin/DoricNavigatorPlugin.h
Normal file
25
doric-Qt/example/doric/plugin/DoricNavigatorPlugin.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef DORICNAVIGATORPLUGIN_H
|
||||||
|
#define DORICNAVIGATORPLUGIN_H
|
||||||
|
|
||||||
|
#include "DoricExport.h"
|
||||||
|
|
||||||
|
#include "DoricNativePlugin.h"
|
||||||
|
|
||||||
|
class DORIC_EXPORT DoricNavigatorPlugin : public DoricNativePlugin {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
using DoricNativePlugin::DoricNativePlugin;
|
||||||
|
|
||||||
|
Q_INVOKABLE void push(QString jsValueString, QString callbackId);
|
||||||
|
|
||||||
|
Q_INVOKABLE void pop(QString jsValueString, QString callbackId);
|
||||||
|
|
||||||
|
Q_INVOKABLE void popSelf(QString jsValueString, QString callbackId);
|
||||||
|
|
||||||
|
Q_INVOKABLE void popToRoot(QString jsValueString, QString callbackId);
|
||||||
|
|
||||||
|
Q_INVOKABLE void openUrl(QString jsValueString, QString callbackId);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DORICNAVIGATORPLUGIN_H
|
Reference in New Issue
Block a user