diff --git a/desktop/CMakeLists.txt b/desktop/CMakeLists.txt new file mode 100644 index 0000000..5e50dd4 --- /dev/null +++ b/desktop/CMakeLists.txt @@ -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) diff --git a/desktop/rnlanguagesdesktop.cpp b/desktop/rnlanguagesdesktop.cpp new file mode 100644 index 0000000..54926ad --- /dev/null +++ b/desktop/rnlanguagesdesktop.cpp @@ -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 + +#include "bridge.h" +#include "rnlanguagesdesktop.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +struct RegisterQMLMetaType { + RegisterQMLMetaType() { + qRegisterMetaType(); + } +} 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 RNLanguages::methodsToExport() { + return QList{}; +} + +QVariantMap RNLanguages::constantsToExport() { + return QVariantMap{{"languages", d_ptr->languages()}}; +} + +void RNLanguages::setBridge(Bridge* bridge) { + Q_D(RNLanguages); + d->bridge = bridge; +} +