react-native-unistyles 1.2.0 → 2.0.0-alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.cpp +255 -0
- package/cxx/UnistylesRuntime.h +60 -0
- package/ios/UnistylesHelpers.h +4 -0
- package/ios/UnistylesHelpers.mm +20 -0
- package/ios/UnistylesModule.h +10 -0
- package/ios/UnistylesModule.mm +158 -0
- package/lib/commonjs/common.js +26 -0
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/core/UnistyleRegistry.js +38 -0
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/core/Unistyles.js +31 -0
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js +9 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/core/UnistylesRuntime.js +66 -0
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/createStyleSheet.js +14 -0
- package/lib/commonjs/createStyleSheet.js.map +1 -0
- package/lib/commonjs/global.js +2 -0
- package/lib/commonjs/global.js.map +1 -0
- package/lib/commonjs/hooks/index.js +10 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useInitialTheme.js +17 -0
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +54 -0
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
- package/lib/commonjs/index.js +35 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/common.js +2 -0
- package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/mq.js +6 -0
- package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
- package/lib/commonjs/types/unistyles.js +6 -0
- package/lib/commonjs/types/unistyles.js.map +1 -0
- package/lib/commonjs/useStyles.js +49 -0
- package/lib/commonjs/useStyles.js.map +1 -0
- package/lib/commonjs/utils/breakpoints.js +44 -82
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +6 -1
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +25 -30
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +89 -0
- package/lib/commonjs/utils/mq.js.map +1 -0
- package/lib/commonjs/utils/mqParser.js +86 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/styles.js +6 -53
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +20 -0
- package/lib/commonjs/utils/variants.js.map +1 -0
- package/lib/module/common.js +22 -0
- package/lib/module/common.js.map +1 -0
- package/lib/module/core/UnistyleRegistry.js +31 -0
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/core/Unistyles.js +25 -0
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js +3 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/core/UnistylesRuntime.js +59 -0
- package/lib/module/core/UnistylesRuntime.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/createStyleSheet.js +7 -0
- package/lib/module/createStyleSheet.js.map +1 -0
- package/lib/module/global.js +2 -0
- package/lib/module/global.js.map +1 -0
- package/lib/module/hooks/index.js +2 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useInitialTheme.js +10 -0
- package/lib/module/hooks/useInitialTheme.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +47 -0
- package/lib/module/hooks/useUnistyles.js.map +1 -0
- package/lib/module/index.js +13 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/mq.js +2 -0
- package/lib/module/types/mq.js.map +1 -0
- package/lib/module/types/unistyles.js +2 -0
- package/lib/module/types/unistyles.js.map +1 -0
- package/lib/module/useStyles.js +42 -0
- package/lib/module/useStyles.js.map +1 -0
- package/lib/module/utils/breakpoints.js +43 -82
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +5 -0
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +5 -3
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +83 -0
- package/lib/module/utils/mq.js.map +1 -0
- package/lib/module/utils/mqParser.js +79 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/styles.js +7 -55
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +13 -0
- package/lib/module/utils/variants.js.map +1 -0
- package/lib/typescript/src/common.d.ts +17 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +15 -0
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/core/Unistyles.d.ts +13 -0
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts +6 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +24 -0
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/createStyleSheet.d.ts +3 -0
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
- package/lib/typescript/src/global.d.ts +7 -0
- package/lib/typescript/src/global.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +2 -1
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +14 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +12 -13
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +3 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +34 -18
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +5 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mq.d.ts +3 -0
- package/lib/typescript/src/types/mq.d.ts.map +1 -0
- package/lib/typescript/src/types/unistyles.d.ts +37 -0
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +10 -0
- package/lib/typescript/src/useStyles.d.ts.map +1 -0
- package/lib/typescript/src/utils/breakpoints.d.ts +5 -62
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +5 -0
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +5 -3
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +21 -0
- package/lib/typescript/src/utils/mq.d.ts.map +1 -0
- package/lib/typescript/src/utils/mqParser.d.ts +3 -0
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts +4 -49
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +3 -0
- package/lib/typescript/src/utils/variants.d.ts.map +1 -0
- package/package.json +30 -19
- package/react-native-unistyles.podspec +22 -0
- package/src/common.ts +19 -0
- package/src/core/UnistyleRegistry.ts +41 -0
- package/src/core/Unistyles.ts +34 -0
- package/src/core/UnistylesModule.ts +7 -0
- package/src/core/UnistylesRuntime.ts +73 -0
- package/src/core/index.ts +1 -0
- package/src/createStyleSheet.ts +9 -0
- package/src/global.ts +5 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useInitialTheme.ts +11 -0
- package/src/hooks/useUnistyles.ts +55 -0
- package/src/index.ts +30 -2
- package/src/types/breakpoints.ts +16 -19
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +42 -24
- package/src/types/index.ts +5 -9
- package/src/types/mq.ts +3 -0
- package/src/types/unistyles.ts +45 -0
- package/src/useStyles.ts +56 -0
- package/src/utils/breakpoints.ts +57 -88
- package/src/utils/common.ts +6 -0
- package/src/utils/index.ts +5 -10
- package/src/utils/mq.ts +106 -0
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/styles.ts +17 -64
- package/src/utils/variants.ts +17 -0
- package/lib/commonjs/UnistylesTheme.js +0 -21
- package/lib/commonjs/UnistylesTheme.js.map +0 -1
- package/lib/commonjs/createUnistyles.js +0 -57
- package/lib/commonjs/createUnistyles.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.js +0 -10
- package/lib/commonjs/hooks/useDimensions.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.web.js +0 -34
- package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/utils/mediaQueries.js +0 -189
- package/lib/commonjs/utils/mediaQueries.js.map +0 -1
- package/lib/module/UnistylesTheme.js +0 -12
- package/lib/module/UnistylesTheme.js.map +0 -1
- package/lib/module/createUnistyles.js +0 -50
- package/lib/module/createUnistyles.js.map +0 -1
- package/lib/module/hooks/useDimensions.js +0 -3
- package/lib/module/hooks/useDimensions.js.map +0 -1
- package/lib/module/hooks/useDimensions.web.js +0 -27
- package/lib/module/hooks/useDimensions.web.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/utils/mediaQueries.js +0 -176
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/typescript/examples/expo/src/App.d.ts +0 -3
- package/lib/typescript/examples/expo/src/App.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
- package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
- package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/examples/index.d.ts +0 -9
- package/lib/typescript/examples/expo/src/examples/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/index.d.ts +0 -2
- package/lib/typescript/examples/expo/src/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +0 -8
- package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/index.d.ts +0 -46
- package/lib/typescript/examples/expo/src/styles/index.d.ts.map +0 -1
- package/lib/typescript/examples/expo/src/styles/theme.d.ts +0 -24
- package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
- package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
- package/lib/typescript/src/createUnistyles.d.ts +0 -10
- package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
- package/src/UnistylesTheme.tsx +0 -17
- package/src/__tests__/createUnistyles.spec.tsx +0 -192
- package/src/createUnistyles.ts +0 -70
- package/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -34
- package/src/types/mediaQueries.ts +0 -10
- package/src/utils/mediaQueries.ts +0 -201
@@ -1,63 +1,6 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
* It returns a new object with the same keys but sorted based on their corresponding numeric values.
|
7
|
-
* Additionally, it validates that:
|
8
|
-
* 1. The first breakpoint starts with a value of 0.
|
9
|
-
* 2. No duplicate breakpoint values exist.
|
10
|
-
*
|
11
|
-
* If the validation fails, appropriate error messages are logged to the console.
|
12
|
-
*
|
13
|
-
* @template B - An object type where keys are strings and values are numbers.
|
14
|
-
* @param {B} breakpoints - The breakpoints object to be sorted and validated.
|
15
|
-
* @returns {B} A new object with sorted and validated breakpoints.
|
16
|
-
*
|
17
|
-
* @example
|
18
|
-
* const input = { md: 768, lg: 1024, sm: 0 }
|
19
|
-
* sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
|
20
|
-
*/
|
21
|
-
export declare const sortAndValidateBreakpoints: <B extends Breakpoints>(breakpoints: B) => B;
|
22
|
-
/**
|
23
|
-
* Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
|
24
|
-
*
|
25
|
-
* This function takes a screen width and an object of breakpoints. It returns the key of the breakpoint
|
26
|
-
* that the screen width falls into. The breakpoints are assumed to be sorted in ascending order.
|
27
|
-
*
|
28
|
-
* @template B - An object type where keys are strings and values are numbers representing screen widths.
|
29
|
-
* @param {number} width - The screen width to determine the breakpoint for.
|
30
|
-
* @param breakpointEntries - sorted pairs of breakpoints
|
31
|
-
* @returns {keyof B & string} The key of the breakpoint that the screen width falls into.
|
32
|
-
*
|
33
|
-
* @example
|
34
|
-
* const breakpoints = { sm: 0, md: 768, lg: 1024 }
|
35
|
-
* getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
|
36
|
-
*/
|
37
|
-
export declare const getBreakpointFromScreenWidth: <B extends Breakpoints>(width: number, breakpointEntries: SortedBreakpointEntries<B>) => keyof B & string;
|
38
|
-
/**
|
39
|
-
* Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
|
40
|
-
*
|
41
|
-
* The function first checks for custom media queries. If a matching custom media query is found, its associated value is returned.
|
42
|
-
* If no custom media query matches, the function then checks for a direct breakpoint match.
|
43
|
-
* If there's no direct breakpoint match, the function simulates CSS cascading to find the closest matching breakpoint.
|
44
|
-
*
|
45
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
46
|
-
*
|
47
|
-
* @param {Record<keyof B & string, string | number>} value - An object containing values associated with breakpoints or custom media queries.
|
48
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
49
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
50
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
51
|
-
*
|
52
|
-
* @returns {string | number | undefined} Returns the value associated with the matching breakpoint or custom media query, or `undefined` if no match is found.
|
53
|
-
*
|
54
|
-
* @example
|
55
|
-
*
|
56
|
-
* const values = { ':w[200]': 'value1', sm: 'value2', md: 'value3' }
|
57
|
-
* const screenSize = { width: 250, height: 400 }
|
58
|
-
* const breakpoints = { sm: 300, md: 600, lg: 900 }
|
59
|
-
*
|
60
|
-
* getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
|
61
|
-
*/
|
62
|
-
export declare const getValueForBreakpoint: <B extends Breakpoints>(value: Record<keyof B & string, string | number | undefined>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => string | number | undefined;
|
1
|
+
import type { NestedStyle, RNValue } from '../types';
|
2
|
+
import type { UnistylesBreakpoints } from '../global';
|
3
|
+
export declare const sortAndValidateBreakpoints: (breakpoints: UnistylesBreakpoints) => UnistylesBreakpoints;
|
4
|
+
export declare const getBreakpointFromScreenWidth: (width: number, breakpointEntries: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>) => keyof UnistylesBreakpoints & string;
|
5
|
+
export declare const getValueForNestedStyle: (value: NestedStyle, variant?: string) => RNValue;
|
63
6
|
//# sourceMappingURL=breakpoints.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAoB,OAAO,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAKrD,eAAO,MAAM,0BAA0B,gBAAiB,oBAAoB,KAAG,oBAuB9E,CAAA;AAED,eAAO,MAAM,4BAA4B,UAAW,MAAM,qBAAqB,MAAM,CAAC,MAAM,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,KAAG,MAAM,oBAAoB,GAAG,MAcnM,CAAA;AAGD,eAAO,MAAM,sBAAsB,UAAW,WAAW,YAAY,MAAM,KAAG,OA0D7E,CAAA"}
|
@@ -1,7 +1,12 @@
|
|
1
1
|
export declare const throwError: (message: string) => never;
|
2
2
|
export declare const warn: (message: string) => void;
|
3
|
+
export declare const isMobile: boolean;
|
3
4
|
export declare const isWeb: boolean;
|
4
5
|
export declare const isIOS: boolean;
|
5
6
|
export declare const isAndroid: boolean;
|
6
7
|
export declare const isServer: boolean;
|
8
|
+
export declare const Orientation: {
|
9
|
+
readonly Landscape: "landscape";
|
10
|
+
readonly Portrait: "portrait";
|
11
|
+
};
|
7
12
|
//# sourceMappingURL=common.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/utils/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,MAAM,UAEzC,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,MAAM,SAEnC,CAAA;AAED,eAAO,MAAM,KAAK,SAAwB,CAAA;AAC1C,eAAO,MAAM,KAAK,SAAwB,CAAA;AAC1C,eAAO,MAAM,SAAS,SAA4B,CAAA;AAClD,eAAO,MAAM,QAAQ,SAAgC,CAAA"}
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/utils/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,MAAM,UAEzC,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,MAAM,SAEnC,CAAA;AAED,eAAO,MAAM,QAAQ,SAAqD,CAAA;AAC1E,eAAO,MAAM,KAAK,SAAwB,CAAA;AAC1C,eAAO,MAAM,KAAK,SAAwB,CAAA;AAC1C,eAAO,MAAM,SAAS,SAA4B,CAAA;AAClD,eAAO,MAAM,QAAQ,SAAgC,CAAA;AAErD,eAAO,MAAM,WAAW;;;CAGd,CAAA"}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
export { normalizeStyles } from './normalizeStyles';
|
2
2
|
export * from './normalizer';
|
3
|
-
export {
|
3
|
+
export { mq, MQSymbol } from './mq';
|
4
|
+
export { getKeyForVariant } from './variants';
|
5
|
+
export { getKeyForUnistylesMediaQuery } from './mqParser';
|
6
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForNestedStyle } from './breakpoints';
|
4
7
|
export { proxifyFunction, parseStyle } from './styles';
|
5
|
-
export { isServer } from './common';
|
6
|
-
export { extractValues, getKeyForCustomMediaQuery, isMediaQuery, isWithinTheHeight, isWithinTheWidth, isWithinTheWidthAndHeight } from './mediaQueries';
|
8
|
+
export { isServer, Orientation } from './common';
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAChH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { MediaQuery, Nullable } from '../types';
|
2
|
+
import type { UnistylesBreakpoints } from '../global';
|
3
|
+
export declare const MQSymbol: unique symbol;
|
4
|
+
type MQValue = keyof UnistylesBreakpoints | number;
|
5
|
+
type MQHandler = {
|
6
|
+
w(wMin?: Nullable<MQValue>, wMax?: MQValue): WidthHandler;
|
7
|
+
width(wMin?: Nullable<MQValue>, wMax?: MQValue): WidthHandler;
|
8
|
+
h(hMin?: Nullable<MQValue>, hMax?: MQValue): HeightHandler;
|
9
|
+
height(hMin?: Nullable<MQValue>, hMax?: MQValue): HeightHandler;
|
10
|
+
};
|
11
|
+
type HeightHandler = {
|
12
|
+
w(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
|
13
|
+
width(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
|
14
|
+
} & MediaQuery;
|
15
|
+
type WidthHandler = {
|
16
|
+
h(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
|
17
|
+
height(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
|
18
|
+
} & MediaQuery;
|
19
|
+
export declare const mq: MQHandler;
|
20
|
+
export {};
|
21
|
+
//# sourceMappingURL=mq.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../../src/utils/mq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,eAAO,MAAM,QAAQ,eAAyB,CAAA;AAE9C,KAAK,OAAO,GAAG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAElD,KAAK,SAAS,GAAG;IACb,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC1D,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC9D,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;CAClE,CAAA;AAED,KAAK,aAAa,GAAG;IACjB,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IACxD,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;CAC9D,GAAG,UAAU,CAAA;AAEd,KAAK,YAAY,GAAG;IAChB,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IACxD,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;CAC/D,GAAG,UAAU,CAAA;AAsEd,eAAO,MAAM,EAAE,WAYb,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mqParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/mqParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAkFtE,eAAO,MAAM,4BAA4B,+CAAgD,UAAU,qBAgBlG,CAAA"}
|
@@ -1,51 +1,6 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
4
|
-
*
|
5
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
6
|
-
*
|
7
|
-
* @param {Function} fn - The function to be proxified.
|
8
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
9
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
10
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
11
|
-
*
|
12
|
-
* @returns {Function} Returns the proxified function
|
13
|
-
*
|
14
|
-
* @example
|
15
|
-
*
|
16
|
-
* const myFunction = () => ({ ':w[200]': 'value1', sm: 'value2' })
|
17
|
-
* const screenSize = { width: 250, height: 400 }
|
18
|
-
* const breakpoints = { sm: 300, md: 600 }
|
19
|
-
*
|
20
|
-
* const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
|
21
|
-
* proxifiedFunction() // parsed style based on screenSize and breakpoints
|
22
|
-
*/
|
23
|
-
export declare const proxifyFunction: <B extends Breakpoints>(fn: Function, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => Function;
|
1
|
+
import type { CustomNamedStyles, ScreenSize } from '../types';
|
2
|
+
import type { UnistylesBreakpoints } from '../global';
|
3
|
+
export declare const proxifyFunction: (fn: Function, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize, variant?: string) => Function;
|
24
4
|
export declare const isPlatformColor: <T extends {}>(value: T) => boolean;
|
25
|
-
|
26
|
-
* Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
|
27
|
-
*
|
28
|
-
* The function processes each key-value pair in the style object. If the value is a function or a valid style (not an object or a 'transform' key),
|
29
|
-
* it is returned as-is. Otherwise, the function attempts to resolve the value based on the provided breakpoint, screen size, and defined breakpoints.
|
30
|
-
*
|
31
|
-
* @template T - The type of the style object.
|
32
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
33
|
-
*
|
34
|
-
* @param {CustomNamedStyles<T, B>} style - The style object to be parsed.
|
35
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
36
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
37
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
38
|
-
*
|
39
|
-
* @returns {Record<string, string | number | Function>} Returns the parsed style object with resolved custom media queries or breakpoints.
|
40
|
-
*
|
41
|
-
* @example
|
42
|
-
*
|
43
|
-
* const style = { fontSize: { sm: '12px', md: '16px' } }
|
44
|
-
* const screenSize = { width: 300, height: 400 }
|
45
|
-
* const breakpoints = { xs: 0, sm: 300, md: 600 }
|
46
|
-
*
|
47
|
-
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
48
|
-
* // { fontSize: '12px' }
|
49
|
-
*/
|
50
|
-
export declare const parseStyle: <T, B extends Breakpoints>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => T;
|
5
|
+
export declare const parseStyle: <T>(style: CustomNamedStyles<T>, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize, variant?: string) => T;
|
51
6
|
//# sourceMappingURL=styles.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAe,MAAM,UAAU,CAAA;AAG1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,eAAO,MAAM,eAAe,OACpB,QAAQ,cAAc,MAAM,oBAAoB,GAAG,MAAM,cACjD,UAAU,YACZ,MAAM,KACjB,QAGD,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,+CAEP,MAAM,oBAAoB,GAAG,MAAM,cACnC,UAAU,YACZ,MAAM,MAgDnB,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/utils/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,gBAAgB,UAAW,WAAW,YAAY,MAAM,oGAcpE,CAAA"}
|
package/package.json
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-native-unistyles",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0-alpha.10",
|
4
4
|
"description": "Level up your React Native StyleSheet",
|
5
5
|
"scripts": {
|
6
6
|
"test": "jest",
|
7
7
|
"test:coverage": "jest --coverage",
|
8
8
|
"tsc": "node_modules/typescript/bin/tsc --noEmit",
|
9
9
|
"lint": "eslint . --ext .ts,.tsx",
|
10
|
-
"clean": "del-cli lib",
|
11
10
|
"prepare": "husky install && bob build",
|
12
11
|
"precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
|
13
|
-
"release": "release-it"
|
12
|
+
"release": "release-it patch --preRelease=alpha --npm.tag=next"
|
14
13
|
},
|
15
14
|
"main": "lib/commonjs/index",
|
16
15
|
"module": "lib/module/index",
|
@@ -20,7 +19,19 @@
|
|
20
19
|
"files": [
|
21
20
|
"src",
|
22
21
|
"lib",
|
22
|
+
"ios",
|
23
|
+
"android",
|
24
|
+
"cxx",
|
25
|
+
"react-native-unistyles.podspec",
|
26
|
+
"!lib/typescript/examples",
|
27
|
+
"!ios/build",
|
28
|
+
"!android/build",
|
29
|
+
"!android/gradle",
|
30
|
+
"!android/gradlew",
|
31
|
+
"!android/gradlew.bat",
|
32
|
+
"!android/local.properties",
|
23
33
|
"!**/*.spec.ts",
|
34
|
+
"!**/*.spec.tsx",
|
24
35
|
"!**/.*"
|
25
36
|
],
|
26
37
|
"keywords": [
|
@@ -39,26 +50,24 @@
|
|
39
50
|
"registry": "https://registry.npmjs.org/"
|
40
51
|
},
|
41
52
|
"devDependencies": {
|
42
|
-
"@commitlint/config-conventional": "
|
53
|
+
"@commitlint/config-conventional": "18.1.0",
|
43
54
|
"@react-native/eslint-config": "0.74.0",
|
44
55
|
"@react-native/normalize-colors": "0.74.1",
|
45
|
-
"@release-it/conventional-changelog": "
|
56
|
+
"@release-it/conventional-changelog": "7.0.2",
|
46
57
|
"@testing-library/react-hooks": "8.0.1",
|
47
|
-
"@types/jest": "29.5.
|
48
|
-
"@types/react": "18.2.
|
49
|
-
"@
|
50
|
-
"@typescript-eslint/eslint-plugin": "6.
|
51
|
-
"@typescript-eslint/
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"del-cli": "5.1.0",
|
56
|
-
"eslint": "8.51.0",
|
58
|
+
"@types/jest": "29.5.7",
|
59
|
+
"@types/react": "18.2.34",
|
60
|
+
"@typescript-eslint/eslint-plugin": "6.9.1",
|
61
|
+
"@typescript-eslint/eslint-plugin-tslint": "6.9.1",
|
62
|
+
"@typescript-eslint/parser": "6.9.1",
|
63
|
+
"commitlint": "18.2.0",
|
64
|
+
"concurrently": "8.2.2",
|
65
|
+
"eslint": "8.53.0",
|
57
66
|
"eslint-config-codemask": "1.1.7",
|
58
67
|
"eslint-plugin-functional": "6.0.0",
|
59
|
-
"eslint-plugin-import": "2.
|
68
|
+
"eslint-plugin-import": "2.29.0",
|
60
69
|
"eslint-plugin-jsdoc": "46.8.2",
|
61
|
-
"eslint-plugin-jsx-a11y": "6.
|
70
|
+
"eslint-plugin-jsx-a11y": "6.8.0",
|
62
71
|
"eslint-plugin-nested-if": "1.0.0",
|
63
72
|
"eslint-plugin-no-else": "0.2.2",
|
64
73
|
"eslint-plugin-no-loops": "0.3.0",
|
@@ -120,11 +129,13 @@
|
|
120
129
|
"publish": true
|
121
130
|
},
|
122
131
|
"github": {
|
123
|
-
"release":
|
132
|
+
"release": false
|
124
133
|
},
|
125
134
|
"plugins": {
|
126
135
|
"@release-it/conventional-changelog": {
|
127
|
-
"preset":
|
136
|
+
"preset": {
|
137
|
+
"name": "conventionalcommits"
|
138
|
+
}
|
128
139
|
}
|
129
140
|
}
|
130
141
|
},
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
4
|
+
|
5
|
+
Pod::Spec.new do |s|
|
6
|
+
s.name = package["name"]
|
7
|
+
s.version = package["version"]
|
8
|
+
s.summary = package["description"]
|
9
|
+
s.homepage = package["homepage"]
|
10
|
+
s.license = package["license"]
|
11
|
+
s.authors = package["author"]
|
12
|
+
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
14
|
+
s.source = { :git => package["repository"], :tag => "#{s.version}" }
|
15
|
+
|
16
|
+
s.source_files = [
|
17
|
+
"ios/*.{h,mm}",
|
18
|
+
"cxx/*.{h,cpp}"
|
19
|
+
]
|
20
|
+
|
21
|
+
s.dependency "React-Core"
|
22
|
+
end
|
package/src/common.ts
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
export enum CxxUnistylesEventTypes {
|
2
|
+
Theme = 'theme',
|
3
|
+
Layout = 'layout'
|
4
|
+
}
|
5
|
+
|
6
|
+
export enum UnistylesError {
|
7
|
+
RuntimeUnavailable = 'UNISTYLES_ERROR_RUNTIME_UNAVAILABLE',
|
8
|
+
ThemeNotFound = 'UNISTYLES_ERROR_THEME_NOT_FOUND',
|
9
|
+
ThemeNotRegistered = 'UNISTYLES_ERROR_THEME_NOT_REGISTERED',
|
10
|
+
ThemesCannotBeEmpty = 'UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY',
|
11
|
+
BreakpointsCannotBeEmpty = 'UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY',
|
12
|
+
BreakpointsMustStartFromZero = 'UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO',
|
13
|
+
}
|
14
|
+
|
15
|
+
// todo to string?
|
16
|
+
export enum ScreenOrientation {
|
17
|
+
Portrait = 1,
|
18
|
+
Landscape = 2
|
19
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import type { UnistylesBridge, UnistylesConfig } from '../types'
|
2
|
+
import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
|
3
|
+
|
4
|
+
export class UnistyleRegistry {
|
5
|
+
public config: UnistylesConfig = {}
|
6
|
+
public themeNames: Array<keyof UnistylesThemes> = []
|
7
|
+
public themes: UnistylesThemes = {} as UnistylesThemes
|
8
|
+
public breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
|
9
|
+
public sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]> = []
|
10
|
+
|
11
|
+
constructor(private unistylesBridge: UnistylesBridge) {}
|
12
|
+
|
13
|
+
public addThemes = (themes: UnistylesThemes) => {
|
14
|
+
this.themes = themes
|
15
|
+
|
16
|
+
const keys = Object.keys(themes) as Array<keyof UnistylesThemes>
|
17
|
+
|
18
|
+
this.unistylesBridge.themes = keys
|
19
|
+
this.themeNames = keys
|
20
|
+
|
21
|
+
return this
|
22
|
+
}
|
23
|
+
|
24
|
+
public addBreakpoints = (breakpoints: UnistylesBreakpoints) => {
|
25
|
+
this.breakpoints = breakpoints
|
26
|
+
this.unistylesBridge.useBreakpoints(breakpoints)
|
27
|
+
this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs
|
28
|
+
|
29
|
+
return this
|
30
|
+
}
|
31
|
+
|
32
|
+
public addConfig = (config: UnistylesConfig) => {
|
33
|
+
this.config = config
|
34
|
+
|
35
|
+
if (config.adaptiveThemes) {
|
36
|
+
this.unistylesBridge.useAdaptiveThemes(config.adaptiveThemes)
|
37
|
+
}
|
38
|
+
|
39
|
+
return this
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { UnistylesModule } from './UnistylesModule'
|
2
|
+
import { UnistylesRuntime } from './UnistylesRuntime'
|
3
|
+
import { UnistyleRegistry } from './UnistyleRegistry'
|
4
|
+
import type { UnistylesBridge } from '../types'
|
5
|
+
import { UnistylesError } from '../common'
|
6
|
+
|
7
|
+
class Unistyles {
|
8
|
+
private _runtime: UnistylesRuntime
|
9
|
+
private _registry: UnistyleRegistry
|
10
|
+
private _bridge: UnistylesBridge
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
const isInstalled = UnistylesModule?.install() ?? false
|
14
|
+
|
15
|
+
if (!isInstalled) {
|
16
|
+
throw new Error(UnistylesError.RuntimeUnavailable)
|
17
|
+
}
|
18
|
+
|
19
|
+
// @ts-ignore
|
20
|
+
this._bridge = global.__UNISTYLES__ as UnistylesBridge
|
21
|
+
this._registry = new UnistyleRegistry(this._bridge)
|
22
|
+
this._runtime = new UnistylesRuntime(this._bridge, this._registry)
|
23
|
+
}
|
24
|
+
|
25
|
+
public get registry() {
|
26
|
+
return this._registry
|
27
|
+
}
|
28
|
+
|
29
|
+
public get runtime() {
|
30
|
+
return this._runtime
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export const unistyles = new Unistyles()
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { ScreenOrientation, UnistylesError } from '../common'
|
2
|
+
import type { UnistylesBridge } from '../types'
|
3
|
+
import type { UnistylesThemes } from '../global'
|
4
|
+
import type { UnistyleRegistry } from './UnistyleRegistry'
|
5
|
+
|
6
|
+
export class UnistylesRuntime {
|
7
|
+
constructor(private unistylesBridge: UnistylesBridge, private registry: UnistyleRegistry) {}
|
8
|
+
|
9
|
+
public get colorScheme() {
|
10
|
+
return this.unistylesBridge.colorScheme
|
11
|
+
}
|
12
|
+
|
13
|
+
public get hasAdaptiveThemes() {
|
14
|
+
return this.unistylesBridge.hasAdaptiveThemes
|
15
|
+
}
|
16
|
+
|
17
|
+
public get sortedBreakpoints() {
|
18
|
+
return this.registry.sortedBreakpointPairs
|
19
|
+
}
|
20
|
+
|
21
|
+
public get themeName() {
|
22
|
+
return this.unistylesBridge.themeName
|
23
|
+
}
|
24
|
+
|
25
|
+
public get breakpoint() {
|
26
|
+
return this.unistylesBridge.breakpoint
|
27
|
+
}
|
28
|
+
|
29
|
+
public get screen() {
|
30
|
+
return {
|
31
|
+
width: this.unistylesBridge.screenWidth,
|
32
|
+
height: this.unistylesBridge.screenHeight
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
public get orientation() {
|
37
|
+
const { width, height } = this.screen
|
38
|
+
|
39
|
+
if (width > height) {
|
40
|
+
return ScreenOrientation.Landscape
|
41
|
+
}
|
42
|
+
|
43
|
+
return ScreenOrientation.Portrait
|
44
|
+
}
|
45
|
+
|
46
|
+
public setTheme = (name: keyof UnistylesThemes) => {
|
47
|
+
if (this.hasTheme(name)) {
|
48
|
+
this.unistylesBridge.useTheme(name)
|
49
|
+
|
50
|
+
return true
|
51
|
+
}
|
52
|
+
|
53
|
+
throw new Error(UnistylesError.ThemeNotRegistered)
|
54
|
+
}
|
55
|
+
|
56
|
+
public getTheme = (forName: keyof UnistylesThemes) => {
|
57
|
+
if (this.registry.themeNames.length === 0) {
|
58
|
+
return {} as UnistylesThemes[keyof UnistylesThemes]
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!this.hasTheme(forName)) {
|
62
|
+
throw new Error(UnistylesError.ThemeNotFound)
|
63
|
+
}
|
64
|
+
|
65
|
+
return this.registry.themes[forName]
|
66
|
+
}
|
67
|
+
|
68
|
+
public setAdaptiveThemes = (enable: boolean) => {
|
69
|
+
this.unistylesBridge.useAdaptiveThemes(enable)
|
70
|
+
}
|
71
|
+
|
72
|
+
private hasTheme = (name: keyof UnistylesThemes) => name in this.registry.themes
|
73
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { unistyles } from './Unistyles'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { CustomNamedStyles, UnistylesTheme } from './types'
|
2
|
+
|
3
|
+
export const createStyleSheet = <S, X>(styles: S | CustomNamedStyles<S> | X | ((theme: UnistylesTheme) => X | CustomNamedStyles<X>)): S | X => {
|
4
|
+
if (typeof styles === 'function') {
|
5
|
+
return styles as X
|
6
|
+
}
|
7
|
+
|
8
|
+
return styles as S
|
9
|
+
}
|
package/src/global.ts
ADDED
package/src/hooks/index.ts
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
export {
|
1
|
+
export { useInitialTheme } from './useInitialTheme'
|
2
|
+
export { useUnistyles } from './useUnistyles'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { useMemo } from 'react'
|
2
|
+
import { unistyles } from '../core'
|
3
|
+
import type { UnistylesThemes } from '../global'
|
4
|
+
|
5
|
+
export const useInitialTheme = (forName: keyof UnistylesThemes) => {
|
6
|
+
useMemo(() => {
|
7
|
+
if (!unistyles.runtime.themeName) {
|
8
|
+
unistyles.runtime.setTheme(forName)
|
9
|
+
}
|
10
|
+
}, [])
|
11
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { NativeEventEmitter, NativeModules } from 'react-native'
|
2
|
+
import { useEffect, useState } from 'react'
|
3
|
+
import { unistyles } from '../core'
|
4
|
+
import { CxxUnistylesEventTypes } from '../common'
|
5
|
+
import type { UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
|
6
|
+
|
7
|
+
const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
|
8
|
+
|
9
|
+
export const useUnistyles = () => {
|
10
|
+
const [theme, setTheme] = useState(unistyles.runtime.getTheme(unistyles.runtime.themeName))
|
11
|
+
const [layout, setLayout] = useState({
|
12
|
+
breakpoint: unistyles.runtime.breakpoint,
|
13
|
+
orientation: unistyles.runtime.orientation,
|
14
|
+
screenSize: {
|
15
|
+
width: unistyles.runtime.screen.width,
|
16
|
+
height: unistyles.runtime.screen.height
|
17
|
+
}
|
18
|
+
})
|
19
|
+
|
20
|
+
useEffect(() => {
|
21
|
+
const subscription = unistylesEvents.addListener(
|
22
|
+
'onChange',
|
23
|
+
(event: UnistylesEvents) => {
|
24
|
+
switch (event.type) {
|
25
|
+
case CxxUnistylesEventTypes.Theme: {
|
26
|
+
const themeEvent = event as UnistylesThemeEvent
|
27
|
+
|
28
|
+
return setTheme(unistyles.runtime.getTheme(themeEvent.payload.themeName))
|
29
|
+
}
|
30
|
+
case CxxUnistylesEventTypes.Layout: {
|
31
|
+
const layoutEvent = event as UnistylesMobileLayoutEvent
|
32
|
+
|
33
|
+
return setLayout({
|
34
|
+
breakpoint: layoutEvent.payload.breakpoint,
|
35
|
+
orientation: layoutEvent.payload.orientation,
|
36
|
+
screenSize: {
|
37
|
+
width: layoutEvent.payload.screen.width,
|
38
|
+
height: layoutEvent.payload.screen.height
|
39
|
+
}
|
40
|
+
})
|
41
|
+
}
|
42
|
+
default:
|
43
|
+
return
|
44
|
+
}
|
45
|
+
}
|
46
|
+
)
|
47
|
+
|
48
|
+
return subscription.remove
|
49
|
+
}, [])
|
50
|
+
|
51
|
+
return {
|
52
|
+
theme,
|
53
|
+
layout
|
54
|
+
}
|
55
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,2 +1,30 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { unistyles } from './core'
|
2
|
+
import { mq } from './utils'
|
3
|
+
import { useInitialTheme } from './hooks'
|
4
|
+
import type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
5
|
+
import { ScreenOrientation } from './common'
|
6
|
+
import { useStyles } from './useStyles'
|
7
|
+
import { createStyleSheet } from './createStyleSheet'
|
8
|
+
|
9
|
+
const UnistylesRegistry = {
|
10
|
+
addThemes: unistyles.registry.addThemes,
|
11
|
+
addBreakpoints: unistyles.registry.addBreakpoints,
|
12
|
+
addConfig: unistyles.registry.addConfig
|
13
|
+
}
|
14
|
+
|
15
|
+
const UnistylesRuntime = unistyles.runtime
|
16
|
+
|
17
|
+
export {
|
18
|
+
mq,
|
19
|
+
useStyles,
|
20
|
+
useInitialTheme,
|
21
|
+
createStyleSheet,
|
22
|
+
ScreenOrientation,
|
23
|
+
UnistylesRegistry,
|
24
|
+
UnistylesRuntime
|
25
|
+
}
|
26
|
+
|
27
|
+
export type {
|
28
|
+
UnistylesThemes,
|
29
|
+
UnistylesBreakpoints
|
30
|
+
}
|