add switch bridge

This commit is contained in:
王劲鹏 2021-05-27 18:18:30 +08:00 committed by osborn
parent b6033d6eb6
commit 19cc85cf1c
7 changed files with 52 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include "utils/DoricImageBridge.h"
#include "utils/DoricInputBridge.h"
#include "utils/DoricMouseAreaBridge.h"
#include "utils/DoricSwitchBridge.h"
#include "utils/DoricUtils.h"
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
@ -108,4 +109,6 @@ void DoricDemoBridge::navigate(QVariant route) {
context->setContextProperty("imageBridge", imageBridge);
DoricInputBridge *inputBridge = new DoricInputBridge();
context->setContextProperty("inputBridge", inputBridge);
DoricSwitchBridge *switchBridge = new DoricSwitchBridge();
context->setContextProperty("switchBridge", switchBridge);
}

View File

@ -63,6 +63,7 @@ SOURCES += \
utils/DoricInputBridge.cpp \
utils/DoricLayouts.cpp \
utils/DoricMouseAreaBridge.cpp \
utils/DoricSwitchBridge.cpp \
widget/flex/FlexLayout.cpp \
widget/flex/FlexLayoutConfig.cpp \
widget/flex/FlexLayoutService.cpp \
@ -148,6 +149,7 @@ HEADERS += \
utils/DoricMouseAreaBridge.h \
utils/DoricNetworkService.h \
utils/DoricObjectFactory.h \
utils/DoricSwitchBridge.h \
utils/DoricThreadMode.h \
utils/DoricUtils.h \
widget/flex/FlexLayout.h \

View File

@ -28,5 +28,6 @@ Switch {
} else {
this.indicator.children[0].color = offTintColor
}
switchBridge.onSwitch(wrapper, checked)
}
}

View File

@ -25,7 +25,7 @@ void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
view->setProperty("checked", prop.toBool());
checkByCodeToggle = false;
} else if (name == "onSwitch") {
onSwitchFuncId = prop.toString();
} else if (name == "offTintColor") {
view->setProperty(
"offTintColor",
@ -41,3 +41,13 @@ void DoricSwitchNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
DoricViewNode::blend(view, name, prop);
}
}
void DoricSwitchNode::onSwitch(bool checked) {
if (checkByCodeToggle)
return;
if (!onSwitchFuncId.isEmpty()) {
QVariantList args;
args.append(checked);
callJSResponse(onSwitchFuncId, args);
}
}

View File

@ -10,12 +10,16 @@ class DORIC_EXPORT DoricSwitchNode : public DoricViewNode {
private:
bool checkByCodeToggle = false;
QString onSwitchFuncId;
public:
using DoricViewNode::DoricViewNode;
QQuickItem *build() override;
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
void onSwitch(bool checked);
};
#endif // DORICSWITCHNODE_H

View File

@ -0,0 +1,12 @@
#include "DoricSwitchBridge.h"
#include "shader/DoricSwitchNode.h"
DoricSwitchBridge::DoricSwitchBridge(QObject *parent) : QObject(parent) {}
void DoricSwitchBridge::onSwitch(QString pointer, bool checked) {
QObject *object = (QObject *)(pointer.toULongLong());
DoricSwitchNode *switchNode = dynamic_cast<DoricSwitchNode *>(object);
switchNode->onSwitch(checked);
}

View File

@ -0,0 +1,19 @@
#ifndef DORICSWITCHBRIDGE_H
#define DORICSWITCHBRIDGE_H
#include <QObject>
#include <QVariant>
#include "DoricExport.h"
class DORIC_EXPORT DoricSwitchBridge : public QObject {
Q_OBJECT
public:
explicit DoricSwitchBridge(QObject *parent = nullptr);
Q_INVOKABLE
void onSwitch(QString pointer, bool checked);
signals:
};
#endif // DORICSWITCHBRIDGE_H