add slider bridge

This commit is contained in:
王劲鹏 2021-06-01 19:30:37 +08:00 committed by osborn
parent 9f1839f2f7
commit d34655db07
7 changed files with 46 additions and 2 deletions

View File

@ -9,6 +9,7 @@
#include "utils/DoricInputBridge.h" #include "utils/DoricInputBridge.h"
#include "utils/DoricMouseAreaBridge.h" #include "utils/DoricMouseAreaBridge.h"
#include "utils/DoricSlideItemBridge.h" #include "utils/DoricSlideItemBridge.h"
#include "utils/DoricSliderBridge.h"
#include "utils/DoricSwitchBridge.h" #include "utils/DoricSwitchBridge.h"
#include "utils/DoricUtils.h" #include "utils/DoricUtils.h"
@ -123,4 +124,6 @@ void DoricDemoBridge::navigate(QVariant route) {
context->setContextProperty("switchBridge", switchBridge); context->setContextProperty("switchBridge", switchBridge);
DoricSlideItemBridge *slideItemBridge = new DoricSlideItemBridge(); DoricSlideItemBridge *slideItemBridge = new DoricSlideItemBridge();
context->setContextProperty("slideItemBridge", slideItemBridge); context->setContextProperty("slideItemBridge", slideItemBridge);
DoricSliderBridge *sliderBridge = new DoricSliderBridge();
context->setContextProperty("sliderBridge", sliderBridge);
} }

View File

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

View File

@ -43,6 +43,7 @@ SwipeView {
onCurrentIndexChanged: { onCurrentIndexChanged: {
console.log(tag, uuid + " onCurrentIndexChanged: " + this.currentIndex) console.log(tag, uuid + " onCurrentIndexChanged: " + this.currentIndex)
sliderBridge.onPageSlided(wrapper)
} }
} }

View File

@ -47,7 +47,7 @@ void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
} else if (name == "batchCount") { } else if (name == "batchCount") {
this->batchCount = prop.toInt(); this->batchCount = prop.toInt();
} else if (name == "onPageSlided") { } else if (name == "onPageSlided") {
this->onPageSelectedFuncId = prop.toString(); this->onPageSlidedFuncId = prop.toString();
} else if (name == "loop") { } else if (name == "loop") {
this->loop = prop.toBool(); this->loop = prop.toBool();
} else { } else {
@ -88,3 +88,10 @@ void DoricSliderNode::afterBlended(QJsonValue prop) {
} }
} }
} }
void DoricSliderNode::onPageSlided() {
int currentIndex = mView->property("currentIndex").toInt();
QVariantList args;
args.append(currentIndex);
callJSResponse(this->onPageSlidedFuncId, args);
}

View File

@ -12,7 +12,7 @@ private:
int itemCount = 0; int itemCount = 0;
QString renderPageFuncId; QString renderPageFuncId;
int batchCount = 15; int batchCount = 15;
QString onPageSelectedFuncId; QString onPageSlidedFuncId;
bool loop = false; bool loop = false;
QList<DoricSlideItemNode *> childNodes; QList<DoricSlideItemNode *> childNodes;
@ -28,6 +28,8 @@ public:
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override; virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
virtual void afterBlended(QJsonValue prop) override; virtual void afterBlended(QJsonValue prop) override;
void onPageSlided();
}; };
#endif // DORICSLIDERNODE_H #endif // DORICSLIDERNODE_H

View File

@ -0,0 +1,11 @@
#include "DoricSliderBridge.h"
#include "shader/slider/DoricSliderNode.h"
DoricSliderBridge::DoricSliderBridge(QObject *parent) : QObject(parent) {}
void DoricSliderBridge::onPageSlided(QString pointer) {
QObject *object = (QObject *)(pointer.toULongLong());
DoricSliderNode *sliderNode = dynamic_cast<DoricSliderNode *>(object);
sliderNode->onPageSlided();
}

View File

@ -0,0 +1,18 @@
#ifndef DORICSLIDERBRIDGE_H
#define DORICSLIDERBRIDGE_H
#include <QObject>
#include <QVariant>
#include "DoricExport.h"
class DORIC_EXPORT DoricSliderBridge : public QObject {
Q_OBJECT
public:
explicit DoricSliderBridge(QObject *parent = nullptr);
Q_INVOKABLE
void onPageSlided(QString pointer);
};
#endif // DORICSLIDERBRIDGE_H