diff --git a/doric-Qt/example/app/main.qml b/doric-Qt/example/app/main.qml
index 43e9511a..2747ee39 100644
--- a/doric-Qt/example/app/main.qml
+++ b/doric-Qt/example/app/main.qml
@@ -14,14 +14,28 @@ ApplicationWindow {
Rectangle {
id: navbar
+ objectName: "navbar"
visible: false
Layout.fillWidth: true
Layout.preferredHeight: 44
- Text {
- text: "Title"
- font.pixelSize: 16
- anchors.centerIn: parent
+ Rectangle {
+ anchors.fill: parent
+ color: "transparent"
+
+ Text {
+ anchors.centerIn: parent
+ objectName: "title"
+ font.pixelSize: 16
+ }
+
+ Rectangle {
+ anchors.centerIn: parent
+ objectName: "center"
+ color: "red"
+ width: childrenRect.width
+ height: childrenRect.height
+ }
}
RowLayout {
@@ -30,16 +44,15 @@ ApplicationWindow {
Layout.preferredWidth: 10
}
- Image {
- Layout.preferredWidth: 24
- Layout.preferredHeight: 24
- id: name
- source: "qrc:/doric/qml/doric_icon_back.png"
- }
+ RowLayout {
+ objectName: "left"
- Text {
- text: "Left"
- font.pixelSize: 16
+ Image {
+ Layout.preferredWidth: 24
+ Layout.preferredHeight: 24
+ id: name
+ source: "qrc:/doric/qml/doric_icon_back.png"
+ }
}
MouseArea {
@@ -55,9 +68,8 @@ ApplicationWindow {
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
- Text {
- text: "Right"
- font.pixelSize: 16
+ RowLayout {
+ objectName: "right"
}
Rectangle {
@@ -88,7 +100,7 @@ ApplicationWindow {
ListView {
id: list
width: content.width
- model: 23
+ model: 24
boundsBehavior: Flickable.StopAtBounds
function getSource(index) : string {
@@ -118,26 +130,28 @@ ApplicationWindow {
case 11:
return "ModularDemo.js"
case 12:
- return "NavigatorDemo.js"
+ return "NavBarDemo.js"
case 13:
- return "NetworkDemo.js"
+ return "NavigatorDemo.js"
case 14:
- return "NotificationDemo.js"
+ return "NetworkDemo.js"
case 15:
- return "PopoverDemo.js"
+ return "NotificationDemo.js"
case 16:
- return "ScrollerDemo.js"
+ return "PopoverDemo.js"
case 17:
- return "SimpleDemo.js"
+ return "ScrollerDemo.js"
case 18:
- return "SliderDemo.js"
+ return "SimpleDemo.js"
case 19:
- return "Snake.js"
+ return "SliderDemo.js"
case 20:
- return "StorageDemo.js"
+ return "Snake.js"
case 21:
- return "SwitchDemo.js"
+ return "StorageDemo.js"
case 22:
+ return "SwitchDemo.js"
+ case 23:
return "TextDemo.js"
}
}
diff --git a/doric-Qt/example/app/qml.qrc b/doric-Qt/example/app/qml.qrc
index 83da511f..1bbc859a 100644
--- a/doric-Qt/example/app/qml.qrc
+++ b/doric-Qt/example/app/qml.qrc
@@ -21,6 +21,7 @@
../../../doric-demo/bundle/src/LayoutTestDemo.js
../../../doric-demo/bundle/src/ModalDemo.js
../../../doric-demo/bundle/src/ModularDemo.js
+ ../../../doric-demo/bundle/src/NavBarDemo.js
../../../doric-demo/bundle/src/NavigatorDemo.js
../../../doric-demo/bundle/src/NetworkDemo.js
../../../doric-demo/bundle/src/NotificationDemo.js
diff --git a/doric-Qt/example/doric/DoricRegistry.cpp b/doric-Qt/example/doric/DoricRegistry.cpp
index 2695df74..a5305961 100644
--- a/doric-Qt/example/doric/DoricRegistry.cpp
+++ b/doric-Qt/example/doric/DoricRegistry.cpp
@@ -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("storage");
registerNativePlugin("notification");
registerNativePlugin("navigator");
+ registerNativePlugin("navbar");
registerViewNode("Root");
registerViewNode("Stack");
diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro
index 557376b5..e3aae23f 100644
--- a/doric-Qt/example/doric/doric.pro
+++ b/doric-Qt/example/doric/doric.pro
@@ -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 \
diff --git a/doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp b/doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp
new file mode 100644
index 00000000..df4d5d75
--- /dev/null
+++ b/doric-Qt/example/doric/plugin/DoricNavBarPlugin.cpp
@@ -0,0 +1,259 @@
+#include "DoricNavBarPlugin.h"
+
+#include "engine/DoricPromise.h"
+#include "shader/DoricViewNode.h"
+#include "utils/DoricUtils.h"
+
+#include
+#include
+#include
+
+void DoricNavBarPlugin::isHidden(QString jsValueString, QString callbackId) {
+ getContext()->getDriver()->asyncCall(
+ [this, callbackId] {
+ QQuickItem *navbar = getContext()
+ ->getQmlEngine()
+ ->rootObjects()
+ .at(0)
+ ->findChild("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("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("navbar");
+ if (navbar != nullptr) {
+ QQuickItem *title = navbar->findChild("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("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("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("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("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("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("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("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);
+}
diff --git a/doric-Qt/example/doric/plugin/DoricNavBarPlugin.h b/doric-Qt/example/doric/plugin/DoricNavBarPlugin.h
new file mode 100644
index 00000000..4ab307c1
--- /dev/null
+++ b/doric-Qt/example/doric/plugin/DoricNavBarPlugin.h
@@ -0,0 +1,34 @@
+#ifndef DORICNAVBARPLUGIN_H
+#define DORICNAVBARPLUGIN_H
+
+#include
+
+#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