diff --git a/doric-Qt/example/app/demo/DoricDemoBridge.cpp b/doric-Qt/example/app/demo/DoricDemoBridge.cpp index efb45f81..1ce8fc05 100644 --- a/doric-Qt/example/app/demo/DoricDemoBridge.cpp +++ b/doric-Qt/example/app/demo/DoricDemoBridge.cpp @@ -59,15 +59,18 @@ void DoricDemoBridge::navigate(QVariant route) { name = "SimpleDemo.js"; break; case 14: - name = "Snake.js"; + name = "SliderDemo.js"; break; case 15: - name = "StorageDemo.js"; + name = "Snake.js"; break; case 16: - name = "SwitchDemo.js"; + name = "StorageDemo.js"; break; case 17: + name = "SwitchDemo.js"; + break; + case 18: name = "TextDemo.js"; break; } diff --git a/doric-Qt/example/app/main.qml b/doric-Qt/example/app/main.qml index aa412253..4a5bb6e7 100644 --- a/doric-Qt/example/app/main.qml +++ b/doric-Qt/example/app/main.qml @@ -15,7 +15,7 @@ ApplicationWindow { ListView { width: parent.width - model: 18 + model: 19 delegate: Rectangle { Column { anchors.centerIn: parent @@ -51,12 +51,14 @@ ApplicationWindow { case 13: return "SimpleDemo.js" case 14: - return "Snake.js" + return "SliderDemo.js" case 15: - return "StorageDemo.js" + return "Snake.js" case 16: - return "SwitchDemo.js" + return "StorageDemo.js" case 17: + return "SwitchDemo.js" + case 18: return "TextDemo.js" } } diff --git a/doric-Qt/example/app/qml.qrc b/doric-Qt/example/app/qml.qrc index 935ca886..38d62c41 100644 --- a/doric-Qt/example/app/qml.qrc +++ b/doric-Qt/example/app/qml.qrc @@ -21,8 +21,9 @@ ../../../doric-demo/bundle/src/ModularDemo.js ../../../doric-demo/bundle/src/NetworkDemo.js ../../../doric-demo/bundle/src/PopoverDemo.js - ../../../doric-demo/bundle/src/SimpleDemo.js ../../../doric-demo/bundle/src/ScrollerDemo.js + ../../../doric-demo/bundle/src/SimpleDemo.js + ../../../doric-demo/bundle/src/SliderDemo.js ../../../doric-demo/bundle/src/Snake.js ../../../doric-demo/bundle/src/StorageDemo.js ../../../doric-demo/bundle/src/SwitchDemo.js diff --git a/doric-Qt/example/doric/async/DoricAsyncResult.cpp b/doric-Qt/example/doric/async/DoricAsyncResult.cpp index 32fca82a..16f52192 100644 --- a/doric-Qt/example/doric/async/DoricAsyncResult.cpp +++ b/doric-Qt/example/doric/async/DoricAsyncResult.cpp @@ -1,13 +1,31 @@ #include "DoricAsyncResult.h" +#include + DoricAsyncResult::DoricAsyncResult() {} -void DoricAsyncResult::setResult(QString result) { this->result = result; } +void DoricAsyncResult::setResult(QString result) { + this->result = result; + this->resultCallback(); +} void DoricAsyncResult::setError(QString exception) { this->result = exception; } -bool DoricAsyncResult::hasResult() { return !(result == EMPTY); } +bool DoricAsyncResult::hasResult() { return !(result.isEmpty()); } -QJSValue DoricAsyncResult::getResult() { return this->result; } +QString DoricAsyncResult::getResult() { return this->result; } -DoricSettableFuture *DoricAsyncResult::synchronous() { return NULL; } +QString DoricAsyncResult::waitUntilResult() { + if (hasResult()) { + return this->result; + } + + QMutex mutex; + QWaitCondition condition; + this->resultCallback = [&condition]() { condition.wakeAll(); }; + + mutex.lock(); + condition.wait(&mutex); + mutex.unlock(); + return this->result; +} diff --git a/doric-Qt/example/doric/async/DoricAsyncResult.h b/doric-Qt/example/doric/async/DoricAsyncResult.h index a9f1adba..efb161bf 100644 --- a/doric-Qt/example/doric/async/DoricAsyncResult.h +++ b/doric-Qt/example/doric/async/DoricAsyncResult.h @@ -1,17 +1,13 @@ #ifndef ASYNCRESULT_H #define ASYNCRESULT_H -#include +#include #include "DoricExport.h" -#include "DoricSettableFuture.h" - -static QString EMPTY(""); - class DORIC_EXPORT DoricAsyncResult { private: - QString result = EMPTY; + QString result; public: std::function resultCallback; @@ -26,9 +22,9 @@ public: bool hasResult(); - QJSValue getResult(); + QString getResult(); - DoricSettableFuture *synchronous(); + QString waitUntilResult(); }; #endif // ASYNCRESULT_H diff --git a/doric-Qt/example/doric/async/DoricSettableFuture.cpp b/doric-Qt/example/doric/async/DoricSettableFuture.cpp deleted file mode 100644 index a5e8cf9b..00000000 --- a/doric-Qt/example/doric/async/DoricSettableFuture.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -#include "DoricSettableFuture.h" - -void DoricSettableFuture::set(QJSValue result) { - if (mReadyLatch == NULL) { - qDebug() << "Result has already been set!"; - return; - } - mResult = result; - delete mReadyLatch; -} - -QJSValue DoricSettableFuture::get() { - mReadyLatch->lock(); - return mResult; -} diff --git a/doric-Qt/example/doric/async/DoricSettableFuture.h b/doric-Qt/example/doric/async/DoricSettableFuture.h deleted file mode 100644 index 10f6961a..00000000 --- a/doric-Qt/example/doric/async/DoricSettableFuture.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SETTABLE_FUTURE_H -#define SETTABLE_FUTURE_H - -#include - -#include "DoricExport.h" - -#include "utils/DoricCountDownLatch.h" - -class DORIC_EXPORT DoricSettableFuture { -private: - QJSValue mResult; - DoricCountDownLatch *mReadyLatch = new DoricCountDownLatch(); - -public: - void set(QJSValue result); - - QJSValue get(); -}; - -#endif // SETTABLE_FUTURE_H diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index 7fca89d1..f15d0efb 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -26,7 +26,6 @@ SOURCES += \ DoricPanel.cpp \ DoricRegistry.cpp \ async/DoricAsyncResult.cpp \ - async/DoricSettableFuture.cpp \ engine/DoricBridgeExtension.cpp \ engine/DoricJSEngine.cpp \ engine/DoricNativeEmpty.cpp \ @@ -105,7 +104,6 @@ HEADERS += \ DoricRegistry.h \ async/DoricAsyncCall.h \ async/DoricAsyncResult.h \ - async/DoricSettableFuture.h \ engine/DoricBridgeExtension.h \ engine/DoricInterfaceJSE.h \ engine/DoricJSEngine.h \ diff --git a/doric-Qt/example/doric/resources/slider.qml b/doric-Qt/example/doric/resources/slider.qml index 6968665d..11c991ac 100644 --- a/doric-Qt/example/doric/resources/slider.qml +++ b/doric-Qt/example/doric/resources/slider.qml @@ -1,6 +1,8 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 +import "util.mjs" as Util + SwipeView { property var wrapper diff --git a/doric-Qt/example/doric/shader/DoricViewNode.cpp b/doric-Qt/example/doric/shader/DoricViewNode.cpp index edf712fa..713a7078 100644 --- a/doric-Qt/example/doric/shader/DoricViewNode.cpp +++ b/doric-Qt/example/doric/shader/DoricViewNode.cpp @@ -232,8 +232,8 @@ DoricViewNode::pureCallJSResponse(QString funcId, QVariantList args) { foreach (const QVariant &arg, args) nArgs.append(arg); - return getContext()->callEntity(DoricConstant::DORIC_CONTEXT_INVOKE_PURE, - nArgs); + return getContext()->getDriver()->invokeDoricMethod( + DoricConstant::DORIC_CONTEXT_INVOKE_PURE, nArgs); } void DoricViewNode::onClick() { diff --git a/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp b/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp index 53f62e6e..b387710d 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp +++ b/doric-Qt/example/doric/shader/slider/DoricSliderNode.cpp @@ -32,15 +32,33 @@ void DoricSliderNode::blendSubNode(QJsonValue subProperties) { } } -void DoricSliderNode::blend(QJsonValue jsValue) {} - -void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {} +void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) { + if (name == "itemCount") { + this->itemCount = prop.toInt(); + } else if (name == "renderPage") { + if (prop.toString() != this->renderPageFuncId) { + this->childNodes.clear(); + this->renderPageFuncId = prop.toString(); + } + } else if (name == "batchCount") { + this->batchCount = prop.toInt(); + } else if (name == "onPageSlided") { + this->onPageSelectedFuncId = prop.toString(); + } else if (name == "loop") { + this->loop = prop.toBool(); + } else { + DoricViewNode::blend(view, name, prop); + } +} void DoricSliderNode::afterBlended(QJsonValue prop) { if (this->childNodes.length() != this->itemCount) { QVariantList args; args.append(this->childNodes.length()); args.append(this->itemCount); - this->pureCallJSResponse("renderBunchedItems", args); + std::shared_ptr asyncResult = + this->pureCallJSResponse("renderBunchedItems", args); + QString result = asyncResult->waitUntilResult(); + qDebug() << result; } } diff --git a/doric-Qt/example/doric/shader/slider/DoricSliderNode.h b/doric-Qt/example/doric/shader/slider/DoricSliderNode.h index 314a2332..068086b6 100644 --- a/doric-Qt/example/doric/shader/slider/DoricSliderNode.h +++ b/doric-Qt/example/doric/shader/slider/DoricSliderNode.h @@ -25,8 +25,6 @@ public: virtual void blendSubNode(QJsonValue subProperties) override; - virtual void blend(QJsonValue jsValue) override; - virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; virtual void afterBlended(QJsonValue prop) override;