impl navbar plugin
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "DoricLibrary.h"
|
||||
|
||||
#include "plugin/DoricModalPlugin.h"
|
||||
#include "plugin/DoricNavBarPlugin.h"
|
||||
#include "plugin/DoricNavigatorPlugin.h"
|
||||
#include "plugin/DoricNetworkPlugin.h"
|
||||
#include "plugin/DoricNotificationPlugin.h"
|
||||
@@ -33,6 +34,7 @@ DoricRegistry::DoricRegistry() {
|
||||
registerNativePlugin<DoricStoragePlugin>("storage");
|
||||
registerNativePlugin<DoricNotificationPlugin>("notification");
|
||||
registerNativePlugin<DoricNavigatorPlugin>("navigator");
|
||||
registerNativePlugin<DoricNavBarPlugin>("navbar");
|
||||
|
||||
registerViewNode<DoricRootNode>("Root");
|
||||
registerViewNode<DoricStackNode>("Stack");
|
||||
|
@@ -39,6 +39,7 @@ SOURCES += \
|
||||
loader/DoricAssetJSLoader.cpp \
|
||||
loader/DoricJSLoaderManager.cpp \
|
||||
plugin/DoricModalPlugin.cpp \
|
||||
plugin/DoricNavBarPlugin.cpp \
|
||||
plugin/DoricNavigatorPlugin.cpp \
|
||||
plugin/DoricNetworkPlugin.cpp \
|
||||
plugin/DoricNotificationPlugin.cpp \
|
||||
@@ -131,6 +132,7 @@ HEADERS += \
|
||||
loader/DoricJSLoaderManager.h \
|
||||
plugin/DoricModalPlugin.h \
|
||||
plugin/DoricNativePlugin.h \
|
||||
plugin/DoricNavBarPlugin.h \
|
||||
plugin/DoricNavigatorPlugin.h \
|
||||
plugin/DoricNetworkPlugin.h \
|
||||
plugin/DoricNotificationPlugin.h \
|
||||
|
259
doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp
Normal file
259
doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp
Normal file
@@ -0,0 +1,259 @@
|
||||
#include "DoricNavBarPlugin.h"
|
||||
|
||||
#include "engine/DoricPromise.h"
|
||||
#include "shader/DoricViewNode.h"
|
||||
#include "utils/DoricUtils.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QQmlComponent>
|
||||
|
||||
void DoricNavBarPlugin::isHidden(QString jsValueString, QString callbackId) {
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
|
||||
if (navbar != nullptr) {
|
||||
bool hidden = !(navbar->isVisible());
|
||||
|
||||
QVariantList args;
|
||||
args.append(hidden);
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setHidden(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
bool hidden = jsValue["hidden"].toBool();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, hidden] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
navbar->setVisible(!hidden);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setTitle(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
QString titleString = jsValue["title"].toString();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, titleString] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QQuickItem *title = navbar->findChild<QQuickItem *>("title");
|
||||
title->setProperty("text", titleString);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setBgColor(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
QString bgColor = DoricUtils::doricColor(jsValue["color"].toInt()).name();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, bgColor] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
navbar->setProperty("color", bgColor);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setLeft(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, jsValue] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QString viewId = jsValue["id"].toString();
|
||||
QString type = jsValue["type"].toString();
|
||||
|
||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||
if (viewNode == nullptr) {
|
||||
viewNode = DoricViewNode::create(getContext(), type);
|
||||
viewNode->setId(viewId);
|
||||
viewNode->init(nullptr);
|
||||
}
|
||||
|
||||
viewNode->blend(jsValue["props"]);
|
||||
|
||||
QQuickItem *left = navbar->findChild<QQuickItem *>("left");
|
||||
foreach (QQuickItem *child, left->childItems()) {
|
||||
child->setParentItem(nullptr);
|
||||
child->deleteLater();
|
||||
}
|
||||
viewNode->getNodeView()->setParentItem(left);
|
||||
|
||||
getContext()->addHeadNode(TYPE_LEFT, viewNode);
|
||||
|
||||
DoricLayouts *layout = (DoricLayouts *)(viewNode->getNodeView()
|
||||
->property("doricLayout")
|
||||
.toULongLong());
|
||||
layout->apply(QSizeF(navbar->width(), navbar->height()));
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setRight(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, jsValue] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QString viewId = jsValue["id"].toString();
|
||||
QString type = jsValue["type"].toString();
|
||||
|
||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||
if (viewNode == nullptr) {
|
||||
viewNode = DoricViewNode::create(getContext(), type);
|
||||
viewNode->setId(viewId);
|
||||
viewNode->init(nullptr);
|
||||
}
|
||||
|
||||
viewNode->blend(jsValue["props"]);
|
||||
|
||||
QQuickItem *right = navbar->findChild<QQuickItem *>("right");
|
||||
foreach (QQuickItem *child, right->childItems()) {
|
||||
child->setParentItem(nullptr);
|
||||
child->deleteLater();
|
||||
}
|
||||
viewNode->getNodeView()->setParentItem(right);
|
||||
|
||||
getContext()->addHeadNode(TYPE_RIGHT, viewNode);
|
||||
|
||||
DoricLayouts *layout = (DoricLayouts *)(viewNode->getNodeView()
|
||||
->property("doricLayout")
|
||||
.toULongLong());
|
||||
layout->apply(QSizeF(navbar->width(), navbar->height()));
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
||||
|
||||
void DoricNavBarPlugin::setCenter(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
getContext()->getDriver()->asyncCall(
|
||||
[this, callbackId, jsValue] {
|
||||
QQuickItem *navbar = getContext()
|
||||
->getQmlEngine()
|
||||
->rootObjects()
|
||||
.at(0)
|
||||
->findChild<QQuickItem *>("navbar");
|
||||
if (navbar != nullptr) {
|
||||
QString viewId = jsValue["id"].toString();
|
||||
QString type = jsValue["type"].toString();
|
||||
|
||||
DoricViewNode *viewNode = getContext()->targetViewNode(viewId);
|
||||
if (viewNode == nullptr) {
|
||||
viewNode = DoricViewNode::create(getContext(), type);
|
||||
viewNode->setId(viewId);
|
||||
viewNode->init(nullptr);
|
||||
}
|
||||
|
||||
viewNode->blend(jsValue["props"]);
|
||||
|
||||
QQuickItem *center = navbar->findChild<QQuickItem *>("center");
|
||||
foreach (QQuickItem *child, center->childItems()) {
|
||||
child->setParentItem(nullptr);
|
||||
child->deleteLater();
|
||||
}
|
||||
viewNode->getNodeView()->setParentItem(center);
|
||||
|
||||
getContext()->addHeadNode(TYPE_CENTER, viewNode);
|
||||
|
||||
DoricLayouts *layout = (DoricLayouts *)(viewNode->getNodeView()
|
||||
->property("doricLayout")
|
||||
.toULongLong());
|
||||
layout->apply(QSizeF(navbar->width(), navbar->height()));
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
} else {
|
||||
QVariantList args;
|
||||
args.append("Not implement NavBar");
|
||||
DoricPromise::reject(getContext(), callbackId, args);
|
||||
}
|
||||
},
|
||||
DoricThreadMode::UI);
|
||||
}
|
34
doric-Qt/example/doric/plugin/DoricNavBarPlugin.h
Normal file
34
doric-Qt/example/doric/plugin/DoricNavBarPlugin.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef DORICNAVBARPLUGIN_H
|
||||
#define DORICNAVBARPLUGIN_H
|
||||
|
||||
#include <QQuickItem>
|
||||
|
||||
#include "DoricExport.h"
|
||||
|
||||
#include "DoricNativePlugin.h"
|
||||
|
||||
static QString TYPE_LEFT = "navbar_left";
|
||||
static QString TYPE_RIGHT = "navbar_right";
|
||||
static QString TYPE_CENTER = "navbar_center";
|
||||
|
||||
class DORIC_EXPORT DoricNavBarPlugin : public DoricNativePlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using DoricNativePlugin::DoricNativePlugin;
|
||||
|
||||
Q_INVOKABLE void isHidden(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setHidden(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setTitle(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setBgColor(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setLeft(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setRight(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void setCenter(QString jsValueString, QString callbackId);
|
||||
};
|
||||
|
||||
#endif // DORICNAVBARPLUGIN_H
|
Reference in New Issue
Block a user