react-native-unistyles 2.6.0-rc.0 → 2.6.0-rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,8 @@
6
6
  #import "Platform_macOS.h"
7
7
  #elif TARGET_OS_IOS
8
8
  #import "Platform_iOS.h"
9
+ #elif TARGET_OS_TV
10
+ #import "Platform_tvOS.h"
9
11
  #endif
10
12
 
11
13
  @interface UnistylesModule : RCTEventEmitter<RCTBridgeModule>
@@ -0,0 +1,23 @@
1
+ #include <string>
2
+ #include <map>
3
+ #include <UnistylesRuntime.h>
4
+
5
+ @interface Platform : NSObject
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
+ @property (nonatomic, assign) void* unistylesRuntime;
14
+
15
+ - (instancetype)init;
16
+
17
+ - (void)onAppearanceChange:(NSNotification *)notification;
18
+ - (void)onContentSizeCategoryChange:(NSNotification *)notification;
19
+
20
+ - (std::string)getColorScheme;
21
+
22
+ @end
23
+
@@ -0,0 +1,147 @@
1
+ #if TARGET_OS_TV
2
+
3
+ #import "Platform_tvOS.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
+ 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
+ [self setupListeners];
22
+ }
23
+ return self;
24
+ }
25
+
26
+ - (void)dealloc {
27
+ if (self.unistylesRuntime != nullptr) {
28
+ self.unistylesRuntime = nullptr;
29
+ }
30
+
31
+ [[NSNotificationCenter defaultCenter] removeObserver:self
32
+ name: UIContentSizeCategoryDidChangeNotification
33
+ object: nil];
34
+ [[NSNotificationCenter defaultCenter] removeObserver:self
35
+ name: RCTUserInterfaceStyleDidChangeNotification
36
+ object: nil];
37
+ }
38
+
39
+ - (void)setupListeners {
40
+ [[NSNotificationCenter defaultCenter] addObserver:self
41
+ selector:@selector(onAppearanceChange:)
42
+ name:RCTUserInterfaceStyleDidChangeNotification
43
+ object:nil];
44
+ [[NSNotificationCenter defaultCenter] addObserver:self
45
+ selector:@selector(onContentSizeCategoryChange:)
46
+ name:UIContentSizeCategoryDidChangeNotification
47
+ object:nil];
48
+ }
49
+
50
+ - (void)onAppearanceChange:(NSNotification *)notification {
51
+ std::string colorScheme = [self getColorScheme];
52
+
53
+ if (self.unistylesRuntime != nullptr) {
54
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
55
+ }
56
+ }
57
+
58
+ - (void)onContentSizeCategoryChange:(NSNotification *)notification {
59
+ UIContentSizeCategory contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
60
+
61
+ if (self.unistylesRuntime != nullptr) {
62
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleContentSizeCategoryChange([self getContentSizeCategory:contentSizeCategory]);
63
+ }
64
+ }
65
+
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;
77
+ }
78
+ }
79
+
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
+ }
120
+
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]);
142
+ }
143
+
144
+ @end
145
+
146
+
147
+ #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.6.0-rc.0",
3
+ "version": "2.6.0-rc.1",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -43,6 +43,7 @@
43
43
  "react-native-macos",
44
44
  "react-native-windows",
45
45
  "react-native-web",
46
+ "react-native-tvos",
46
47
  "expo"
47
48
  ],
48
49
  "repository": "https://github.com/jpudysz/react-native-unistyles",
@@ -117,6 +118,7 @@
117
118
  "examples/macos",
118
119
  "examples/win",
119
120
  "examples/bare",
121
+ "examples/tv",
120
122
  "docs"
121
123
  ],
122
124
  "packageManager": "yarn@3.6.4",
@@ -130,6 +132,7 @@
130
132
  "<rootDir>/examples/macos/node_modules",
131
133
  "<rootDir>/examples/win/node_modules",
132
134
  "<rootDir>/examples/bare/node_modules",
135
+ "<rootDir>/examples/tv/node_modules",
133
136
  "<rootDir>/docs/node_modules",
134
137
  "<rootDir>/lib/"
135
138
  ],
@@ -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" }
13
+ s.platforms = { :ios => min_ios_version_supported, :osx => "10.14", :tvos => "9.0" }
14
14
  s.source = { :git => package["repository"], :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = [