react-native-unistyles 2.6.0 → 2.7.0

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/README.md CHANGED
@@ -10,10 +10,11 @@
10
10
  [![platform - ios](https://img.shields.io/badge/iOS-000?logo=apple&style=for-the-badge)](https://developer.apple.com/ios/)
11
11
  [![platform - macos](https://img.shields.io/badge/macOS-000?logo=apple&style=for-the-badge)](https://developer.apple.com/macos/)
12
12
  [![platform - appletv](https://img.shields.io/badge/Apple_TV-000?logo=apple&style=for-the-badge)](https://developer.apple.com/tvos/)
13
- [![platform - windows](https://img.shields.io/badge/windows-00a2ed?logo=windows&style=for-the-badge)](https://microsoft.github.io/react-native-windows/docs/getting-started)
14
- [![platform - ssr](https://img.shields.io/badge/SSR-black?style=for-the-badge&logo=next.js&logoColor=white)](https://nextjs.org/)
13
+ [![platform - visionos](https://img.shields.io/badge/vision_os-000?logo=apple&style=for-the-badge)](https://developer.apple.com/visionos/)
15
14
  [![platform - android](https://img.shields.io/badge/Android-44CD11?style=for-the-badge&logo=android&logoColor=white)](https://developer.android.com/)
16
15
  [![platform - androidtv](https://img.shields.io/badge/Android_TV-44CD11?style=for-the-badge&logo=android&logoColor=white)](https://www.android.com/intl/pl_pl/tv/)
16
+ [![platform - windows](https://img.shields.io/badge/windows-00a2ed?logo=windows&style=for-the-badge)](https://microsoft.github.io/react-native-windows/docs/getting-started)
17
+ [![platform - ssr](https://img.shields.io/badge/SSR-black?style=for-the-badge&logo=next.js&logoColor=white)](https://nextjs.org/)
17
18
 
18
19
  <a href="https://github.com/jpudysz?tab=followers">
19
20
  <img src="https://img.shields.io/github/followers/jpudysz?label=Follow%20%40jpudysz&style=social" />
@@ -220,6 +220,10 @@ jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& p
220
220
  1,
221
221
  [this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
222
222
  bool enableAdaptiveThemes = arguments[0].asBool();
223
+
224
+ if (enableAdaptiveThemes && this->colorScheme == UnistylesUnspecifiedScheme) {
225
+ throw jsi::JSError(runtime, UnistylesErrorAdaptiveThemesNotSupported);
226
+ }
223
227
 
224
228
  this->hasAdaptiveThemes = enableAdaptiveThemes;
225
229
 
@@ -17,6 +17,7 @@ const std::string UnistylesUnspecifiedScheme = "unspecified";
17
17
  const std::string UnistylesErrorBreakpointsCannotBeEmpty = "You are trying to register empty breakpoints object";
18
18
  const std::string UnistylesErrorBreakpointsMustStartFromZero = "You are trying to register breakpoints that don't start from 0";
19
19
  const std::string UnistylesErrorThemesCannotBeEmpty = "You are trying to register empty themes object";
20
+ const std::string UnistylesErrorAdaptiveThemesNotSupported = "Your platform doesn't support adaptive themes";
20
21
 
21
22
  struct Dimensions {
22
23
  int width;
@@ -8,6 +8,8 @@
8
8
  #import "Platform_iOS.h"
9
9
  #elif TARGET_OS_TV
10
10
  #import "Platform_tvOS.h"
11
+ #elif TARGET_OS_VISION
12
+ #import "Platform_visionOS.h"
11
13
  #endif
12
14
 
13
15
  @interface UnistylesModule : RCTEventEmitter<RCTBridgeModule>
@@ -0,0 +1,25 @@
1
+ #include <string>
2
+ #include <map>
3
+ #include <UnistylesRuntime.h>
4
+ #import <UIKit/UIKit.h>
5
+
6
+ @interface Platform : NSObject
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
+ @property (nonatomic, assign) void* unistylesRuntime;
15
+
16
+ - (instancetype)init;
17
+
18
+ - (void)setupListeners;
19
+ - (UIWindow *)getMainWindow;
20
+ - (std::string)getContentSizeCategory:(UIContentSizeCategory)contentSizeCategory;
21
+ - (void)onContentSizeCategoryChange:(NSNotification *)notification;
22
+ - (void)onWindowResize:(NSNotification *)notification;
23
+
24
+ @end
25
+
@@ -0,0 +1,164 @@
1
+ #if TARGET_OS_VISION
2
+
3
+ #import "Platform_visionOS.h"
4
+ #import "UnistylesRuntime.h"
5
+ #import <React/RCTAppearance.h>
6
+
7
+ @implementation Platform
8
+
9
+ - (instancetype)init {
10
+ self = [super init];
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
+ [self setupListeners];
22
+ }
23
+ return self;
24
+ }
25
+
26
+ - (UIWindow *)getMainWindow {
27
+ if (RCTRunningInAppExtension()) {
28
+ return nil;
29
+ }
30
+
31
+ for (UIScene* scene in RCTSharedApplication().connectedScenes) {
32
+ if (scene.activationState != UISceneActivationStateForegroundActive || ![scene isKindOfClass:[UIWindowScene class]]) {
33
+ continue;
34
+ }
35
+ UIWindowScene *windowScene = (UIWindowScene *)scene;
36
+
37
+ for (UIWindow *window in windowScene.windows) {
38
+ if (window.isKeyWindow) {
39
+ return window;
40
+ }
41
+ }
42
+ }
43
+
44
+ return nil;
45
+ }
46
+
47
+ - (void)dealloc {
48
+ if (self.unistylesRuntime != nullptr) {
49
+ self.unistylesRuntime = nullptr;
50
+ }
51
+
52
+ [[NSNotificationCenter defaultCenter] removeObserver:self
53
+ name: UIContentSizeCategoryDidChangeNotification
54
+ object: nil];
55
+ [[NSNotificationCenter defaultCenter] removeObserver:self
56
+ name: RCTWindowFrameDidChangeNotification
57
+ object: nil];
58
+ }
59
+
60
+ - (void)setupListeners {
61
+ [[NSNotificationCenter defaultCenter] addObserver:self
62
+ selector:@selector(onContentSizeCategoryChange:)
63
+ name:UIContentSizeCategoryDidChangeNotification
64
+ object:nil];
65
+ [[NSNotificationCenter defaultCenter] addObserver:self
66
+ selector:@selector(onWindowResize:)
67
+ name:RCTWindowFrameDidChangeNotification
68
+ object:nil];
69
+ }
70
+
71
+ - (void)onWindowResize:(NSNotification *)notification {
72
+ UIWindow* mainWindow = [self getMainWindow];
73
+
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];
78
+
79
+ if (self.unistylesRuntime != nullptr) {
80
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange(
81
+ screen,
82
+ insets,
83
+ statusBar,
84
+ navigationBar
85
+ );
86
+ }
87
+ }
88
+
89
+ - (void)onContentSizeCategoryChange:(NSNotification *)notification {
90
+ UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
91
+
92
+ if (self.unistylesRuntime != nullptr) {
93
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange([self getContentSizeCategory:contentSizeCategory]);
94
+ }
95
+ }
96
+
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
+ }
157
+
158
+ return std::string([@"unspecified" UTF8String]);
159
+ }
160
+
161
+ @end
162
+
163
+
164
+ #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -44,6 +44,7 @@
44
44
  "react-native-windows",
45
45
  "react-native-web",
46
46
  "react-native-tvos",
47
+ "react-native-visionos",
47
48
  "expo"
48
49
  ],
49
50
  "repository": "https://github.com/jpudysz/react-native-unistyles",
@@ -119,6 +120,7 @@
119
120
  "examples/win",
120
121
  "examples/bare",
121
122
  "examples/tv",
123
+ "examples/vision",
122
124
  "docs"
123
125
  ],
124
126
  "packageManager": "yarn@3.6.4",
@@ -133,6 +135,7 @@
133
135
  "<rootDir>/examples/win/node_modules",
134
136
  "<rootDir>/examples/bare/node_modules",
135
137
  "<rootDir>/examples/tv/node_modules",
138
+ "<rootDir>/examples/vision/node_modules",
136
139
  "<rootDir>/docs/node_modules",
137
140
  "<rootDir>/lib/"
138
141
  ],
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
- s.platforms = { :ios => min_ios_version_supported, :osx => "10.14", :tvos => "9.0" }
13
+ s.platforms = { :ios => min_ios_version_supported, :osx => "10.14", :tvos => "9.0", :visionos => "1.0" }
14
14
  s.source = { :git => package["repository"], :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = [