react-native-unistyles 2.8.0-beta.1 → 2.8.0-beta.2

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.
@@ -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)onAppearanceChange:(NSNotification *)notification {
51
- std::string colorScheme = [self getColorScheme];
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
- if (self.unistylesRuntime != nullptr) {
54
- ((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
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)onContentSizeCategoryChange:(NSNotification *)notification {
59
- UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
60
-
64
+ - (void)onAppearanceChange:(NSNotification *)notification {
61
65
  if (self.unistylesRuntime != nullptr) {
62
- ((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange([self getContentSizeCategory:contentSizeCategory]);
66
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(getColorScheme());
63
67
  }
64
68
  }
65
69
 
66
- - (std::string)getColorScheme {
67
- UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
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
- - (Insets)getInsets {
81
- return {0, 0, 0, 0};
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
- if ([contentSizeCategory isEqualToString:UIContentSizeCategoryAccessibilityMedium]) {
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)onWindowChange:(NSNotification *)notification {
72
- UIWindow* mainWindow = [self getMainWindow];
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
- Dimensions screen = {(int)mainWindow.frame.size.width, (int)mainWindow.frame.size.height};
75
- Insets insets = [self getInsets];
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
- insets,
83
- statusBar,
84
- navigationBar
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([self getContentSizeCategory:contentSizeCategory]);
96
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange(getContentSizeCategory());
94
97
  }
95
98
  }
96
99
 
97
- - (Insets)getInsets {
98
- return {0, 0, 0, 0};
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 std::string([@"unspecified" UTF8String]);
104
+ return screenDimension;
159
105
  }
160
106
 
161
107
  @end
162
108
 
163
-
164
109
  #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.8.0-beta.1",
3
+ "version": "2.8.0-beta.2",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -17,6 +17,9 @@ Pod::Spec.new do |s|
17
17
  "ios/**/*.{h,mm}",
18
18
  "cxx/*.{h,cpp}"
19
19
  ]
20
+ s.pod_target_xcconfig = {
21
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20"
22
+ }
20
23
 
21
24
  install_modules_dependencies(s)
22
25
  end
@@ -1,3 +0,0 @@
1
- #include <string>
2
-
3
- NSString* cxxStringToNSString(std::string);
@@ -1,5 +0,0 @@
1
- #import "UnistylesHelpers.h"
2
-
3
- NSString* cxxStringToNSString(std::string cxxString) {
4
- return [NSString stringWithUTF8String:cxxString.c_str()];
5
- }