react-native-unistyles 2.7.2 → 2.8.0-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +8 -1
- package/android/build.gradle +4 -1
- package/android/src/main/cxx/cpp-adapter.cpp +10 -100
- package/android/src/main/cxx/helpers.h +2 -0
- package/android/src/main/cxx/platform.cpp +126 -0
- package/android/src/main/cxx/platform.h +15 -0
- package/android/src/main/java/com/unistyles/Config.kt +31 -5
- package/android/src/main/java/com/unistyles/Platform.kt +24 -0
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +24 -87
- package/cxx/Macros.h +11 -0
- package/cxx/UnistylesImpl.cpp +241 -0
- package/cxx/UnistylesModel.cpp +230 -0
- package/cxx/UnistylesModel.h +112 -0
- package/cxx/UnistylesRuntime.cpp +17 -388
- package/cxx/UnistylesRuntime.h +56 -95
- package/ios/UnistylesModule.h +8 -0
- package/ios/UnistylesModule.mm +12 -89
- package/ios/platform/Platform_Shared.h +5 -0
- package/ios/platform/Platform_Shared.mm +69 -0
- package/ios/platform/Platform_iOS.h +3 -10
- package/ios/platform/Platform_iOS.mm +53 -96
- package/ios/platform/Platform_macOS.h +2 -7
- package/ios/platform/Platform_macOS.mm +36 -36
- package/ios/platform/Platform_tvOS.h +2 -9
- package/ios/platform/Platform_tvOS.mm +30 -92
- package/ios/platform/Platform_visionOS.h +3 -9
- package/ios/platform/Platform_visionOS.mm +29 -84
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -1
- package/lib/commonjs/normalizer/normalizer.js +1 -1
- package/lib/commonjs/normalizer/normalizer.js.map +1 -1
- package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
- package/lib/commonjs/utils/generateId.js.map +1 -1
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/module/common.js.map +1 -1
- package/lib/module/normalizer/normalizeStyle.js.map +1 -1
- package/lib/module/normalizer/normalizer.js.map +1 -1
- package/lib/module/utils/cssMediaQuery.js.map +1 -1
- package/lib/module/utils/generateId.js.map +1 -1
- package/lib/module/utils/mq.js.map +1 -1
- package/package.json +2 -1
- package/react-native-unistyles.podspec +3 -0
- package/ios/UnistylesHelpers.h +0 -3
- package/ios/UnistylesHelpers.mm +0 -5
package/ios/UnistylesModule.mm
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#import "UnistylesModule.h"
|
2
|
-
#import "UnistylesHelpers.h"
|
3
2
|
#import "UnistylesRuntime.h"
|
4
3
|
|
5
4
|
#import <React/RCTBridge+Private.h>
|
@@ -47,106 +46,30 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
47
46
|
#pragma mark - Core
|
48
47
|
|
49
48
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if (
|
54
|
-
return @false;
|
55
|
-
}
|
56
|
-
|
57
|
-
auto jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
|
58
|
-
|
59
|
-
if (jsiRuntime == nil) {
|
49
|
+
UnistylesModule *__weak weakSelf = self;
|
50
|
+
RCTBridge *bridge = self.bridge;
|
51
|
+
|
52
|
+
if (bridge == nullptr) {
|
60
53
|
return @false;
|
61
54
|
}
|
62
55
|
|
63
|
-
|
64
|
-
UnistylesModule *__weak weakSelf = self;
|
65
|
-
|
66
|
-
registerUnistylesHostObject(runtime, weakSelf);
|
56
|
+
registerUnistylesHostObject(bridge, weakSelf);
|
67
57
|
|
68
58
|
NSLog(@"Installed Unistyles 🦄!");
|
69
59
|
|
70
60
|
return @true;
|
71
61
|
}
|
72
62
|
|
73
|
-
void registerUnistylesHostObject(
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
weakSelf.platform.initialContentSizeCategory,
|
78
|
-
weakSelf.platform.initialInsets,
|
79
|
-
weakSelf.platform.initialStatusBar,
|
80
|
-
weakSelf.platform.initialNavigationBar
|
81
|
-
);
|
82
|
-
|
83
|
-
unistylesRuntime.get()->onThemeChange([=](std::string theme) {
|
84
|
-
NSDictionary *body = @{
|
85
|
-
@"type": @"theme",
|
86
|
-
@"payload": @{
|
87
|
-
@"themeName": cxxStringToNSString(theme)
|
88
|
-
}
|
89
|
-
};
|
90
|
-
|
91
|
-
[weakSelf emitEvent:@"__unistylesOnChange" withBody:body];
|
92
|
-
});
|
93
|
-
|
94
|
-
unistylesRuntime.get()->onLayoutChange([=](std::string breakpoint, std::string orientation, Dimensions& screen, Dimensions& statusBar, Insets& insets, Dimensions& navigationBar) {
|
95
|
-
NSDictionary *body = @{
|
96
|
-
@"type": @"layout",
|
97
|
-
@"payload": @{
|
98
|
-
@"breakpoint": cxxStringToNSString(breakpoint),
|
99
|
-
@"orientation": cxxStringToNSString(orientation),
|
100
|
-
@"screen": @{
|
101
|
-
@"width": @(screen.width),
|
102
|
-
@"height": @(screen.height)
|
103
|
-
},
|
104
|
-
@"statusBar": @{
|
105
|
-
@"width": @(statusBar.width),
|
106
|
-
@"height": @(statusBar.height)
|
107
|
-
},
|
108
|
-
@"navigationBar": @{
|
109
|
-
@"width": @(navigationBar.width),
|
110
|
-
@"height": @(navigationBar.height)
|
111
|
-
},
|
112
|
-
@"insets": @{
|
113
|
-
@"top": @(insets.top),
|
114
|
-
@"bottom": @(insets.bottom),
|
115
|
-
@"left": @(insets.left),
|
116
|
-
@"right": @(insets.right)
|
117
|
-
}
|
118
|
-
}
|
119
|
-
};
|
120
|
-
|
121
|
-
[weakSelf emitEvent:@"__unistylesOnChange" withBody:body];
|
122
|
-
});
|
123
|
-
|
124
|
-
unistylesRuntime.get()->onPluginChange([=]() {
|
125
|
-
NSDictionary *body = @{
|
126
|
-
@"type": @"plugin"
|
127
|
-
};
|
128
|
-
|
129
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
130
|
-
[weakSelf emitEvent:@"__unistylesOnChange" withBody:body];
|
131
|
-
});
|
132
|
-
});
|
133
|
-
|
134
|
-
unistylesRuntime.get()->onContentSizeCategoryChange([=](std::string contentSizeCategory) {
|
135
|
-
NSDictionary *body = @{
|
136
|
-
@"type": @"dynamicTypeSize",
|
137
|
-
@"payload": @{
|
138
|
-
@"contentSizeCategory": cxxStringToNSString(contentSizeCategory)
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
[weakSelf emitEvent:@"__unistylesOnChange" withBody:body];
|
143
|
-
});
|
63
|
+
void registerUnistylesHostObject(RCTBridge* bridge, UnistylesModule* weakSelf) {
|
64
|
+
std::shared_ptr<react::CallInvoker> callInvoker = bridge.jsCallInvoker;
|
65
|
+
jsi::Runtime* runtime = reinterpret_cast<jsi::Runtime*>(bridge.runtime);
|
66
|
+
auto unistylesRuntime = std::make_shared<UnistylesRuntime>(*runtime, callInvoker);
|
144
67
|
|
145
|
-
weakSelf.platform
|
68
|
+
[weakSelf.platform makeShared:unistylesRuntime.get()];
|
146
69
|
|
147
|
-
auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
|
70
|
+
auto hostObject = jsi::Object::createFromHostObject(*runtime, unistylesRuntime);
|
148
71
|
|
149
|
-
runtime
|
72
|
+
runtime->global().setProperty(*runtime, "__UNISTYLES__", std::move(hostObject));
|
150
73
|
}
|
151
74
|
|
152
75
|
@end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#include "Platform_Shared.h"
|
2
|
+
|
3
|
+
std::string getContentSizeCategory() {
|
4
|
+
UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
5
|
+
|
6
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) {
|
7
|
+
return std::string([@"xxxLarge" UTF8String]);
|
8
|
+
}
|
9
|
+
|
10
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraLarge]) {
|
11
|
+
return std::string([@"xxLarge" UTF8String]);
|
12
|
+
}
|
13
|
+
|
14
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraLarge]) {
|
15
|
+
return std::string([@"xLarge" UTF8String]);
|
16
|
+
}
|
17
|
+
|
18
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryLarge]) {
|
19
|
+
return std::string([@"Large" UTF8String]);
|
20
|
+
}
|
21
|
+
|
22
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryMedium]) {
|
23
|
+
return std::string([@"Medium" UTF8String]);
|
24
|
+
}
|
25
|
+
|
26
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategorySmall]) {
|
27
|
+
return std::string([@"Small" UTF8String]);
|
28
|
+
}
|
29
|
+
|
30
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraSmall]) {
|
31
|
+
return std::string([@"xSmall" UTF8String]);
|
32
|
+
}
|
33
|
+
|
34
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityMedium]) {
|
35
|
+
return std::string([@"accessibilityMedium" UTF8String]);
|
36
|
+
}
|
37
|
+
|
38
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityLarge]) {
|
39
|
+
return std::string([@"accessibilityLarge" UTF8String]);
|
40
|
+
}
|
41
|
+
|
42
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) {
|
43
|
+
return std::string([@"accessibilityExtraLarge" UTF8String]);
|
44
|
+
}
|
45
|
+
|
46
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) {
|
47
|
+
return std::string([@"accessibilityExtraExtraLarge" UTF8String]);
|
48
|
+
}
|
49
|
+
|
50
|
+
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) {
|
51
|
+
return std::string([@"accessibilityExtraExtraExtraLarge" UTF8String]);
|
52
|
+
}
|
53
|
+
|
54
|
+
return std::string([@"unspecified" UTF8String]);
|
55
|
+
}
|
56
|
+
|
57
|
+
std::string getColorScheme() {
|
58
|
+
UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
|
59
|
+
|
60
|
+
switch (colorScheme) {
|
61
|
+
case UIUserInterfaceStyleLight:
|
62
|
+
return UnistylesLightScheme;
|
63
|
+
case UIUserInterfaceStyleDark:
|
64
|
+
return UnistylesDarkScheme;
|
65
|
+
case UIUserInterfaceStyleUnspecified:
|
66
|
+
default:
|
67
|
+
return UnistylesUnspecifiedScheme;
|
68
|
+
}
|
69
|
+
}
|
@@ -1,25 +1,18 @@
|
|
1
1
|
#include <string>
|
2
2
|
#include <map>
|
3
3
|
#include <UnistylesRuntime.h>
|
4
|
+
#include "Platform_Shared.h"
|
4
5
|
|
5
6
|
@interface Platform : NSObject
|
6
7
|
|
7
|
-
@property (nonatomic, assign) Dimensions initialScreen;
|
8
|
-
@property (nonatomic, assign) std::string initialColorScheme;
|
9
|
-
@property (nonatomic, assign) std::string initialContentSizeCategory;
|
10
|
-
@property (nonatomic, assign) Insets initialInsets;
|
11
|
-
@property (nonatomic, assign) Dimensions initialStatusBar;
|
12
|
-
@property (nonatomic, assign) Dimensions initialNavigationBar;
|
13
8
|
@property (nonatomic, assign) void* unistylesRuntime;
|
14
9
|
|
15
10
|
- (instancetype)init;
|
16
11
|
|
17
12
|
- (void)setupListeners;
|
18
|
-
- (void)
|
13
|
+
- (void)makeShared:(void*)runtime;
|
14
|
+
- (void)onWindowChange:(NSNotification *)notification;
|
19
15
|
- (void)onAppearanceChange:(NSNotification *)notification;
|
20
16
|
- (void)onContentSizeCategoryChange:(NSNotification *)notification;
|
21
17
|
|
22
|
-
- (std::string)getColorScheme;
|
23
|
-
- (std::string)getContentSizeCategory:(UIContentSizeCategory)contentSizeCategory;
|
24
|
-
|
25
18
|
@end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
#if TARGET_OS_IOS
|
2
2
|
|
3
3
|
#import "Platform_iOS.h"
|
4
|
-
#import "UnistylesRuntime.h"
|
5
4
|
#import <React/RCTAppearance.h>
|
6
5
|
|
7
6
|
@implementation Platform
|
@@ -9,15 +8,6 @@
|
|
9
8
|
- (instancetype)init {
|
10
9
|
self = [super init];
|
11
10
|
if (self) {
|
12
|
-
UIScreen *screen = [UIScreen mainScreen];
|
13
|
-
UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
14
|
-
|
15
|
-
self.initialScreen = {(int)screen.bounds.size.width, (int)screen.bounds.size.height};
|
16
|
-
self.initialColorScheme = [self getColorScheme];
|
17
|
-
self.initialContentSizeCategory = [self getContentSizeCategory:contentSizeCategory];
|
18
|
-
self.initialStatusBar = [self getStatusBarDimensions];
|
19
|
-
self.initialInsets = [self getInsets];
|
20
|
-
|
21
11
|
[self setupListeners];
|
22
12
|
}
|
23
13
|
return self;
|
@@ -32,17 +22,17 @@
|
|
32
22
|
name: UIContentSizeCategoryDidChangeNotification
|
33
23
|
object: nil];
|
34
24
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
35
|
-
name:
|
36
|
-
object:
|
25
|
+
name:RCTWindowFrameDidChangeNotification
|
26
|
+
object:nil];
|
37
27
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
38
|
-
name:
|
28
|
+
name: RCTUserInterfaceStyleDidChangeNotification
|
39
29
|
object: nil];
|
40
30
|
}
|
41
31
|
|
42
32
|
- (void)setupListeners {
|
43
33
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
44
|
-
selector:@selector(
|
45
|
-
name:
|
34
|
+
selector:@selector(onWindowChange:)
|
35
|
+
name:RCTWindowFrameDidChangeNotification
|
46
36
|
object:nil];
|
47
37
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
48
38
|
selector:@selector(onAppearanceChange:)
|
@@ -54,117 +44,84 @@
|
|
54
44
|
object:nil];
|
55
45
|
}
|
56
46
|
|
57
|
-
- (void)
|
58
|
-
|
47
|
+
- (void)makeShared:(void*)runtime {
|
48
|
+
self.unistylesRuntime = runtime;
|
49
|
+
|
50
|
+
auto unistylesRuntime = ((UnistylesRuntime*)self.unistylesRuntime);
|
51
|
+
|
52
|
+
unistylesRuntime->setScreenDimensionsCallback([self](){
|
53
|
+
return [self getScreenDimensions];
|
54
|
+
});
|
55
|
+
|
56
|
+
unistylesRuntime->setContentSizeCategoryCallback([](){
|
57
|
+
return getContentSizeCategory();
|
58
|
+
});
|
59
|
+
|
60
|
+
unistylesRuntime->setColorSchemeCallback([self](){
|
61
|
+
return getColorScheme();
|
62
|
+
});
|
63
|
+
|
64
|
+
unistylesRuntime->setStatusBarDimensionsCallback([self](){
|
65
|
+
return [self getStatusBarDimensions];
|
66
|
+
});
|
67
|
+
|
68
|
+
unistylesRuntime->setInsetsCallback([self](){
|
69
|
+
return [self getInsets];
|
70
|
+
});
|
71
|
+
|
72
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
73
|
+
unistylesRuntime->screen = [self getScreenDimensions];
|
74
|
+
unistylesRuntime->contentSizeCategory = getContentSizeCategory();
|
75
|
+
unistylesRuntime->colorScheme = getColorScheme();
|
76
|
+
unistylesRuntime->statusBar = [self getStatusBarDimensions];
|
77
|
+
unistylesRuntime->insets = [self getInsets];
|
78
|
+
});
|
79
|
+
}
|
59
80
|
|
81
|
+
- (void)onAppearanceChange:(NSNotification *)notification {
|
60
82
|
if (self.unistylesRuntime != nullptr) {
|
61
|
-
((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(
|
83
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(getColorScheme());
|
62
84
|
}
|
63
85
|
}
|
64
86
|
|
65
87
|
- (void)onContentSizeCategoryChange:(NSNotification *)notification {
|
66
|
-
UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
67
|
-
|
68
88
|
if (self.unistylesRuntime != nullptr) {
|
69
|
-
((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange(
|
89
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange(getContentSizeCategory());
|
70
90
|
}
|
71
91
|
}
|
72
92
|
|
73
|
-
- (void)
|
93
|
+
- (void)onWindowChange:(NSNotification *)notification {
|
74
94
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
75
|
-
|
76
|
-
Dimensions screen = {(int)mainScreen.bounds.size.width, (int)mainScreen.bounds.size.height};
|
95
|
+
Dimensions screen = [self getScreenDimensions];
|
77
96
|
Insets insets = [self getInsets];
|
78
97
|
Dimensions statusBar = [self getStatusBarDimensions];
|
79
|
-
Dimensions navigationBar = [self getNavigationBarDimensions];
|
80
98
|
|
81
99
|
if (self.unistylesRuntime != nullptr) {
|
82
|
-
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange(screen, insets, statusBar,
|
100
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange(screen, insets, statusBar, std::nullopt);
|
83
101
|
}
|
84
102
|
});
|
85
103
|
}
|
86
104
|
|
87
|
-
- (std::string)getColorScheme {
|
88
|
-
UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
|
89
|
-
|
90
|
-
switch (colorScheme) {
|
91
|
-
case UIUserInterfaceStyleLight:
|
92
|
-
return UnistylesLightScheme;
|
93
|
-
case UIUserInterfaceStyleDark:
|
94
|
-
return UnistylesDarkScheme;
|
95
|
-
case UIUserInterfaceStyleUnspecified:
|
96
|
-
default:
|
97
|
-
return UnistylesUnspecifiedScheme;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
105
|
- (Insets)getInsets {
|
102
106
|
UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
|
103
107
|
UIEdgeInsets safeArea = window.safeAreaInsets;
|
104
|
-
|
108
|
+
|
105
109
|
return {(int)safeArea.top, (int)safeArea.bottom, (int)safeArea.left, (int)safeArea.right};
|
106
110
|
}
|
107
111
|
|
108
112
|
- (Dimensions)getStatusBarDimensions {
|
109
|
-
|
110
|
-
|
113
|
+
UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
|
114
|
+
CGRect statusBarFrame = window.windowScene.statusBarManager.statusBarFrame;
|
115
|
+
|
111
116
|
return {(int)statusBarFrame.size.width, (int)statusBarFrame.size.height};
|
112
117
|
}
|
113
118
|
|
114
|
-
- (Dimensions)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
- (std::string)getContentSizeCategory:(UIContentSizeCategory)contentSizeCategory {
|
119
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) {
|
120
|
-
return std::string([@"xxxLarge" UTF8String]);
|
121
|
-
}
|
122
|
-
|
123
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraLarge]) {
|
124
|
-
return std::string([@"xxLarge" UTF8String]);
|
125
|
-
}
|
126
|
-
|
127
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraLarge]) {
|
128
|
-
return std::string([@"xLarge" UTF8String]);
|
129
|
-
}
|
130
|
-
|
131
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryLarge]) {
|
132
|
-
return std::string([@"Large" UTF8String]);
|
133
|
-
}
|
134
|
-
|
135
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryMedium]) {
|
136
|
-
return std::string([@"Medium" UTF8String]);
|
137
|
-
}
|
138
|
-
|
139
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategorySmall]) {
|
140
|
-
return std::string([@"Small" UTF8String]);
|
141
|
-
}
|
142
|
-
|
143
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraSmall]) {
|
144
|
-
return std::string([@"xSmall" UTF8String]);
|
145
|
-
}
|
146
|
-
|
147
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityMedium]) {
|
148
|
-
return std::string([@"accessibilityMedium" UTF8String]);
|
149
|
-
}
|
150
|
-
|
151
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityLarge]) {
|
152
|
-
return std::string([@"accessibilityLarge" UTF8String]);
|
153
|
-
}
|
154
|
-
|
155
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) {
|
156
|
-
return std::string([@"accessibilityExtraLarge" UTF8String]);
|
157
|
-
}
|
158
|
-
|
159
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) {
|
160
|
-
return std::string([@"accessibilityExtraExtraLarge" UTF8String]);
|
161
|
-
}
|
162
|
-
|
163
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) {
|
164
|
-
return std::string([@"accessibilityExtraExtraExtraLarge" UTF8String]);
|
165
|
-
}
|
119
|
+
- (Dimensions)getScreenDimensions {
|
120
|
+
UIViewController *presentedViewController = RCTPresentedViewController();
|
121
|
+
CGRect windowFrame = presentedViewController.view.window.frame;
|
122
|
+
Dimensions screenDimension = {(int)windowFrame.size.width, (int)windowFrame.size.height};
|
166
123
|
|
167
|
-
return
|
124
|
+
return screenDimension;
|
168
125
|
}
|
169
126
|
|
170
127
|
@end
|
@@ -4,18 +4,13 @@
|
|
4
4
|
|
5
5
|
@interface Platform : NSObject
|
6
6
|
|
7
|
-
@property (nonatomic, assign) Dimensions initialScreen;
|
8
|
-
@property (nonatomic, assign) std::string initialColorScheme;
|
9
|
-
@property (nonatomic, assign) std::string initialContentSizeCategory;
|
10
|
-
@property (nonatomic, assign) Insets initialInsets;
|
11
|
-
@property (nonatomic, assign) Dimensions initialStatusBar;
|
12
|
-
@property (nonatomic, assign) Dimensions initialNavigationBar;
|
13
7
|
@property (nonatomic, assign) void* unistylesRuntime;
|
14
8
|
|
15
9
|
- (instancetype)init;
|
16
10
|
|
17
11
|
- (void)setupListeners;
|
18
|
-
- (void)
|
12
|
+
- (void)makeShared:(void*)runtime;
|
13
|
+
- (void)onWindowChange;
|
19
14
|
- (void)onAppearanceChange;
|
20
15
|
|
21
16
|
- (std::string)getColorScheme;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
#if TARGET_OS_OSX
|
2
2
|
|
3
3
|
#import "Platform_macOS.h"
|
4
|
-
#import "UnistylesRuntime.h"
|
5
4
|
#import <React/RCTUtils.h>
|
6
5
|
|
7
6
|
@implementation Platform
|
@@ -9,15 +8,6 @@
|
|
9
8
|
- (instancetype)init {
|
10
9
|
self = [super init];
|
11
10
|
if (self) {
|
12
|
-
NSWindow *window = RCTSharedApplication().mainWindow;
|
13
|
-
|
14
|
-
self.initialScreen = {(int)window.frame.size.width, (int)window.frame.size.height};
|
15
|
-
self.initialContentSizeCategory = std::string([@"unspecified" UTF8String]);
|
16
|
-
self.initialColorScheme = [self getColorScheme];
|
17
|
-
self.initialStatusBar = [self getStatusBarDimensions];
|
18
|
-
self.initialNavigationBar = [self getNavigationBarDimensions];
|
19
|
-
self.initialInsets = [self getInsets];
|
20
|
-
|
21
11
|
[self setupListeners];
|
22
12
|
}
|
23
13
|
return self;
|
@@ -27,27 +17,46 @@
|
|
27
17
|
if (self.unistylesRuntime != nullptr) {
|
28
18
|
self.unistylesRuntime = nullptr;
|
29
19
|
}
|
30
|
-
|
20
|
+
|
31
21
|
NSWindow *window = RCTSharedApplication().mainWindow;
|
32
|
-
|
22
|
+
|
33
23
|
[window removeObserver:self forKeyPath:@"effectiveAppearance"];
|
34
24
|
[window removeObserver:self forKeyPath:@"frame"];
|
35
25
|
}
|
36
26
|
|
37
27
|
- (void)setupListeners {
|
38
28
|
NSWindow *window = RCTSharedApplication().mainWindow;
|
39
|
-
|
29
|
+
|
40
30
|
[window addObserver:self forKeyPath:@"effectiveAppearance" options:NSKeyValueObservingOptionNew context:nil];
|
41
31
|
[window addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
|
42
32
|
}
|
43
33
|
|
34
|
+
- (void)makeShared:(void*)runtime {
|
35
|
+
self.unistylesRuntime = runtime;
|
36
|
+
|
37
|
+
auto unistylesRuntime = ((UnistylesRuntime*)self.unistylesRuntime);
|
38
|
+
|
39
|
+
unistylesRuntime->setScreenDimensionsCallback([self](){
|
40
|
+
return [self getScreenDimensions];
|
41
|
+
});
|
42
|
+
|
43
|
+
unistylesRuntime->setColorSchemeCallback([self](){
|
44
|
+
return [self getColorScheme];
|
45
|
+
});
|
46
|
+
|
47
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
48
|
+
unistylesRuntime->screen = [self getScreenDimensions];
|
49
|
+
unistylesRuntime->colorScheme = [self getColorScheme];
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
44
53
|
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
|
45
54
|
if ([keyPath isEqualToString:@"effectiveAppearance"]) {
|
46
55
|
return [self onAppearanceChange];
|
47
56
|
}
|
48
|
-
|
57
|
+
|
49
58
|
if ([keyPath isEqualToString:@"frame"]) {
|
50
|
-
return [self
|
59
|
+
return [self onWindowChange];
|
51
60
|
}
|
52
61
|
}
|
53
62
|
|
@@ -59,19 +68,15 @@
|
|
59
68
|
}
|
60
69
|
}
|
61
70
|
|
62
|
-
- (void)
|
63
|
-
|
64
|
-
|
65
|
-
Insets insets = [self getInsets];
|
66
|
-
Dimensions statusBar = [self getStatusBarDimensions];
|
67
|
-
Dimensions navigationBar = [self getNavigationBarDimensions];
|
68
|
-
|
71
|
+
- (void)onWindowChange {
|
72
|
+
Dimensions screen = [self getScreenDimensions];
|
73
|
+
|
69
74
|
if (self.unistylesRuntime != nullptr) {
|
70
75
|
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange(
|
71
76
|
screen,
|
72
|
-
|
73
|
-
|
74
|
-
|
77
|
+
std::nullopt,
|
78
|
+
std::nullopt,
|
79
|
+
std::nullopt
|
75
80
|
);
|
76
81
|
}
|
77
82
|
}
|
@@ -82,20 +87,15 @@
|
|
82
87
|
if (appearance.name == NSAppearanceNameDarkAqua) {
|
83
88
|
return UnistylesDarkScheme;
|
84
89
|
}
|
85
|
-
|
86
|
-
return UnistylesLightScheme;
|
87
|
-
}
|
88
|
-
|
89
|
-
- (Insets)getInsets {
|
90
|
-
return {0, 0, 0, 0};
|
91
|
-
}
|
92
90
|
|
93
|
-
|
94
|
-
return {0, 0};
|
91
|
+
return UnistylesLightScheme;
|
95
92
|
}
|
96
93
|
|
97
|
-
- (Dimensions)
|
98
|
-
|
94
|
+
- (Dimensions)getScreenDimensions {
|
95
|
+
NSWindow *window = RCTSharedApplication().mainWindow;
|
96
|
+
Dimensions screenDimension = {(int)window.frame.size.width, (int)window.frame.size.height};
|
97
|
+
|
98
|
+
return screenDimension;
|
99
99
|
}
|
100
100
|
|
101
101
|
@end
|
@@ -1,23 +1,16 @@
|
|
1
1
|
#include <string>
|
2
2
|
#include <map>
|
3
|
-
#include
|
3
|
+
#include "Platform_Shared.h"
|
4
4
|
|
5
5
|
@interface Platform : NSObject
|
6
6
|
|
7
|
-
@property (nonatomic, assign) Dimensions initialScreen;
|
8
|
-
@property (nonatomic, assign) std::string initialColorScheme;
|
9
|
-
@property (nonatomic, assign) std::string initialContentSizeCategory;
|
10
|
-
@property (nonatomic, assign) Insets initialInsets;
|
11
|
-
@property (nonatomic, assign) Dimensions initialStatusBar;
|
12
|
-
@property (nonatomic, assign) Dimensions initialNavigationBar;
|
13
7
|
@property (nonatomic, assign) void* unistylesRuntime;
|
14
8
|
|
15
9
|
- (instancetype)init;
|
16
10
|
|
11
|
+
- (void)makeShared:(void*)runtime;
|
17
12
|
- (void)onAppearanceChange:(NSNotification *)notification;
|
18
13
|
- (void)onContentSizeCategoryChange:(NSNotification *)notification;
|
19
14
|
|
20
|
-
- (std::string)getColorScheme;
|
21
|
-
|
22
15
|
@end
|
23
16
|
|