react-native-unistyles 2.8.0-rc.3 → 2.8.0-rc.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@
7
7
  #include <optional>
8
8
  #include <variant>
9
9
  #include <math.h>
10
+ #include <algorithm>
10
11
 
11
12
  using namespace facebook;
12
13
 
@@ -1,3 +1,4 @@
1
+ #import <UIKit/UIKit.h>
1
2
  #import "UnistylesRuntime.h"
2
3
  #include <string>
3
4
 
@@ -112,17 +112,21 @@ float getFontScale() {
112
112
  }
113
113
 
114
114
  std::string getColorScheme() {
115
- UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
116
-
117
- switch (colorScheme) {
118
- case UIUserInterfaceStyleLight:
119
- return UnistylesLightScheme;
120
- case UIUserInterfaceStyleDark:
121
- return UnistylesDarkScheme;
122
- case UIUserInterfaceStyleUnspecified:
123
- default:
124
- return UnistylesUnspecifiedScheme;
125
- }
115
+ #if !TARGET_OS_VISION
116
+ UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
117
+
118
+ switch (colorScheme) {
119
+ case UIUserInterfaceStyleLight:
120
+ return UnistylesLightScheme;
121
+ case UIUserInterfaceStyleDark:
122
+ return UnistylesDarkScheme;
123
+ case UIUserInterfaceStyleUnspecified:
124
+ default:
125
+ return UnistylesUnspecifiedScheme;
126
+ }
127
+ #endif
128
+
129
+ return UnistylesUnspecifiedScheme;
126
130
  }
127
131
 
128
132
  UIColor* colorFromHexString(NSString* hexString, float alpha) {
@@ -73,13 +73,17 @@
73
73
  });
74
74
 
75
75
  dispatch_async(dispatch_get_main_queue(), ^{
76
- unistylesRuntime->screen = [self getScreenDimensions];
76
+ Screen screen = [self getScreenDimensions];
77
+
78
+ unistylesRuntime->screen = Dimensions({screen.width, screen.height});
77
79
  unistylesRuntime->contentSizeCategory = getContentSizeCategory();
80
+ unistylesRuntime->pixelRatio = screen.pixelRatio;
81
+ unistylesRuntime->fontScale = screen.fontScale;
78
82
  });
79
83
  }
80
84
 
