Add desktop implementation

This commit is contained in:
kn 2019-01-13 21:31:34 -08:00
parent 828ee9875d
commit 2aa017115f
2 changed files with 87 additions and 0 deletions

7
desktop/CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES}
\"RNLanguages\" PARENT_SCOPE)
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/rnlanguagesdesktop.cpp PARENT_SCOPE)

View File

@ -0,0 +1,80 @@
/**
* Copyright (c) 2017-present, Status Research and Development GmbH.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <memory>
#include "bridge.h"
#include "rnlanguagesdesktop.h"
#include <QCryptographicHash>
#include <QDateTime>
#include <QDebug>
#include <QLocale>
#include <QMap>
#include <QNetworkDiskCache>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QQuickImageProvider>
namespace {
struct RegisterQMLMetaType {
RegisterQMLMetaType() {
qRegisterMetaType<RNLanguages*>();
}
} registerMetaType;
} // namespace
class RNLanguagesPrivate {
public:
RNLanguagesPrivate() {}
Bridge* bridge = nullptr;
QVariantList languages() {
QStringList languages = QLocale().uiLanguages();
QVariantList variantLanguages;
for (QString l : languages) {
variantLanguages.push_back(l);
}
return variantLanguages;
}
};
RNLanguages::RNLanguages(QObject* parent) : QObject(parent), d_ptr(new RNLanguagesPrivate) {}
RNLanguages::~RNLanguages() {}
void RNLanguages::getLanguages(double successCallback, double errorCallback) {
Q_D(RNLanguages);
QVariantList args;
args.push_back(d->languages());
if (d->bridge) {
d->bridge->invokePromiseCallback(successCallback, args);
}
}
QString RNLanguages::moduleName() {
return "RNLanguages";
}
QList<ModuleMethod*> RNLanguages::methodsToExport() {
return QList<ModuleMethod*>{};
}
QVariantMap RNLanguages::constantsToExport() {
return QVariantMap{{"languages", d_ptr->languages()}};
}
void RNLanguages::setBridge(Bridge* bridge) {
Q_D(RNLanguages);
d->bridge = bridge;
}