@react-native-gpui/unistyles 0.0.0-stage → 3.8.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +42 -2
- package/desktop/CMakeLists.txt +55 -0
- package/desktop/cpp/GPUIUnistylesModule.cpp +80 -0
- package/desktop/cpp/HybridNativePlatformDesktop.cpp +202 -0
- package/desktop/cpp/HybridNativePlatformDesktop.hpp +53 -0
- package/desktop/include/Unistyles-Swift-Cxx-Umbrella.hpp +7 -0
- package/package.json +40 -4
- package/react-native.config.js +10 -0
- package/src/NativeGPUIUnistyles.ts +6 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@react-native-gpui/unistyles` are listed here. Each version's section becomes the notes of its GitHub release.
|
|
4
|
+
|
|
5
|
+
## 3.8.0-alpha.1 - 2026-11-27
|
|
6
|
+
|
|
7
|
+
- First release, for `react-native-unistyles` 3.8.x: StyleSheets with themes, adaptive themes, breakpoints, media queries, variants and dynamic functions, `UnistylesRuntime` values, `withUnistyles`, and style updates that skip React renders.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Streetwriters
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @react-native-gpui/unistyles
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Adapter for [`react-native-unistyles`](https://github.com/jpudysz/react-native-unistyles) (MIT): themes, breakpoints, media queries and runtime values on the desktop renderer.
|
|
4
|
+
|
|
5
|
+
Part of [react-native-gpui](https://github.com/streetwriters/react-native-gpui), React Native for macOS, Windows and Linux.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Install it next to `react-native-unistyles` and the Nitro adapter it builds on:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install react-native-unistyles@3.8.x react-native-nitro-modules@0.37.x @react-native-gpui/nitro-modules @react-native-gpui/unistyles
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Keep using `react-native-unistyles` as you do on iOS and Android; its JavaScript API is unchanged. Autolinking builds the desktop side when the app is built.
|
|
16
|
+
|
|
17
|
+
Add Unistyles' Babel plugin to `babel.config.js`, exactly as its documentation says:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
module.exports = {
|
|
21
|
+
plugins: [['react-native-unistyles/plugin', { root: 'src' }]],
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Unistyles' C++ updates styles on the shadow tree directly, so the plugin is what lets a style change without a React render.
|
|
26
|
+
|
|
27
|
+
## Supported
|
|
28
|
+
|
|
29
|
+
StyleSheet with themes, adaptive themes (the system color scheme and `Appearance.setColorScheme`), breakpoints, media queries, variants and dynamic functions; the `UnistylesRuntime` values (color scheme, theme, breakpoint, screen size, pixel ratio, font scale, content size category, insets, right to left, orientation); `useUnistyles` and `withUnistyles`; style updates through the shadow tree.
|
|
30
|
+
|
|
31
|
+
Screen dimensions and breakpoints follow the window, so resizing it updates styles.
|
|
32
|
+
|
|
33
|
+
## Not supported
|
|
34
|
+
|
|
35
|
+
These are no-ops on desktop: the status bar, the navigation bar, immersive mode, the root view background color and the IME insets.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
[Supported libraries](https://streetwriters.github.io/react-native-gpui/docs/supported-libraries)
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT. See [LICENSE](LICENSE). `react-native-unistyles` is MIT, copyright Jacek Pudysz.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
if(NOT RN_GPUI_PROJECT_ROOT)
|
|
2
|
+
message(FATAL_ERROR
|
|
3
|
+
"@react-native-gpui/unistyles was added by the platform; RN_GPUI_PROJECT_ROOT must be set by its build.rs")
|
|
4
|
+
endif()
|
|
5
|
+
find_program(_gpui_node node REQUIRED)
|
|
6
|
+
|
|
7
|
+
function(_gpui_unistyles_resolve out package)
|
|
8
|
+
execute_process(
|
|
9
|
+
COMMAND "${_gpui_node}" -e
|
|
10
|
+
"process.stdout.write(require.resolve(process.argv[2] + '/package.json', {paths: [process.argv[1]]}))"
|
|
11
|
+
"${RN_GPUI_PROJECT_ROOT}" "${package}"
|
|
12
|
+
RESULT_VARIABLE _result
|
|
13
|
+
OUTPUT_VARIABLE _package_json
|
|
14
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
15
|
+
if(NOT _result EQUAL 0 OR NOT EXISTS "${_package_json}")
|
|
16
|
+
message(FATAL_ERROR "${package} could not be resolved from ${RN_GPUI_PROJECT_ROOT}")
|
|
17
|
+
endif()
|
|
18
|
+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_package_json}")
|
|
19
|
+
get_filename_component(_root "${_package_json}" DIRECTORY)
|
|
20
|
+
set(${out} "${_root}" PARENT_SCOPE)
|
|
21
|
+
endfunction()
|
|
22
|
+
|
|
23
|
+
_gpui_unistyles_resolve(_unistyles_root react-native-unistyles)
|
|
24
|
+
_gpui_unistyles_resolve(_nitro_adapter_root @react-native-gpui/nitro-modules)
|
|
25
|
+
|
|
26
|
+
execute_process(
|
|
27
|
+
COMMAND "${_gpui_node}" -e
|
|
28
|
+
"process.stdout.write(require(process.argv[1] + '/package.json').version)"
|
|
29
|
+
"${_unistyles_root}"
|
|
30
|
+
OUTPUT_VARIABLE _unistyles_version
|
|
31
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
32
|
+
if(NOT _unistyles_version MATCHES "^3\\.8\\.")
|
|
33
|
+
message(FATAL_ERROR
|
|
34
|
+
"@react-native-gpui/unistyles supports react-native-unistyles 3.8.x, found ${_unistyles_version}")
|
|
35
|
+
endif()
|
|
36
|
+
|
|
37
|
+
include("${_nitro_adapter_root}/desktop/NitroDesktop.cmake")
|
|
38
|
+
|
|
39
|
+
file(GLOB_RECURSE _unistyles_sources CONFIGURE_DEPENDS "${_unistyles_root}/cxx/*.cpp")
|
|
40
|
+
file(GLOB _unistyles_desktop_sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/cpp/*.cpp")
|
|
41
|
+
|
|
42
|
+
rn_gpui_nitro_library(
|
|
43
|
+
PACKAGE react-native-unistyles
|
|
44
|
+
SOURCES ${_unistyles_sources} ${_unistyles_desktop_sources}
|
|
45
|
+
INCLUDE_DIRS
|
|
46
|
+
"${_unistyles_root}/cxx"
|
|
47
|
+
"${_unistyles_root}/cxx/common"
|
|
48
|
+
"${_unistyles_root}/cxx/core"
|
|
49
|
+
"${_unistyles_root}/cxx/converters"
|
|
50
|
+
"${_unistyles_root}/cxx/hybridObjects"
|
|
51
|
+
"${_unistyles_root}/cxx/parser"
|
|
52
|
+
"${_unistyles_root}/cxx/shadowTree"
|
|
53
|
+
"${CMAKE_CURRENT_LIST_DIR}/include"
|
|
54
|
+
"${CMAKE_CURRENT_LIST_DIR}/cpp")
|
|
55
|
+
set_property(GLOBAL APPEND PROPERTY RN_GPUI_APP_CPP_INIT_FUNCTIONS rn_gpui_unistyles_init)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#include "HybridNativePlatformDesktop.hpp"
|
|
2
|
+
|
|
3
|
+
#include "HybridShadowRegistry.h"
|
|
4
|
+
#include "HybridStyleSheet.h"
|
|
5
|
+
#include "HybridUnistylesRuntime.h"
|
|
6
|
+
#include "UnistylesRegistry.h"
|
|
7
|
+
|
|
8
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
9
|
+
#include <ReactCommon/TurboModule.h>
|
|
10
|
+
#include <ReactCommon/TurboModuleWithJSIBindings.h>
|
|
11
|
+
|
|
12
|
+
#include <cstdint>
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <string>
|
|
16
|
+
|
|
17
|
+
namespace {
|
|
18
|
+
using namespace margelo::nitro;
|
|
19
|
+
|
|
20
|
+
class UnistylesModule final : public facebook::react::TurboModule,
|
|
21
|
+
public facebook::react::TurboModuleWithJSIBindings {
|
|
22
|
+
public:
|
|
23
|
+
explicit UnistylesModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker)
|
|
24
|
+
: TurboModule("Unistyles", jsInvoker), callInvoker_(std::move(jsInvoker)) {}
|
|
25
|
+
|
|
26
|
+
~UnistylesModule() override {
|
|
27
|
+
if (generation_ != 0) {
|
|
28
|
+
core::UnistylesRegistry::get().releaseOwnership(generation_);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private:
|
|
33
|
+
// Runs on first init and on every reload; the newest runtime owns the
|
|
34
|
+
// registry and a previous runtime's state is kept until it releases it.
|
|
35
|
+
void installJSIBindingsWithRuntime(facebook::jsi::Runtime&) override {
|
|
36
|
+
generation_ = core::UnistylesRegistry::get().takeOwnership();
|
|
37
|
+
|
|
38
|
+
if (HybridObjectRegistry::hasHybridObject("UnistylesRuntime")) {
|
|
39
|
+
HybridObjectRegistry::unregisterHybridObjectConstructor("UnistylesRuntime");
|
|
40
|
+
HybridObjectRegistry::unregisterHybridObjectConstructor("UnistylesStyleSheet");
|
|
41
|
+
HybridObjectRegistry::unregisterHybridObjectConstructor("UnistylesShadowRegistry");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
auto callInvoker = callInvoker_;
|
|
45
|
+
auto runOnJSThread = [callInvoker](std::function<void(facebook::jsi::Runtime&)>&& callback) {
|
|
46
|
+
callInvoker->invokeAsync(std::move(callback));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
auto nativePlatform = std::make_shared<unistyles::HybridNativePlatformDesktop>();
|
|
50
|
+
unistyles::HybridNativePlatformDesktop::makeCurrent(nativePlatform);
|
|
51
|
+
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, runOnJSThread, generation_);
|
|
52
|
+
auto styleSheet = std::make_shared<HybridStyleSheet>(unistylesRuntime);
|
|
53
|
+
|
|
54
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
55
|
+
"UnistylesRuntime", [unistylesRuntime]() -> std::shared_ptr<HybridObject> { return unistylesRuntime; });
|
|
56
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
57
|
+
"UnistylesStyleSheet", [styleSheet]() -> std::shared_ptr<HybridObject> { return styleSheet; });
|
|
58
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
59
|
+
"UnistylesShadowRegistry", [unistylesRuntime]() -> std::shared_ptr<HybridObject> {
|
|
60
|
+
return std::make_shared<HybridShadowRegistry>(unistylesRuntime);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
std::shared_ptr<facebook::react::CallInvoker> callInvoker_;
|
|
65
|
+
uint64_t generation_ = 0;
|
|
66
|
+
};
|
|
67
|
+
} // namespace
|
|
68
|
+
|
|
69
|
+
extern "C" void rn_gpui_unistyles_init() {
|
|
70
|
+
margelo::nitro::unistyles::HybridNativePlatformDesktop::installObservers();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::shared_ptr<facebook::react::TurboModule> create_gpui_unistyles_module(
|
|
74
|
+
const std::string& name,
|
|
75
|
+
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
|
|
76
|
+
if (name != "Unistyles") {
|
|
77
|
+
return nullptr;
|
|
78
|
+
}
|
|
79
|
+
return std::make_shared<UnistylesModule>(std::move(jsInvoker));
|
|
80
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#include "HybridNativePlatformDesktop.hpp"
|
|
2
|
+
|
|
3
|
+
#include "GpuiModules.h"
|
|
4
|
+
#include "Dimensions.hpp"
|
|
5
|
+
#include "Insets.hpp"
|
|
6
|
+
#include "rn-gpui-sys/src/lib.rs.h"
|
|
7
|
+
|
|
8
|
+
#include <react/coremodules/DeviceInfoModule.h>
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::unistyles {
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
std::mutex currentMutex;
|
|
14
|
+
std::weak_ptr<HybridNativePlatformDesktop> currentPlatform;
|
|
15
|
+
|
|
16
|
+
std::shared_ptr<HybridNativePlatformDesktop> current() {
|
|
17
|
+
std::lock_guard<std::mutex> lock(currentMutex);
|
|
18
|
+
return currentPlatform.lock();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
bool sameDimensions(const Dimensions& a, const Dimensions& b) {
|
|
22
|
+
return a.width == b.width && a.height == b.height;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
bool sameInsets(const Insets& a, const Insets& b) {
|
|
26
|
+
return a.top == b.top && a.bottom == b.bottom && a.left == b.left && a.right == b.right && a.ime == b.ime;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
std::vector<UnistyleDependency> diff(const UnistylesNativeMiniRuntime& lhs, const UnistylesNativeMiniRuntime& rhs) {
|
|
30
|
+
std::vector<UnistyleDependency> dependencies;
|
|
31
|
+
if (lhs.colorScheme != rhs.colorScheme) {
|
|
32
|
+
dependencies.push_back(UnistyleDependency::COLORSCHEME);
|
|
33
|
+
}
|
|
34
|
+
if (!sameDimensions(lhs.screen, rhs.screen)) {
|
|
35
|
+
dependencies.push_back(UnistyleDependency::DIMENSIONS);
|
|
36
|
+
}
|
|
37
|
+
if (lhs.screen.width != rhs.screen.width) {
|
|
38
|
+
dependencies.push_back(UnistyleDependency::BREAKPOINTS);
|
|
39
|
+
}
|
|
40
|
+
if (lhs.isPortrait != rhs.isPortrait) {
|
|
41
|
+
dependencies.push_back(UnistyleDependency::ORIENTATION);
|
|
42
|
+
}
|
|
43
|
+
if (lhs.contentSizeCategory != rhs.contentSizeCategory) {
|
|
44
|
+
dependencies.push_back(UnistyleDependency::CONTENTSIZECATEGORY);
|
|
45
|
+
}
|
|
46
|
+
if (!sameInsets(lhs.insets, rhs.insets)) {
|
|
47
|
+
dependencies.push_back(UnistyleDependency::INSETS);
|
|
48
|
+
}
|
|
49
|
+
if (lhs.pixelRatio != rhs.pixelRatio) {
|
|
50
|
+
dependencies.push_back(UnistyleDependency::PIXELRATIO);
|
|
51
|
+
}
|
|
52
|
+
if (lhs.fontScale != rhs.fontScale) {
|
|
53
|
+
dependencies.push_back(UnistyleDependency::FONTSCALE);
|
|
54
|
+
}
|
|
55
|
+
if (lhs.rtl != rhs.rtl) {
|
|
56
|
+
dependencies.push_back(UnistyleDependency::RTL);
|
|
57
|
+
}
|
|
58
|
+
return dependencies;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void notifyCurrent() {
|
|
62
|
+
if (auto platform = current()) {
|
|
63
|
+
platform->onPlatformChangeFromHost();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} // namespace
|
|
67
|
+
|
|
68
|
+
HybridNativePlatformDesktop::HybridNativePlatformDesktop() : HybridObject(TAG) {
|
|
69
|
+
miniRuntime_ = buildMiniRuntime();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
HybridNativePlatformDesktop::~HybridNativePlatformDesktop() = default;
|
|
73
|
+
|
|
74
|
+
void HybridNativePlatformDesktop::installObservers() {
|
|
75
|
+
static std::once_flag once;
|
|
76
|
+
std::call_once(once, [] {
|
|
77
|
+
rngpui::registerColorSchemeObserver([](const std::string&) { notifyCurrent(); });
|
|
78
|
+
rngpui::registerWindowMetricsObserver([] { notifyCurrent(); });
|
|
79
|
+
rngpui::registerWindowInsetsObserver([](float, float, float, float) { notifyCurrent(); });
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void HybridNativePlatformDesktop::makeCurrent(const std::shared_ptr<HybridNativePlatformDesktop>& platform) {
|
|
84
|
+
std::lock_guard<std::mutex> lock(currentMutex);
|
|
85
|
+
currentPlatform = platform;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Insets HybridNativePlatformDesktop::getInsets() {
|
|
89
|
+
float top = 0, right = 0, bottom = 0, left = 0;
|
|
90
|
+
rngpui::currentWindowInsets(top, right, bottom, left);
|
|
91
|
+
return Insets(top, bottom, left, right, 0);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ColorScheme HybridNativePlatformDesktop::getColorScheme() {
|
|
95
|
+
return rngpui::currentColorScheme() == "dark" ? ColorScheme::DARK : ColorScheme::LIGHT;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
double HybridNativePlatformDesktop::getFontScale() {
|
|
99
|
+
return facebook::react::DeviceInfoModule::fontScale();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
double HybridNativePlatformDesktop::getPixelRatio() {
|
|
103
|
+
return rngpui::windowScale();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Orientation HybridNativePlatformDesktop::getOrientation() {
|
|
107
|
+
const auto size = facebook::react::DeviceInfoModule::windowSize();
|
|
108
|
+
return size.width > size.height ? Orientation::LANDSCAPE : Orientation::PORTRAIT;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
std::string HybridNativePlatformDesktop::getContentSizeCategory() {
|
|
112
|
+
const auto scale = getFontScale();
|
|
113
|
+
if (scale <= 0.82) return "xSmall";
|
|
114
|
+
if (scale <= 0.9) return "Small";
|
|
115
|
+
if (scale <= 1.0) return "Medium";
|
|
116
|
+
if (scale <= 1.1) return "Large";
|
|
117
|
+
if (scale <= 1.2) return "xLarge";
|
|
118
|
+
if (scale <= 1.3) return "xxLarge";
|
|
119
|
+
return "xxxLarge";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
Dimensions HybridNativePlatformDesktop::getScreenDimensions() {
|
|
123
|
+
const auto size = facebook::react::DeviceInfoModule::windowSize();
|
|
124
|
+
return Dimensions(size.width, size.height);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Dimensions HybridNativePlatformDesktop::getStatusBarDimensions() {
|
|
128
|
+
return Dimensions(0, 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
Dimensions HybridNativePlatformDesktop::getNavigationBarDimensions() {
|
|
132
|
+
return Dimensions(0, 0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
bool HybridNativePlatformDesktop::getPrefersRtlDirection() {
|
|
136
|
+
return rngpui::rn_gpui_layout_direction_rtl();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void HybridNativePlatformDesktop::setRootViewBackgroundColor(double) {}
|
|
140
|
+
|
|
141
|
+
void HybridNativePlatformDesktop::setNavigationBarHidden(bool) {}
|
|
142
|
+
|
|
143
|
+
void HybridNativePlatformDesktop::setStatusBarHidden(bool) {}
|
|
144
|
+
|
|
145
|
+
void HybridNativePlatformDesktop::setImmersiveMode(bool) {}
|
|
146
|
+
|
|
147
|
+
UnistylesNativeMiniRuntime HybridNativePlatformDesktop::getMiniRuntime() {
|
|
148
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
149
|
+
return miniRuntime_;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
UnistylesNativeMiniRuntime HybridNativePlatformDesktop::buildMiniRuntime() {
|
|
153
|
+
const auto orientation = getOrientation();
|
|
154
|
+
return UnistylesNativeMiniRuntime(
|
|
155
|
+
getColorScheme(),
|
|
156
|
+
getScreenDimensions(),
|
|
157
|
+
getContentSizeCategory(),
|
|
158
|
+
getInsets(),
|
|
159
|
+
getPixelRatio(),
|
|
160
|
+
getFontScale(),
|
|
161
|
+
getPrefersRtlDirection(),
|
|
162
|
+
getStatusBarDimensions(),
|
|
163
|
+
getNavigationBarDimensions(),
|
|
164
|
+
orientation == Orientation::PORTRAIT,
|
|
165
|
+
orientation == Orientation::LANDSCAPE);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void HybridNativePlatformDesktop::registerPlatformListener(const DependencyListener& callback) {
|
|
169
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
170
|
+
dependencyListeners_.push_back(callback);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void HybridNativePlatformDesktop::registerImeListener(const ImeListener& callback) {
|
|
174
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
175
|
+
imeListeners_.push_back(callback);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
void HybridNativePlatformDesktop::unregisterPlatformListeners() {
|
|
179
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
180
|
+
dependencyListeners_.clear();
|
|
181
|
+
imeListeners_.clear();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
void HybridNativePlatformDesktop::onPlatformChangeFromHost() {
|
|
185
|
+
auto next = buildMiniRuntime();
|
|
186
|
+
std::vector<UnistyleDependency> changed;
|
|
187
|
+
std::vector<DependencyListener> listeners;
|
|
188
|
+
{
|
|
189
|
+
std::lock_guard<std::mutex> lock(mutex_);
|
|
190
|
+
changed = diff(miniRuntime_, next);
|
|
191
|
+
if (changed.empty()) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
miniRuntime_ = next;
|
|
195
|
+
listeners = dependencyListeners_;
|
|
196
|
+
}
|
|
197
|
+
for (const auto& listener : listeners) {
|
|
198
|
+
listener(changed, next);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} // namespace margelo::nitro::unistyles
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "HybridNativePlatformSpec.hpp"
|
|
4
|
+
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <mutex>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::unistyles {
|
|
11
|
+
|
|
12
|
+
using DependencyListener = std::function<void(const std::vector<UnistyleDependency>&, const UnistylesNativeMiniRuntime&)>;
|
|
13
|
+
using ImeListener = std::function<void(const UnistylesNativeMiniRuntime&)>;
|
|
14
|
+
|
|
15
|
+
class HybridNativePlatformDesktop final : public HybridNativePlatformSpec {
|
|
16
|
+
public:
|
|
17
|
+
HybridNativePlatformDesktop();
|
|
18
|
+
~HybridNativePlatformDesktop() override;
|
|
19
|
+
|
|
20
|
+
// Routes the host's change notifications to the newest instance.
|
|
21
|
+
static void installObservers();
|
|
22
|
+
static void makeCurrent(const std::shared_ptr<HybridNativePlatformDesktop>& platform);
|
|
23
|
+
void onPlatformChangeFromHost();
|
|
24
|
+
|
|
25
|
+
Insets getInsets() override;
|
|
26
|
+
ColorScheme getColorScheme() override;
|
|
27
|
+
double getFontScale() override;
|
|
28
|
+
double getPixelRatio() override;
|
|
29
|
+
Orientation getOrientation() override;
|
|
30
|
+
std::string getContentSizeCategory() override;
|
|
31
|
+
Dimensions getScreenDimensions() override;
|
|
32
|
+
Dimensions getStatusBarDimensions() override;
|
|
33
|
+
Dimensions getNavigationBarDimensions() override;
|
|
34
|
+
bool getPrefersRtlDirection() override;
|
|
35
|
+
void setRootViewBackgroundColor(double color) override;
|
|
36
|
+
void setNavigationBarHidden(bool isHidden) override;
|
|
37
|
+
void setStatusBarHidden(bool isHidden) override;
|
|
38
|
+
void setImmersiveMode(bool isEnabled) override;
|
|
39
|
+
UnistylesNativeMiniRuntime getMiniRuntime() override;
|
|
40
|
+
void registerPlatformListener(const DependencyListener& callback) override;
|
|
41
|
+
void registerImeListener(const ImeListener& callback) override;
|
|
42
|
+
void unregisterPlatformListeners() override;
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
UnistylesNativeMiniRuntime buildMiniRuntime();
|
|
46
|
+
|
|
47
|
+
std::mutex mutex_;
|
|
48
|
+
UnistylesNativeMiniRuntime miniRuntime_;
|
|
49
|
+
std::vector<DependencyListener> dependencyListeners_;
|
|
50
|
+
std::vector<ImeListener> imeListeners_;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
} // namespace margelo::nitro::unistyles
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-gpui/unistyles",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.8.0-alpha.1",
|
|
4
|
+
"description": "Adapter for react-native-unistyles (MIT): themes, breakpoints, media queries and runtime values on the desktop renderer",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/streetwriters/react-native-gpui-modules.git",
|
|
9
|
+
"directory": "modules/unistyles"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/streetwriters/react-native-gpui-modules/tree/main/modules/unistyles#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/streetwriters/react-native-gpui-modules/issues"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"desktop",
|
|
17
|
+
"src",
|
|
18
|
+
"react-native.config.js",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"CHANGELOG.md",
|
|
22
|
+
"!**/*.test.js",
|
|
23
|
+
"!**/*.test.mjs",
|
|
24
|
+
"!**/*.test.ts",
|
|
25
|
+
"!**/*.test.cjs"
|
|
26
|
+
],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react-native": "0.87.x",
|
|
29
|
+
"react-native-unistyles": "3.8.x",
|
|
30
|
+
"react-native-nitro-modules": "0.37.x",
|
|
31
|
+
"@react-native-gpui/nitro-modules": "0.37.0-alpha.1"
|
|
32
|
+
},
|
|
33
|
+
"codegenConfig": {
|
|
34
|
+
"name": "GPUIUnistylesSpec",
|
|
35
|
+
"type": "modules",
|
|
36
|
+
"jsSrcsDir": "src"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"tag": "latest"
|
|
41
|
+
}
|
|
42
|
+
}
|