81
85
  - (void)onWindowChange:(NSNotification *)notification {
82
- Dimensions screen = [self getScreenDimensions];
86
+ Screen screen = [self getScreenDimensions];
83
87
 
84
88
  if (self.unistylesRuntime != nullptr) {
85
89
  ((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange(
@@ -97,11 +101,14 @@
97
101
  }
98
102
  }
99
103
 
100
- - (Dimensions)getScreenDimensions {
104
+ - (Screen)getScreenDimensions {
101
105
  UIWindow* mainWindow = [self getMainWindow];
102
- Dimensions screenDimension = {(int)mainWindow.frame.size.width, (int)mainWindow.frame.size.height};
106
+ int width = (int)mainWindow.frame.size.width;
107
+ int height = (int)mainWindow.frame.size.height;
108
+ float pixelRatio = 1.0;
109
+ float fontScale = getFontScale();
103
110
 
104
- return screenDimension;
111
+ return Screen({width, height, pixelRatio, fontScale});
105
112
  }
106
113
 
107
114
  @end
@@ -1 +1 @@
1
- {"version":3,"file":"UnistylesModule.native.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesModule.native.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG;IACzB,OAAO,IAAI,OAAO,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,eAAe,EAA+B,qBAAqB,CAAA"}
1
+ {"version":3,"file":"UnistylesModule.native.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesModule.native.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG;IACzB,OAAO,IAAI,OAAO,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,eAAe,uBAAoD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"UnistylesModule.windows.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesModule.windows.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG;IACzB,OAAO,IAAI,OAAO,CAAA;CACrB,CAAA;AAID,eAAO,MAAM,eAAe,EAAkF,qBAAqB,CAAA"}
1
+ {"version":3,"file":"UnistylesModule.windows.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesModule.windows.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG;IACzB,OAAO,IAAI,OAAO,CAAA;CACrB,CAAA;AAID,eAAO,MAAM,eAAe,uBAAuG,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"UnistylesRuntime.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesRuntime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG1D;;GAEG;AACH,qBAAa,gBAAgB;IACb,OAAO,CAAC,eAAe;IAAmB,OAAO,CAAC,iBAAiB;gBAA3D,eAAe,EAAE,eAAe,EAAU,iBAAiB,EAAE,gBAAgB;IAEjG;;;OAGG;IACH,IAAW,WAAW;;;;;;;;;;;;;;;;;;;MAkBrB;IAED;;;OAGG;IACH,IAAW,WAAW,uCAErB;IAED;;;OAGG;IACH,IAAW,iBAAiB,YAE3B;IAED;;;OAGG;IACH,IAAW,SAAS,UAEnB;IAED;;;OAGG;IACH,IAAW,mBAAmB,gGAE7B;IAED;;;OAGG;IACH,IAAW,UAAU,mDAEpB;IAED;;;OAGG;IACH,IAAW,WAAW,6CAErB;IAED;;;OAGG;IACH,IAAW,cAAc,aAExB;IAED;;;OAGG;IACH,IAAW,MAAM;;;MAKhB;IAED;;;OAGG;IACH,IAAW,MAAM,oCAEhB;IAED;;;OAGG;IACH,IAAW,SAAS;;;2BAIO,KAAK,UAAU,MAAM;4BAKpB,OAAO;MAElC;IAED;;;OAGG;IACH,IAAW,aAAa;;;2BAIG,KAAK,UAAU,MAAM;4BAKpB,OAAO;MAElC;IAED;;;OAGG;IACH,IAAW,WAAW,6BAQrB;IAED;;;OAGG;IACH,IAAW,UAAU,WAEpB;IAED;;;OAGG;IACH,IAAW,SAAS,eAInB;IAED;;;OAGG;IACI,gBAAgB,CAAC,SAAS,EAAE,OAAO;IAI1C;;;;OAIG;IACI,0BAA0B,WAAY,KAAK,UAAU,MAAM,UAIjE;IAED;;;;OAIG;IACI,QAAQ,SAAU,MAAM,eAAe,sBAY7C;IAED;;;;;OAKG;IACI,WAAW,SAAU,MAAM,eAAe,WAAW,CAAC,KAAK,EAAE,eAAe,CAAC,MAAM,eAAe,CAAC,KAAK,eAAe,CAAC,MAAM,eAAe,CAAC,UAEpJ;IAED;;;OAGG;IACI,iBAAiB,WAAY,OAAO,UAE1C;IAED;;;OAGG;IACI,SAAS,WAAY,eAAe,UAE1C;IAED;;;OAGG;IACI,YAAY,WAAY,eAAe,UAE7C;CACJ"}
1
+ {"version":3,"file":"UnistylesRuntime.d.ts","sourceRoot":"","sources":["../../../../src/core/UnistylesRuntime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG1D;;GAEG;AACH,qBAAa,gBAAgB;IACb,OAAO,CAAC,eAAe;IAAmB,OAAO,CAAC,iBAAiB;gBAA3D,eAAe,EAAE,eAAe,EAAU,iBAAiB,EAAE,gBAAgB;IAEjG;;;OAGG;IACH,IAAW,WAAW;;;;;;;;;;;;;;;;;;;MAkBrB;IAED;;;OAGG;IACH,IAAW,WAAW,uCAErB;IAED;;;OAGG;IACH,IAAW,iBAAiB,YAE3B;IAED;;;OAGG;IACH,IAAW,SAAS,UAEnB;IAED;;;OAGG;IACH,IAAW,mBAAmB,gGAE7B;IAED;;;OAGG;IACH,IAAW,UAAU,mDAEpB;IAED;;;OAGG;IACH,IAAW,WAAW,6CAErB;IAED;;;OAGG;IACH,IAAW,cAAc,aAExB;IAED;;;OAGG;IACH,IAAW,MAAM;;;MAKhB;IAED;;;OAGG;IACH,IAAW,MAAM,oCAEhB;IAED;;;OAGG;IACH,IAAW,SAAS;;;2BAIO,KAAK,UAAU,MAAM;4BAKpB,OAAO;MAElC;IAED;;;OAGG;IACH,IAAW,aAAa;;;2BAIG,KAAK,UAAU,MAAM;4BAKpB,OAAO;MAElC;IAED;;;OAGG;IACH,IAAW,WAAW,6BAQrB;IAED;;;OAGG;IACH,IAAW,UAAU,WAEpB;IAED;;;OAGG;IACH,IAAW,SAAS,eAInB;IAED;;;OAGG;IACI,gBAAgB,CAAC,SAAS,EAAE,OAAO;IAI1C;;;;OAIG;IACI,0BAA0B,WAAY,KAAK,UAAU,MAAM,UAIjE;IAED;;;;OAIG;IACI,QAAQ,SAAU,MAAM,eAAe,sBAY7C;IAED;;;;;OAKG;IACI,WAAW,SAAU,MAAM,eAAe,mBAAmB,eAAe,CAAC,MAAM,eAAe,CAAC,KAAK,eAAe,CAAC,MAAM,eAAe,CAAC,UAEpJ;IAED;;;OAGG;IACI,iBAAiB,WAAY,OAAO,UAE1C;IAED;;;OAGG;IACI,SAAS,WAAY,eAAe,UAE1C;IAED;;;OAGG;IACI,YAAY,WAAY,eAAe,UAE7C;CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"createStyleSheet.d.ts","sourceRoot":"","sources":["../../../src/createStyleSheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,yBAAyB,cAAc,CAAC,KAAG,CAAe,CAAA"}
1
+ {"version":3,"file":"createStyleSheet.d.ts","sourceRoot":"","sources":["../../../src/createStyleSheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,2DAAwE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCSS.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCSS.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAGrD,eAAO,MAAM,MAAM,GAAI,CAAC,cAAc,qBAAqB,CAAC,CAAC,CAAC,SA6C7D,CAAA"}
1
+ {"version":3,"file":"useCSS.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCSS.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAGrD,eAAO,MAAM,MAAM,mDA6ClB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCSS.native.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCSS.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,MAAM,GAAI,CAAC,eAAe,qBAAqB,CAAC,CAAC,CAAC,KAAG,IAAU,CAAA"}
1
+ {"version":3,"file":"useCSS.native.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useCSS.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,MAAM,gDAA+C,IAAU,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVariants.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useVariants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,eAAO,MAAM,WAAW,iBAAkB,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,+CAMzE,CAAA"}
1
+ {"version":3,"file":"useVariants.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useVariants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,eAAO,MAAM,WAAW,iBAAkB,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,+CAMzE,CAAA"}
@@ -23,7 +23,10 @@ declare const UnistylesRegistry: {
23
23
  };
24
24
  };
25
25
  addConfig: (config: import("./types").UnistylesConfig) => {
26
- addBreakpoints: any;
26
+ addBreakpoints: (breakpoints: UnistylesBreakpoints) => {
27
+ addThemes: any;
28
+ addConfig: any;
29
+ };
27
30
  addThemes: any;
28
31
  };
29
32
  };
@@ -41,7 +44,10 @@ declare const UnistylesRegistry: {
41
44
  };
42
45
  addConfig: (config: import("./types").UnistylesConfig) => {
43
46
  addBreakpoints: any;
44
- addThemes: any;
47
+ addThemes: (themes: UnistylesThemes) => {
48
+ addBreakpoints: any;
49
+ addConfig: any;
50
+ };
45
51
  };
46
52
  };
47
53
  /**
@@ -57,7 +63,10 @@ declare const UnistylesRegistry: {
57
63
  addConfig: any;
58
64
  };
59
65
  addThemes: (themes: UnistylesThemes) => {
60
- addBreakpoints: any;
66
+ addBreakpoints: (breakpoints: UnistylesBreakpoints) => {
67
+ addThemes: any;
68
+ addConfig: any;
69
+ };
61
70
  addConfig: any;
62
71
  };
63
72
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD;;;GAGG;AACH,QAAA,MAAM,iBAAiB;IACnB;;;OAGG;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;CAEN,CAAA;AAED,QAAA,MAAM,gBAAgB,mCAAoB,CAAA;AAE1C,OAAO,EACH,EAAE,EACF,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EACnB,CAAA;AAED,YAAY,EACR,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,mBAAmB,IAAI,iBAAiB,EAC3C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD;;;GAGG;AACH,QAAA,MAAM,iBAAiB;IACnB;;;OAGG;;;;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;;;;CAEN,CAAA;AAED,QAAA,MAAM,gBAAgB,mCAAoB,CAAA;AAE1C,OAAO,EACH,EAAE,EACF,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EACnB,CAAA;AAED,YAAY,EACR,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,mBAAmB,IAAI,iBAAiB,EAC3C,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeStyle.d.ts","sourceRoot":"","sources":["../../../../src/normalizer/normalizeStyle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoE,OAAO,EAAE,MAAM,UAAU,CAAA;AAuDzG,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,OAAO,SAAS,CAAC,KAAG,CAwB5D,CAAA"}
1
+ {"version":3,"file":"normalizeStyle.d.ts","sourceRoot":"","sources":["../../../../src/normalizer/normalizeStyle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoE,OAAO,EAAE,MAAM,UAAU,CAAA;AAuDzG,eAAO,MAAM,cAAc,oCAwB1B,CAAA"}
@@ -11,6 +11,6 @@ type ParsedStylesheet<ST extends StyleSheetWithSuperPowers> = {
11
11
  * @param variantsMap - The map of variants to be used
12
12
  * @returns - The theme, current breakpoint and RN compatible styles
13
13
  */
14
- export declare const useStyles: <ST extends StyleSheetWithSuperPowers>(stylesheet?: ST, variantsMap?: ExtractVariantNames<typeof stylesheet>) => ParsedStylesheet<ST>;
14
+ export declare const useStyles: <ST extends StyleSheetWithSuperPowers>(stylesheet?: ST | undefined, variantsMap?: ExtractVariantNames<ST> | undefined) => ParsedStylesheet<ST>;
15
15
  export {};
16
16
  //# sourceMappingURL=useStyles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAIpH,KAAK,gBAAgB,CAAC,EAAE,SAAS,yBAAyB,IAAI;IAC1D,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,EAAE,SAAS,yBAAyB,eAC7C,EAAE,gBACD,mBAAmB,CAAC,OAAO,UAAU,CAAC,KACrD,gBAAgB,CAAC,EAAE,CAmCrB,CAAA"}
1
+ {"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAIpH,KAAK,gBAAgB,CAAC,EAAE,SAAS,yBAAyB,IAAI;IAC1D,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,gJAsCrB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAKjD,eAAO,MAAM,qBAAqB,UAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,QAAQ,CAAC,OAAO,CAqCtF,CAAA"}
1
+ {"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAKjD,eAAO,MAAM,qBAAqB,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,SAAS,OAAO,CAqCtF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"mqParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/mqParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAM7D,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,OAAO,OAAQ,MAAM,KAAG,iBAcpC,CAAA;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,YAAgC,CAAA;AAExE,eAAO,MAAM,SAAS,aAAc,iBAAiB,YAgBpD,CAAA;AAED,eAAO,MAAM,yBAAyB,aAAc,iBAAiB,cAAc,UAAU,KAAG,OAgB/F,CAAA;AAcD,eAAO,MAAM,4BAA4B,iBAAkB,KAAK,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,cAAc,UAAU,KAAG,QAAQ,CAAC,MAAM,CAgB5H,CAAA"}
1
+ {"version":3,"file":"mqParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/mqParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAM7D,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,OAAO,OAAQ,MAAM,KAAG,iBAcpC,CAAA;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,YAAgC,CAAA;AAExE,eAAO,MAAM,SAAS,aAAc,iBAAiB,YAgBpD,CAAA;AAED,eAAO,MAAM,yBAAyB,aAAc,iBAAiB,cAAc,UAAU,KAAG,OAgB/F,CAAA;AAcD,eAAO,MAAM,4BAA4B,iBAAkB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,cAAc,UAAU,KAAG,SAAS,MAAM,CAgB5H,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAW,MAAM,UAAU,CAAA;AAK1D,eAAO,MAAM,eAAe,QACnB,MAAM,MACP,QAAQ,YACF,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,KAC3C,QAED,CAAA;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,EAAE,SAAS,CAAC,KAAG,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,OAAO,SACjC,CAAC,YACC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,kCAE1C,CAuDY,CAAA"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAW,MAAM,UAAU,CAAA;AAK1D,eAAO,MAAM,eAAe,QACnB,MAAM,MACP,QAAQ,YACF,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,KAC3C,QAED,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,0CAEV,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,mCAyD9B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.8.0-rc.3",
3
+ "version": "2.8.0-rc.5",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -91,7 +91,7 @@
91
91
  "react-native-web": "0.19.12",
92
92
  "react-test-renderer": "18.3.1",
93
93
  "release-it": "17.4.0",
94
- "typescript": "5.5.2"
94
+ "typescript": "5.3.3"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "@react-native/normalize-colors": "*",
@@ -2,10 +2,10 @@
2
2
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
 
4
4
  <!--
5
- Application projects contain a file with this name to specify some important settings
6
- that will apply globally for the app and *all* native modules the app consumes. These
7
- values are set by the app developer. However you can also set them here to test building
8
- the library solution without an app.
5
+ This file contains some important settings that will apply globally for
6
+ your app and *all* native modules your app consumes. These values were
7
+ set when you created the app project, and in some cases cannot be
8
+ simply changed here without recreating a new project.
9
9
  -->
10
10
 
11
11
  <PropertyGroup Label="Microsoft.ReactNative Experimental Features">
@@ -5,7 +5,6 @@
5
5
  </config>
6
6
  <packageSources>
7
7
  <clear />
8
- <add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />
9
8
  <add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
10
9
  </packageSources>
11
10
  <disabledPackageSources>
@@ -8,21 +8,18 @@
8
8
  #include <winrt/Microsoft.ReactNative.h>
9
9
  #include <winrt/Windows.UI.Xaml.h>
10
10
  #include <winrt/Windows.UI.Core.h>
11
+ #include <winrt/Windows.Graphics.Display.h>
11
12
  #include <winrt/Windows.UI.ViewManagement.h>
12
13
  #include "UnistylesRuntime.h"
14
+ #include <TurboModuleProvider.h>
13
15
 
14
16
  using namespace winrt::Windows::UI::ViewManagement;
17
+ using namespace winrt::Windows::Graphics::Display;
15
18
  using namespace winrt::Microsoft::ReactNative;
16
19
  using namespace winrt::Windows::UI::Xaml;
17
20
  using namespace winrt::Windows::UI::Core;
18
21
  using namespace facebook;
19
22
 
20
- struct UIInitialInfo {
21
- Dimensions screen;
22
- std::string colorScheme;
23
- std::string contentSizeCategory;
24
- };
25
-
26
23
  namespace winrt::ReactNativeUnistyles
27
24
  {
28
25
 
@@ -30,157 +27,86 @@ REACT_MODULE(Unistyles, L"Unistyles")
30
27
  struct Unistyles {
31
28
 
32
29
  REACT_INIT(Initialize)
33
- void Initialize(ReactContext const &reactContext) noexcept {
30
+ void Initialize(ReactContext const& reactContext) noexcept {
34
31
  m_reactContext = reactContext;
35
32
 
36
33
  m_reactContext.UIDispatcher().Post([this]() mutable {
37
34
  this->windowSizeChange = Window::Current().CoreWindow().SizeChanged(TypedEventHandler<CoreWindow, WindowSizeChangedEventArgs>([=](CoreWindow const sender, WindowSizeChangedEventArgs const&) {
38
- auto bounds = Window::Current().Bounds();
39
-
40
35
  if (this->unistylesRuntime != nullptr) {
41
- Dimensions screenDimensions = Dimensions{(int)bounds.Width, (int)bounds.Height};
42
-
43
- ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(screenDimensions, this->getInsets(), this->getStatusBarDimensions(), this->getNavigationBarDimensions());
36
+ ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(getScreenDimensions(), std::nullopt, std::nullopt, std::nullopt);
44
37
  }
45
38
  }));
46
39
 
47
- UISettings settings;
48
-
49
- this->colorValuesChange = settings.ColorValuesChanged(TypedEventHandler<UISettings, IInspectable>([this](UISettings const& sender, IInspectable const&){
40
+ this->colorValuesChange = UISettings().ColorValuesChanged(TypedEventHandler<UISettings, IInspectable>([this](UISettings const& sender, IInspectable const&) {
50
41
  if (this->unistylesRuntime != nullptr) {
51
42
  ((UnistylesRuntime*)this->unistylesRuntime)->handleAppearanceChange(this->getColorScheme());
52
43
  }
53
44
  }));
54
45
  });
55
46
  }
56
-
47
+
57
48
  REACT_SYNC_METHOD(install)
58
- bool install() noexcept {
49
+ bool install() noexcept {
59
50
  if (m_reactContext == nullptr) {
60
51
  return false;
61
52
  }
62
53
 
63
54
  jsi::Runtime* jsiRuntime = TryGetOrCreateContextRuntime(m_reactContext);
64
-
55
+
65
56
  if (jsiRuntime == nullptr) {
66
57
  return false;
67
58
  }
68
59
 
69
60
  auto& runtime = *jsiRuntime;
61
+ auto callInvoker = MakeAbiCallInvoker(m_reactContext.Handle().JSDispatcher());
70
62
 
71
- registerUnistylesHostObject(runtime);
63
+ registerUnistylesHostObject(runtime, callInvoker);
72
64
 
73
65
  return true;
74
66
  }
75
67
 
76
- void registerUnistylesHostObject(jsi::Runtime& runtime) {
77
- std::promise<UIInitialInfo> uiInfoPromise;
78
- auto uiInfoFuture = uiInfoPromise.get_future();
79
-
80
- m_reactContext.UIDispatcher().Post([this, promise = std::move(uiInfoPromise)]() mutable {
81
- UIInitialInfo uiMetadata;
82
- auto bounds = Window::Current().Bounds();
68
+ void registerUnistylesHostObject(jsi::Runtime& runtime, std::shared_ptr<facebook::react::CallInvoker> callInvoker) {
69
+ auto unistylesRuntime = std::make_shared<UnistylesRuntime>(runtime, callInvoker);
83
70
 
84
- uiMetadata.screen = Dimensions{(int)bounds.Width, (int)bounds.Height};
85
- uiMetadata.colorScheme = this->getColorScheme();
86
- uiMetadata.contentSizeCategory = UnistylesUnspecifiedScheme;
87
-
88
- promise.set_value(std::move(uiMetadata));
89
- });
90
-
91
- UIInitialInfo uiInfo = uiInfoFuture.get();
71
+ this->unistylesRuntime = unistylesRuntime.get();
92
72
 
93
- auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
94
- uiInfo.screen,
95
- uiInfo.colorScheme,
96
- uiInfo.contentSizeCategory,
97
- this->getInsets(),
98
- this->getStatusBarDimensions(),
99
- this->getNavigationBarDimensions()
100
- );
73
+ makeShared((UnistylesRuntime*)unistylesRuntime.get());
101
74
 
102
- unistylesRuntime->onThemeChange([this](std::string theme) {
103
- winrt::hstring themeName = winrt::to_hstring(theme);
75
+ auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
104
76
 
105
- auto payload = winrt::Microsoft::ReactNative::JSValueObject{
106
- {"type", "theme"},
107
- {"payload", winrt::Microsoft::ReactNative::JSValueObject{{"themeName", winrt::to_string(themeName)}}}
108
- };
77
+ runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
78
+ }
109
79
 
110
- this->OnThemeChange(payload);
80
+ void makeShared(UnistylesRuntime* unistylesRuntime) {
81
+ unistylesRuntime->setScreenDimensionsCallback([this]() {
82
+ return getScreenDimensions();
111
83
  });
112
84
 
113
- unistylesRuntime.get()->onLayoutChange([this](std::string breakpoint, std::string orientation, Dimensions& screen, Dimensions& statusBar, Insets& insets, Dimensions& navigationBar) {
114
- auto payload = winrt::Microsoft::ReactNative::JSValueObject{
115
- {"type", "layout"},
116
- {"payload", winrt::Microsoft::ReactNative::JSValueObject{
117
- {"breakpoint", breakpoint},
118
- {"orientation", orientation},
119
- {"screen", winrt::Microsoft::ReactNative::JSValueObject{
120
- {"width", screen.width},
121
- {"height", screen.height}
122
- }},
123
- {"statusBar", winrt::Microsoft::ReactNative::JSValueObject{
124
- {"width", statusBar.width},
125
- {"height", statusBar.height}
126
- }},
127
- {"navigationBar", winrt::Microsoft::ReactNative::JSValueObject{
128
- {"width", navigationBar.width},
129
- {"height", navigationBar.height}
130
- }},
131
- {"insets", winrt::Microsoft::ReactNative::JSValueObject{
132
- {"top", insets.top},
133
- {"bottom", insets.bottom},
134
- {"left", insets.left},
135
- {"right", insets.right}
136
- }},
137
- }}
138
- };
139
-
140
- this->OnLayoutChange(payload);
85
+ unistylesRuntime->setColorSchemeCallback([this]() {
86
+ return getColorScheme();
141
87
  });
142
88
 
143
- unistylesRuntime.get()->onPluginChange([this]() {
144
- auto payload = winrt::Microsoft::ReactNative::JSValueObject{
145
- {"type", "plugin"}
146
- };
89
+ m_reactContext.UIDispatcher().Post([this, unistylesRuntime]() {
90
+ auto screen = getScreenDimensions();
147
91
 
148
- this->OnPluginChange(payload);
92
+ unistylesRuntime->screen = Dimensions({ screen.width, screen.height });
93
+ unistylesRuntime->pixelRatio = screen.pixelRatio;
94
+ unistylesRuntime->fontScale = screen.fontScale;
95
+ unistylesRuntime->colorScheme = getColorScheme();
149
96
  });
150
-
151
- unistylesRuntime.get()->onContentSizeCategoryChange([this](std::string contentSizeCategory) {
152
- // not available on windows
153
- });
154
-
155
- this->unistylesRuntime = unistylesRuntime.get();
156
-
157
- auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
158
-
159
- runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
160
97
  }
161
98
 
162
- REACT_EVENT(OnThemeChange, L"__unistylesOnChange")
163
- std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnThemeChange;
164
-
165
- REACT_EVENT(OnLayoutChange, L"__unistylesOnChange")
166
- std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnLayoutChange;
167
-
168
- REACT_EVENT(OnPluginChange, L"__unistylesOnChange")
169
- std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnPluginChange;
170
-
171
99
  ~Unistyles() {
172
100
  if (this->unistylesRuntime != nullptr) {
173
101
  this->unistylesRuntime = nullptr;
174
102
  }
175
103
 
176
104
  if (this->windowSizeChange) {
177
- Window::Current().CoreWindow().SizeChanged(this->windowSizeChange);
105
+ this->windowSizeChange = { NULL };
178
106
  }
179
107
 
180
108
  if (this->colorValuesChange) {
181
- UISettings settings;
182
-
183
- settings.ColorValuesChanged(this->colorValuesChange);
109
+ this->colorValuesChange = { NULL };
184
110
  }
185
111
  }
186
112
 
@@ -191,16 +117,17 @@ struct Unistyles {
191
117
  winrt::event_token colorValuesChange{ NULL };
192
118
 
193
119
  std::string getColorScheme() {
194
- auto uiSettings = UISettings();
195
- auto background = uiSettings.GetColorValue(UIColorType::Background);
120
+ UISettings uiSettings;
121
+
122
+ auto backgroundColor = uiSettings.GetColorValue(UIColorType::Background);
196
123
 
197
- bool isDark = background == winrt::Windows::UI::Colors::Black();
124
+ bool isDark = backgroundColor == Colors::Black();
198
125
 
199
126
  if (isDark) {
200
127
  return UnistylesDarkScheme;
201
128
  }
202
129
 
203
- bool isLight = background == winrt::Windows::UI::Colors::White();
130
+ bool isLight = backgroundColor == Colors::White();
204
131
 
205
132
  if (isLight) {
206
133
  return UnistylesLightScheme;
@@ -209,16 +136,13 @@ struct Unistyles {
209
136
  return UnistylesUnspecifiedScheme;
210
137
  }
211
138
 
212
- Insets getInsets() {
213
- return Insets{ 0, 0, 0, 0 };
214
- }
215
-
216
- Dimensions getStatusBarDimensions() {
217
- return {0, 0};
218
- }
139
+ Screen getScreenDimensions() {
140
+ auto bounds = Window::Current().Bounds();
141
+ auto displayInfo = DisplayInformation::GetForCurrentView();
142
+ auto pixelRatio = displayInfo.LogicalDpi() / 96.0f;
143
+ float fontScale = UISettings().TextScaleFactor();
219
144
 
220
- Dimensions getNavigationBarDimensions() {
221
- return { 0, 0 };
145
+ return Screen({ (int)bounds.Width, (int)bounds.Height, pixelRatio, fontScale });
222
146
  }
223
147
  };
224
148
 
@@ -79,7 +79,7 @@
79
79
  <PropertyGroup Label="UserMacros" />
80
80
  <ItemDefinitionGroup>
81
81
  <ClCompile>
82
- <PrecompiledHeader>Use</PrecompiledHeader>
82
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
83
83
  <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
84
84
  <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
85
85
  <WarningLevel>Level4</WarningLevel>
@@ -112,6 +112,9 @@
112
112
  </ClCompile>
113
113
  </ItemDefinitionGroup>
114
114
  <ItemGroup>
115
+ <ClInclude Include="..\..\cxx\Macros.h" />
116
+ <ClInclude Include="..\..\cxx\UnistylesModel.h" />
117
+ <ClInclude Include="..\..\cxx\UnistylesRuntime.h" />
115
118
  <ClInclude Include="ReactPackageProvider.h">
116
119
  <DependentUpon>ReactPackageProvider.idl</DependentUpon>
117
120
  </ClInclude>
@@ -119,6 +122,8 @@
119
122
  <ClInclude Include="pch.h" />
120
123
  </ItemGroup>
121
124
  <ItemGroup>
125
+ <ClCompile Include="..\..\cxx\UnistylesImpl.cpp" />
126
+ <ClCompile Include="..\..\cxx\UnistylesModel.cpp" />
122
127
  <ClCompile Include="..\..\cxx\UnistylesRuntime.cpp">
123
128
  <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
124
129
  <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
@@ -154,4 +159,4 @@
154
159
  <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props'))" />
155
160
  <Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets'))" />
156
161
  </Target>
157
- </Project>
162
+ </Project>
@@ -8,13 +8,18 @@
8
8
  <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
9
9
  <ClCompile Include="ReactPackageProvider.cpp" />
10
10
  <ClCompile Include="..\..\cxx\UnistylesRuntime.cpp" />
11
+ <ClCompile Include="..\..\cxx\UnistylesImpl.cpp" />
12
+ <ClCompile Include="..\..\cxx\UnistylesModel.cpp" />
11
13
  </ItemGroup>
12
14
  <ItemGroup>
13
15
  <ClInclude Include="pch.h" />
14
16
  <ClInclude Include="ReactPackageProvider.h" />
15
17
  <ClInclude Include="ReactNativeUnistyles.h" />
18
+ <ClInclude Include="..\..\cxx\Macros.h" />
19
+ <ClInclude Include="..\..\cxx\UnistylesModel.h" />
20
+ <ClInclude Include="..\..\cxx\UnistylesRuntime.h" />
16
21
  </ItemGroup>
17
22
  <ItemGroup>
18
23
  <None Include="PropertySheet.props" />
19
24
  </ItemGroup>
20
- </Project>
25
+ </Project>