react-native-unistyles 2.8.0-beta.1 → 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 +2 -9
- package/ios/platform/Platform_iOS.mm +47 -94
- package/ios/platform/Platform_macOS.h +1 -6
- package/ios/platform/Platform_macOS.mm +29 -29
- package/ios/platform/Platform_tvOS.h +2 -9
- package/ios/platform/Platform_tvOS.mm +30 -92
- package/ios/platform/Platform_visionOS.h +2 -8
- package/ios/platform/Platform_visionOS.mm +28 -83
- package/package.json +1 -1
- package/react-native-unistyles.podspec +3 -0
- package/ios/UnistylesHelpers.h +0 -3
- package/ios/UnistylesHelpers.mm +0 -5
@@ -1,7 +1,6 @@
|
|
1
1
|
#if TARGET_OS_TV
|
2
2
|
|
3
3
|
#import "Platform_tvOS.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;
|
@@ -47,101 +37,49 @@
|
|
47
37
|
object:nil];
|
48
38
|
}
|
49
39
|
|
50
|
-
- (void)
|
51
|
-
|
40
|
+
- (void)makeShared:(void*)runtime {
|
41
|
+
self.unistylesRuntime = runtime;
|
42
|
+
|
43
|
+
auto unistylesRuntime = ((UnistylesRuntime*)self.unistylesRuntime);
|
44
|
+
|
45
|
+
unistylesRuntime->setScreenDimensionsCallback([self](){
|
46
|
+
return [self getScreenDimensions];
|
47
|
+
});
|
52
48
|
|
53
|
-
|
54
|
-
(
|
55
|
-
}
|
49
|
+
unistylesRuntime->setColorSchemeCallback([](){
|
50
|
+
return getColorScheme();
|
51
|
+
});
|
52
|
+
|
53
|
+
unistylesRuntime->setContentSizeCategoryCallback([](){
|
54
|
+
return getContentSizeCategory();
|
55
|
+
});
|
56
|
+
|
57
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
58
|
+
unistylesRuntime->screen = [self getScreenDimensions];
|
59
|
+
unistylesRuntime->contentSizeCategory = getContentSizeCategory();
|
60
|
+
unistylesRuntime->colorScheme = getColorScheme();
|
61
|
+
});
|
56
62
|
}
|
57
63
|
|
58
|
-
- (void)
|
59
|
-
UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
60
|
-
|
64
|
+
- (void)onAppearanceChange:(NSNotification *)notification {
|
61
65
|
if (self.unistylesRuntime != nullptr) {
|
62
|
-
((UnistylesRuntime*)self.unistylesRuntime)->
|
66
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(getColorScheme());
|
63
67
|
}
|
64
68
|
}
|
65
69
|
|
66
|
-
- (
|
67
|
-
|
68
|
-
|
69
|
-
switch (colorScheme) {
|
70
|
-
case UIUserInterfaceStyleLight:
|
71
|
-
return UnistylesLightScheme;
|
72
|
-
case UIUserInterfaceStyleDark:
|
73
|
-
return UnistylesDarkScheme;
|
74
|
-
case UIUserInterfaceStyleUnspecified:
|
75
|
-
default:
|
76
|
-
return UnistylesUnspecifiedScheme;
|
70
|
+
- (void)onContentSizeCategoryChange:(NSNotification *)notification {
|
71
|
+
if (self.unistylesRuntime != nullptr) {
|
72
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange(getContentSizeCategory());
|
77
73
|
}
|
78
74
|
}
|
79
75
|
|
80
|
-
- (
|
81
|
-
|
82
|
-
}
|
83
|
-
|
84
|
-
- (Dimensions)getStatusBarDimensions {
|
85
|
-
return {0, 0};
|
86
|
-
}
|
87
|
-
|
88
|
-
- (Dimensions)getNavigationBarDimensions {
|
89
|
-
return {0, 0};
|
90
|
-
}
|
91
|
-
|
92
|
-
- (std::string)getContentSizeCategory:(UIContentSizeCategory)contentSizeCategory {
|
93
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) {
|
94
|
-
return std::string([@"xxxLarge" UTF8String]);
|
95
|
-
}
|
96
|
-
|
97
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraLarge]) {
|
98
|
-
return std::string([@"xxLarge" UTF8String]);
|
99
|
-
}
|
100
|
-
|
101
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraLarge]) {
|
102
|
-
return std::string([@"xLarge" UTF8String]);
|
103
|
-
}
|
104
|
-
|
105
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryLarge]) {
|
106
|
-
return std::string([@"Large" UTF8String]);
|
107
|
-
}
|
108
|
-
|
109
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryMedium]) {
|
110
|
-
return std::string([@"Medium" UTF8String]);
|
111
|
-
}
|
112
|
-
|
113
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategorySmall]) {
|
114
|
-
return std::string([@"Small" UTF8String]);
|
115
|
-
}
|
116
|
-
|
117
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraSmall]) {
|
118
|
-
return std::string([@"xSmall" UTF8String]);
|
119
|
-
}
|
76
|
+
- (Dimensions)getScreenDimensions {
|
77
|
+
UIScreen *screen = [UIScreen mainScreen];
|
78
|
+
Dimensions screenDimension = {(int)screen.bounds.size.width, (int)screen.bounds.size.height};
|
120
79
|
|
121
|
-
|
122
|
-
return std::string([@"accessibilityMedium" UTF8String]);
|
123
|
-
}
|
124
|
-
|
125
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityLarge]) {
|
126
|
-
return std::string([@"accessibilityLarge" UTF8String]);
|
127
|
-
}
|
128
|
-
|
129
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) {
|
130
|
-
return std::string([@"accessibilityExtraLarge" UTF8String]);
|
131
|
-
}
|
132
|
-
|
133
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) {
|
134
|
-
return std::string([@"accessibilityExtraExtraLarge" UTF8String]);
|
135
|
-
}
|
136
|
-
|
137
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) {
|
138
|
-
return std::string([@"accessibilityExtraExtraExtraLarge" UTF8String]);
|
139
|
-
}
|
140
|
-
|
141
|
-
return std::string([@"unspecified" UTF8String]);
|
80
|
+
return screenDimension;
|
142
81
|
}
|
143
82
|
|
144
83
|
@end
|
145
84
|
|
146
|
-
|
147
85
|
#endif
|
@@ -1,23 +1,17 @@
|
|
1
1
|
#include <string>
|
2
2
|
#include <map>
|
3
|
-
#include <UnistylesRuntime.h>
|
4
3
|
#import <UIKit/UIKit.h>
|
4
|
+
#import "Platform_Shared.h"
|
5
5
|
|
6
6
|
@interface Platform : NSObject
|
7
7
|
|
8
|
-
@property (nonatomic, assign) Dimensions initialScreen;
|
9
|
-
@property (nonatomic, assign) std::string initialColorScheme;
|
10
|
-
@property (nonatomic, assign) std::string initialContentSizeCategory;
|
11
|
-
@property (nonatomic, assign) Insets initialInsets;
|
12
|
-
@property (nonatomic, assign) Dimensions initialStatusBar;
|
13
|
-
@property (nonatomic, assign) Dimensions initialNavigationBar;
|
14
8
|
@property (nonatomic, assign) void* unistylesRuntime;
|
15
9
|
|
16
10
|
- (instancetype)init;
|
17
11
|
|
18
12
|
- (void)setupListeners;
|
13
|
+
- (void)makeShared:(void*)runtime;
|
19
14
|
- (UIWindow *)getMainWindow;
|
20
|
-
- (std::string)getContentSizeCategory:(UIContentSizeCategory)contentSizeCategory;
|
21
15
|
- (void)onContentSizeCategoryChange:(NSNotification *)notification;
|
22
16
|
- (void)onWindowChange:(NSNotification *)notification;
|
23
17
|
|
@@ -9,15 +9,6 @@
|
|
9
9
|
- (instancetype)init {
|
10
10
|
self = [super init];
|
11
11
|
if (self) {
|
12
|
-
UIWindow* mainWindow = [self getMainWindow];
|
13
|
-
UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
14
|
-
|
15
|
-
self.initialScreen = {(int)mainWindow.bounds.size.width, (int)mainWindow.bounds.size.height};
|
16
|
-
self.initialColorScheme = UnistylesUnspecifiedScheme;
|
17
|
-
self.initialContentSizeCategory = [self getContentSizeCategory:contentSizeCategory];
|
18
|
-
self.initialStatusBar = [self getStatusBarDimensions];
|
19
|
-
self.initialInsets = [self getInsets];
|
20
|
-
|
21
12
|
[self setupListeners];
|
22
13
|
}
|
23
14
|
return self;
|
@@ -68,97 +59,51 @@
|
|
68
59
|
object:nil];
|
69
60
|
}
|
70
61
|
|
71
|
-
- (void)
|
72
|
-
|
62
|
+
- (void)makeShared:(void*)runtime {
|
63
|
+
self.unistylesRuntime = runtime;
|
64
|
+
|
65
|
+
auto unistylesRuntime = ((UnistylesRuntime*)self.unistylesRuntime);
|
66
|
+
|
67
|
+
unistylesRuntime->setScreenDimensionsCallback([self](){
|
68
|
+
return [self getScreenDimensions];
|
69
|
+
});
|
70
|
+
|
71
|
+
unistylesRuntime->setContentSizeCategoryCallback([](){
|
72
|
+
return getContentSizeCategory();
|
73
|
+
});
|
74
|
+
|
75
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
76
|
+
unistylesRuntime->screen = [self getScreenDimensions];
|
77
|
+
unistylesRuntime->contentSizeCategory = getContentSizeCategory();
|
78
|
+
});
|
79
|
+
}
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
Dimensions statusBar = [self getStatusBarDimensions];
|
77
|
-
Dimensions navigationBar = [self getNavigationBarDimensions];
|
81
|
+
- (void)onWindowChange:(NSNotification *)notification {
|
82
|
+
Dimensions screen = [self getScreenDimensions];
|
78
83
|
|
79
84
|
if (self.unistylesRuntime != nullptr) {
|
80
85
|
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange(
|
81
86
|
screen,
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
std::nullopt,
|
88
|
+
std::nullopt,
|
89
|
+
std::nullopt
|
85
90
|
);
|
86
91
|
}
|
87
92
|
}
|
88
93
|
|
89
94
|
- (void)onContentSizeCategoryChange:(NSNotification *)notification {
|
90
|
-
UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
91
|
-
|
92
95
|
if (self.unistylesRuntime != nullptr) {
|
93
|
-
((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange(
|
96
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange(getContentSizeCategory());
|
94
97
|
}
|
95
98
|
}
|
96
99
|
|
97
|
-
- (
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
- (Dimensions)getStatusBarDimensions {
|
102
|
-
return {0, 0};
|
103
|
-
}
|
104
|
-
|
105
|
-
- (Dimensions)getNavigationBarDimensions {
|
106
|
-
return {0, 0};
|
107
|
-
}
|
108
|
-
|
109
|
-
- (std::string)getContentSizeCategory:(UIContentSizeCategory)contentSizeCategory {
|
110
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) {
|
111
|
-
return std::string([@"xxxLarge" UTF8String]);
|
112
|
-
}
|
113
|
-
|
114
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraExtraLarge]) {
|
115
|
-
return std::string([@"xxLarge" UTF8String]);
|
116
|
-
}
|
117
|
-
|
118
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraLarge]) {
|
119
|
-
return std::string([@"xLarge" UTF8String]);
|
120
|
-
}
|
121
|
-
|
122
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryLarge]) {
|
123
|
-
return std::string([@"Large" UTF8String]);
|
124
|
-
}
|
125
|
-
|
126
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryMedium]) {
|
127
|
-
return std::string([@"Medium" UTF8String]);
|
128
|
-
}
|
129
|
-
|
130
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategorySmall]) {
|
131
|
-
return std::string([@"Small" UTF8String]);
|
132
|
-
}
|
133
|
-
|
134
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryExtraSmall]) {
|
135
|
-
return std::string([@"xSmall" UTF8String]);
|
136
|
-
}
|
137
|
-
|
138
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityMedium]) {
|
139
|
-
return std::string([@"accessibilityMedium" UTF8String]);
|
140
|
-
}
|
141
|
-
|
142
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityLarge]) {
|
143
|
-
return std::string([@"accessibilityLarge" UTF8String]);
|
144
|
-
}
|
145
|
-
|
146
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) {
|
147
|
-
return std::string([@"accessibilityExtraLarge" UTF8String]);
|
148
|
-
}
|
149
|
-
|
150
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) {
|
151
|
-
return std::string([@"accessibilityExtraExtraLarge" UTF8String]);
|
152
|
-
}
|
153
|
-
|
154
|
-
if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) {
|
155
|
-
return std::string([@"accessibilityExtraExtraExtraLarge" UTF8String]);
|
156
|
-
}
|
100
|
+
- (Dimensions)getScreenDimensions {
|
101
|
+
UIWindow* mainWindow = [self getMainWindow];
|
102
|
+
Dimensions screenDimension = {(int)mainWindow.frame.size.width, (int)mainWindow.frame.size.height};
|
157
103
|
|
158
|
-
return
|
104
|
+
return screenDimension;
|
159
105
|
}
|
160
106
|
|
161
107
|
@end
|
162
108
|
|
163
|
-
|
164
109
|
#endif
|
package/package.json
CHANGED
package/ios/UnistylesHelpers.h
DELETED