@niibase/uniwind 1.6.3 → 1.6.4
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/CHANGELOG.md +22 -0
- package/dist/common/components/index.js +0 -3
- package/dist/common/core/config/config.common.js +6 -0
- package/dist/common/hooks/useCSSVariable/index.js +7 -11
- package/dist/common/hooks/useCSSVariable/useCSSVariable.js +20 -16
- package/dist/metro/metro-transformer.cjs +13 -0
- package/dist/metro/metro-transformer.mjs +13 -0
- package/dist/module/components/index.js +0 -3
- package/dist/module/core/config/config.common.d.ts +2 -0
- package/dist/module/core/config/config.common.js +4 -0
- package/dist/module/hooks/useCSSVariable/index.d.ts +1 -1
- package/dist/module/hooks/useCSSVariable/index.js +1 -1
- package/dist/module/hooks/useCSSVariable/useCSSVariable.d.ts +4 -2
- package/dist/module/hooks/useCSSVariable/useCSSVariable.js +18 -15
- package/package.json +1 -1
- package/src/components/index.ts +0 -3
- package/src/core/config/config.common.ts +5 -0
- package/src/hooks/useCSSVariable/index.ts +1 -1
- package/src/hooks/useCSSVariable/useCSSVariable.ts +26 -23
- package/src/metro/processor/rn.ts +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## What's Changed in 1.6.4
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### 🚀 Features
|
|
6
|
+
|
|
7
|
+
* getCSSVariable function to get css variable outside of react (#521) by @Brentlok
|
|
8
|
+
* parse inline-start inline-end border to RN (#515) by @Brentlok
|
|
9
|
+
|
|
10
|
+
### 🐛 Bug Fixes
|
|
11
|
+
|
|
12
|
+
* join border radius to fix some components (#517) by @Brentlok
|
|
13
|
+
* remove deprecated push notification ios export (#516) by @Brentlok
|
|
14
|
+
|
|
15
|
+
### 📦 Other
|
|
16
|
+
|
|
17
|
+
* Merge branch 'pre-release' by @divineniiquaye
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
**Full Changelog**: https://github.com/divineniiquaye/uniwind/compare/v1.6.3...v1.6.4
|
|
21
|
+
|
|
22
|
+
|
|
1
23
|
## What's Changed in 1.6.3
|
|
2
24
|
|
|
3
25
|
|
|
@@ -197,9 +197,6 @@ module.exports = {
|
|
|
197
197
|
get PlatformColor() {
|
|
198
198
|
return require("react-native").PlatformColor;
|
|
199
199
|
},
|
|
200
|
-
get PushNotificationIOS() {
|
|
201
|
-
return require("react-native").PushNotificationIOS;
|
|
202
|
-
},
|
|
203
200
|
get processColor() {
|
|
204
201
|
return require("react-native").processColor;
|
|
205
202
|
},
|
|
@@ -7,6 +7,7 @@ exports.UniwindConfigBuilder = exports.Uniwind = void 0;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _withUniwind = require("../../hoc/withUniwind");
|
|
10
|
+
var _useCSSVariable = require("../../hooks/useCSSVariable/useCSSVariable");
|
|
10
11
|
var _types = require("../../types");
|
|
11
12
|
var _listener = require("../listener");
|
|
12
13
|
const SYSTEM_THEME = "system";
|
|
@@ -88,6 +89,11 @@ class UniwindConfigBuilder {
|
|
|
88
89
|
updateCSSVariables(theme, cssVariables) {}
|
|
89
90
|
// oxlint-disable-next-line typescript/no-unused-vars
|
|
90
91
|
updateInsets(insets) {}
|
|
92
|
+
getCSSVariable = variableName => {
|
|
93
|
+
return (0, _useCSSVariable.getCSSVariable)(variableName, {
|
|
94
|
+
scopedTheme: null
|
|
95
|
+
});
|
|
96
|
+
};
|
|
91
97
|
__reinit(_, themes) {
|
|
92
98
|
this._themes = themes;
|
|
93
99
|
}
|
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return _useCSSVariable[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
6
|
+
Object.defineProperty(exports, "useCSSVariable", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useCSSVariable.useCSSVariable;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _useCSSVariable = require("./useCSSVariable");
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useCSSVariable = void 0;
|
|
6
|
+
exports.useCSSVariable = exports.getCSSVariable = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _utils = require("../../common/utils");
|
|
9
9
|
var _context = require("../../core/context");
|
|
@@ -11,45 +11,49 @@ var _listener = require("../../core/listener");
|
|
|
11
11
|
var _logger = require("../../core/logger");
|
|
12
12
|
var _types = require("../../types");
|
|
13
13
|
var _getVariableValue = require("./getVariableValue");
|
|
14
|
-
const getValue = (name, uniwindContext) => Array.isArray(name) ? name.map(name2 => (0, _getVariableValue.getVariableValue)(name2, uniwindContext)) : (0, _getVariableValue.getVariableValue)(name, uniwindContext);
|
|
15
14
|
let warned = false;
|
|
16
15
|
const logDevError = name => {
|
|
17
16
|
warned = true;
|
|
18
17
|
_logger.Logger.warn(`We couldn't find your variable ${name}. Make sure it's used at least once in your className, or define it in a static theme as described in the docs: https://docs.uniwind.dev/api/use-css-variable`);
|
|
19
18
|
};
|
|
19
|
+
const getCSSVariable = (name, uniwindContext) => {
|
|
20
|
+
const value = Array.isArray(name) ? name.map(name2 => (0, _getVariableValue.getVariableValue)(name2, uniwindContext)) : (0, _getVariableValue.getVariableValue)(name, uniwindContext);
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
value.forEach((val, index) => {
|
|
23
|
+
if (val === void 0 && __DEV__ && !warned) {
|
|
24
|
+
logDevError(name[index] ?? "");
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (value === void 0 && __DEV__ && !warned) {
|
|
29
|
+
logDevError(name);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
exports.getCSSVariable = getCSSVariable;
|
|
20
34
|
const useCSSVariable = name => {
|
|
21
35
|
const uniwindContext = (0, _context.useUniwindContext)();
|
|
22
|
-
const [value, setValue] = (0, _react.useState)(
|
|
36
|
+
const [value, setValue] = (0, _react.useState)(getCSSVariable(name, uniwindContext));
|
|
23
37
|
const nameRef = (0, _react.useRef)(name);
|
|
24
38
|
(0, _react.useLayoutEffect)(() => {
|
|
25
39
|
if (Array.isArray(name) && Array.isArray(nameRef.current)) {
|
|
26
40
|
if ((0, _utils.arrayEquals)(name, nameRef.current)) {
|
|
27
41
|
return;
|
|
28
42
|
}
|
|
29
|
-
setValue(
|
|
43
|
+
setValue(getCSSVariable(name, uniwindContext));
|
|
30
44
|
nameRef.current = name;
|
|
31
45
|
return;
|
|
32
46
|
}
|
|
33
47
|
if (name !== nameRef.current) {
|
|
34
|
-
setValue(
|
|
48
|
+
setValue(getCSSVariable(name, uniwindContext));
|
|
35
49
|
nameRef.current = name;
|
|
36
50
|
}
|
|
37
51
|
}, [name]);
|
|
38
52
|
(0, _react.useLayoutEffect)(() => {
|
|
39
|
-
const updateValue = () => setValue(
|
|
53
|
+
const updateValue = () => setValue(getCSSVariable(nameRef.current, uniwindContext));
|
|
40
54
|
const dispose = _listener.UniwindListener.subscribe(updateValue, [_types.StyleDependency.Theme, _types.StyleDependency.Variables]);
|
|
41
55
|
return dispose;
|
|
42
56
|
}, [uniwindContext]);
|
|
43
|
-
if (Array.isArray(value)) {
|
|
44
|
-
value.forEach((val, index) => {
|
|
45
|
-
if (val === void 0 && __DEV__ && !warned) {
|
|
46
|
-
logDevError(name[index] ?? "");
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (value === void 0 && __DEV__ && !warned) {
|
|
51
|
-
logDevError(name);
|
|
52
|
-
}
|
|
53
57
|
return value;
|
|
54
58
|
};
|
|
55
59
|
exports.useCSSVariable = useCSSVariable;
|
|
@@ -1485,6 +1485,7 @@ const cssToRNMap = {
|
|
|
1485
1485
|
};
|
|
1486
1486
|
const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
|
|
1487
1487
|
const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
|
|
1488
|
+
const BORDER_RADIUS_KEYS = ["borderTopLeftRadius", "borderTopRightRadius", "borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
1488
1489
|
class RN {
|
|
1489
1490
|
constructor(Processor) {
|
|
1490
1491
|
this.Processor = Processor;
|
|
@@ -1496,6 +1497,9 @@ class RN {
|
|
|
1496
1497
|
if (x.includes("padding") || x.includes("margin")) {
|
|
1497
1498
|
return x.replace("InlineStart", "Start").replace("InlineEnd", "End").replace("Inline", "Horizontal").replace("Block", "Vertical");
|
|
1498
1499
|
}
|
|
1500
|
+
if (x.includes("border")) {
|
|
1501
|
+
return x.replace("InlineStart", "Start").replace("InlineEnd", "End");
|
|
1502
|
+
}
|
|
1499
1503
|
return x;
|
|
1500
1504
|
}
|
|
1501
1505
|
);
|
|
@@ -1599,6 +1603,15 @@ class RN {
|
|
|
1599
1603
|
};
|
|
1600
1604
|
}
|
|
1601
1605
|
}
|
|
1606
|
+
if (BORDER_RADIUS_KEYS.every((key) => keys.includes(key))) {
|
|
1607
|
+
const borderRadius = styles.borderTopLeftRadius;
|
|
1608
|
+
if (BORDER_RADIUS_KEYS.every((key) => styles[key] === borderRadius)) {
|
|
1609
|
+
return {
|
|
1610
|
+
...common.removeKeys(styles, BORDER_RADIUS_KEYS),
|
|
1611
|
+
borderRadius
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1602
1615
|
return styles;
|
|
1603
1616
|
}
|
|
1604
1617
|
}
|
|
@@ -1478,6 +1478,7 @@ const cssToRNMap = {
|
|
|
1478
1478
|
};
|
|
1479
1479
|
const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
|
|
1480
1480
|
const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
|
|
1481
|
+
const BORDER_RADIUS_KEYS = ["borderTopLeftRadius", "borderTopRightRadius", "borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
1481
1482
|
class RN {
|
|
1482
1483
|
constructor(Processor) {
|
|
1483
1484
|
this.Processor = Processor;
|
|
@@ -1489,6 +1490,9 @@ class RN {
|
|
|
1489
1490
|
if (x.includes("padding") || x.includes("margin")) {
|
|
1490
1491
|
return x.replace("InlineStart", "Start").replace("InlineEnd", "End").replace("Inline", "Horizontal").replace("Block", "Vertical");
|
|
1491
1492
|
}
|
|
1493
|
+
if (x.includes("border")) {
|
|
1494
|
+
return x.replace("InlineStart", "Start").replace("InlineEnd", "End");
|
|
1495
|
+
}
|
|
1492
1496
|
return x;
|
|
1493
1497
|
}
|
|
1494
1498
|
);
|
|
@@ -1592,6 +1596,15 @@ class RN {
|
|
|
1592
1596
|
};
|
|
1593
1597
|
}
|
|
1594
1598
|
}
|
|
1599
|
+
if (BORDER_RADIUS_KEYS.every((key) => keys.includes(key))) {
|
|
1600
|
+
const borderRadius = styles.borderTopLeftRadius;
|
|
1601
|
+
if (BORDER_RADIUS_KEYS.every((key) => styles[key] === borderRadius)) {
|
|
1602
|
+
return {
|
|
1603
|
+
...removeKeys(styles, BORDER_RADIUS_KEYS),
|
|
1604
|
+
borderRadius
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1595
1608
|
return styles;
|
|
1596
1609
|
}
|
|
1597
1610
|
}
|
|
@@ -195,9 +195,6 @@ module.exports = {
|
|
|
195
195
|
get PlatformColor() {
|
|
196
196
|
return require("react-native").PlatformColor;
|
|
197
197
|
},
|
|
198
|
-
get PushNotificationIOS() {
|
|
199
|
-
return require("react-native").PushNotificationIOS;
|
|
200
|
-
},
|
|
201
198
|
get processColor() {
|
|
202
199
|
return require("react-native").processColor;
|
|
203
200
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ComponentPropsWithRef, ElementType } from 'react';
|
|
2
2
|
import { Insets } from 'react-native';
|
|
3
3
|
import { ApplyUniwind } from '../../hoc/types';
|
|
4
|
+
import { GetCSSVariable } from '../../hooks/useCSSVariable/useCSSVariable';
|
|
4
5
|
import { CSSVariables, GenerateStyleSheetsCallback, ThemeName } from '../types';
|
|
5
6
|
declare const SYSTEM_THEME: "system";
|
|
6
7
|
export declare class UniwindConfigBuilder {
|
|
@@ -17,6 +18,7 @@ export declare class UniwindConfigBuilder {
|
|
|
17
18
|
setTheme(theme: ThemeName | typeof SYSTEM_THEME): void;
|
|
18
19
|
updateCSSVariables(theme: ThemeName, cssVariables: CSSVariables): void;
|
|
19
20
|
updateInsets(insets: Insets): void;
|
|
21
|
+
getCSSVariable: GetCSSVariable;
|
|
20
22
|
protected __reinit(_: GenerateStyleSheetsCallback, themes: Array<string>): void;
|
|
21
23
|
protected onThemeChange(): void;
|
|
22
24
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement, useMemo } from "react";
|
|
2
2
|
import { Appearance, Platform } from "react-native";
|
|
3
3
|
import { withUniwind } from "../../hoc/withUniwind.js";
|
|
4
|
+
import { getCSSVariable } from "../../hooks/useCSSVariable/useCSSVariable.js";
|
|
4
5
|
import { ColorScheme, StyleDependency } from "../../types.js";
|
|
5
6
|
import { UniwindListener } from "../listener.js";
|
|
6
7
|
const SYSTEM_THEME = "system";
|
|
@@ -82,6 +83,9 @@ export class UniwindConfigBuilder {
|
|
|
82
83
|
// oxlint-disable-next-line typescript/no-unused-vars
|
|
83
84
|
updateInsets(insets) {
|
|
84
85
|
}
|
|
86
|
+
getCSSVariable = ((variableName) => {
|
|
87
|
+
return getCSSVariable(variableName, { scopedTheme: null });
|
|
88
|
+
});
|
|
85
89
|
__reinit(_, themes) {
|
|
86
90
|
this._themes = themes;
|
|
87
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { useCSSVariable } from './useCSSVariable';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { useCSSVariable } from "./useCSSVariable.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { UniwindContextType } from '../../core/types';
|
|
2
|
+
export declare const getCSSVariable: (name: string | Array<string>, uniwindContext: UniwindContextType) => string | (string | undefined)[] | undefined;
|
|
1
3
|
type IsGenericNumber<T> = T & 0 extends -1 ? false : true;
|
|
2
4
|
type CreateArray<N extends number, Value, TAcc extends Array<Value> = []> = TAcc['length'] extends N ? TAcc : CreateArray<N, Value, [...TAcc, Value]>;
|
|
3
|
-
type
|
|
5
|
+
export type GetCSSVariable = {
|
|
4
6
|
(name: string): string | number | undefined;
|
|
5
7
|
<const T extends Array<string>>(names: T): IsGenericNumber<T['length']> extends true ? Array<string | number | undefined> : CreateArray<T['length'], string | number | undefined>;
|
|
6
8
|
};
|
|
@@ -9,5 +11,5 @@ type UseCSSVariable = {
|
|
|
9
11
|
* @param name Name / Array of names of the CSS variable.
|
|
10
12
|
* @returns Value / Values of the CSS variable. On web it is always a string (1rem, #ff0000, etc.), but on native it can be a string or a number (16px, #ff0000)
|
|
11
13
|
*/
|
|
12
|
-
export declare const useCSSVariable:
|
|
14
|
+
export declare const useCSSVariable: GetCSSVariable;
|
|
13
15
|
export {};
|
|
@@ -5,7 +5,6 @@ import { UniwindListener } from "../../core/listener.js";
|
|
|
5
5
|
import { Logger } from "../../core/logger.js";
|
|
6
6
|
import { StyleDependency } from "../../types.js";
|
|
7
7
|
import { getVariableValue } from "./getVariableValue.js";
|
|
8
|
-
const getValue = (name, uniwindContext) => Array.isArray(name) ? name.map((name2) => getVariableValue(name2, uniwindContext)) : getVariableValue(name, uniwindContext);
|
|
9
8
|
let warned = false;
|
|
10
9
|
const logDevError = (name) => {
|
|
11
10
|
warned = true;
|
|
@@ -13,41 +12,45 @@ const logDevError = (name) => {
|
|
|
13
12
|
`We couldn't find your variable ${name}. Make sure it's used at least once in your className, or define it in a static theme as described in the docs: https://docs.uniwind.dev/api/use-css-variable`
|
|
14
13
|
);
|
|
15
14
|
};
|
|
15
|
+
export const getCSSVariable = (name, uniwindContext) => {
|
|
16
|
+
const value = Array.isArray(name) ? name.map((name2) => getVariableValue(name2, uniwindContext)) : getVariableValue(name, uniwindContext);
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
value.forEach((val, index) => {
|
|
19
|
+
if (val === void 0 && __DEV__ && !warned) {
|
|
20
|
+
logDevError(name[index] ?? "");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (value === void 0 && __DEV__ && !warned) {
|
|
25
|
+
logDevError(name);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
16
29
|
export const useCSSVariable = (name) => {
|
|
17
30
|
const uniwindContext = useUniwindContext();
|
|
18
|
-
const [value, setValue] = useState(
|
|
31
|
+
const [value, setValue] = useState(getCSSVariable(name, uniwindContext));
|
|
19
32
|
const nameRef = useRef(name);
|
|
20
33
|
useLayoutEffect(() => {
|
|
21
34
|
if (Array.isArray(name) && Array.isArray(nameRef.current)) {
|
|
22
35
|
if (arrayEquals(name, nameRef.current)) {
|
|
23
36
|
return;
|
|
24
37
|
}
|
|
25
|
-
setValue(
|
|
38
|
+
setValue(getCSSVariable(name, uniwindContext));
|
|
26
39
|
nameRef.current = name;
|
|
27
40
|
return;
|
|
28
41
|
}
|
|
29
42
|
if (name !== nameRef.current) {
|
|
30
|
-
setValue(
|
|
43
|
+
setValue(getCSSVariable(name, uniwindContext));
|
|
31
44
|
nameRef.current = name;
|
|
32
45
|
}
|
|
33
46
|
}, [name]);
|
|
34
47
|
useLayoutEffect(() => {
|
|
35
|
-
const updateValue = () => setValue(
|
|
48
|
+
const updateValue = () => setValue(getCSSVariable(nameRef.current, uniwindContext));
|
|
36
49
|
const dispose = UniwindListener.subscribe(
|
|
37
50
|
updateValue,
|
|
38
51
|
[StyleDependency.Theme, StyleDependency.Variables]
|
|
39
52
|
);
|
|
40
53
|
return dispose;
|
|
41
54
|
}, [uniwindContext]);
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
value.forEach((val, index) => {
|
|
44
|
-
if (val === void 0 && __DEV__ && !warned) {
|
|
45
|
-
logDevError(name[index] ?? "");
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (value === void 0 && __DEV__ && !warned) {
|
|
50
|
-
logDevError(name);
|
|
51
|
-
}
|
|
52
55
|
return value;
|
|
53
56
|
};
|
package/package.json
CHANGED
package/src/components/index.ts
CHANGED
|
@@ -196,9 +196,6 @@ module.exports = {
|
|
|
196
196
|
get PlatformColor() {
|
|
197
197
|
return require('react-native').PlatformColor
|
|
198
198
|
},
|
|
199
|
-
get PushNotificationIOS() {
|
|
200
|
-
return require('react-native').PushNotificationIOS
|
|
201
|
-
},
|
|
202
199
|
get processColor() {
|
|
203
200
|
return require('react-native').processColor
|
|
204
201
|
},
|
|
@@ -2,6 +2,7 @@ import { ComponentPropsWithRef, createElement, ElementType, useMemo } from 'reac
|
|
|
2
2
|
import { Appearance, Insets, Platform } from 'react-native'
|
|
3
3
|
import { ApplyUniwind } from '../../hoc/types'
|
|
4
4
|
import { withUniwind } from '../../hoc/withUniwind'
|
|
5
|
+
import { GetCSSVariable, getCSSVariable } from '../../hooks/useCSSVariable/useCSSVariable'
|
|
5
6
|
import { ColorScheme, StyleDependency } from '../../types'
|
|
6
7
|
import { UniwindListener } from '../listener'
|
|
7
8
|
import { CSSVariables, GenerateStyleSheetsCallback, ThemeName } from '../types'
|
|
@@ -116,6 +117,10 @@ export class UniwindConfigBuilder {
|
|
|
116
117
|
// noop
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
getCSSVariable = ((variableName: string | Array<string>) => {
|
|
121
|
+
return getCSSVariable(variableName, { scopedTheme: null })
|
|
122
|
+
}) as GetCSSVariable
|
|
123
|
+
|
|
119
124
|
protected __reinit(_: GenerateStyleSheetsCallback, themes: Array<string>) {
|
|
120
125
|
this._themes = themes
|
|
121
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { useCSSVariable } from './useCSSVariable'
|
|
@@ -7,11 +7,6 @@ import { UniwindContextType } from '../../core/types'
|
|
|
7
7
|
import { StyleDependency } from '../../types'
|
|
8
8
|
import { getVariableValue } from './getVariableValue'
|
|
9
9
|
|
|
10
|
-
const getValue = (name: string | Array<string>, uniwindContext: UniwindContextType) =>
|
|
11
|
-
Array.isArray(name)
|
|
12
|
-
? name.map(name => getVariableValue(name, uniwindContext))
|
|
13
|
-
: getVariableValue(name, uniwindContext)
|
|
14
|
-
|
|
15
10
|
let warned = false
|
|
16
11
|
|
|
17
12
|
const logDevError = (name: string) => {
|
|
@@ -21,10 +16,30 @@ const logDevError = (name: string) => {
|
|
|
21
16
|
)
|
|
22
17
|
}
|
|
23
18
|
|
|
19
|
+
export const getCSSVariable = (name: string | Array<string>, uniwindContext: UniwindContextType) => {
|
|
20
|
+
const value = Array.isArray(name)
|
|
21
|
+
? name.map(name => getVariableValue(name, uniwindContext))
|
|
22
|
+
: getVariableValue(name, uniwindContext)
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
value.forEach((val, index) => {
|
|
26
|
+
if (val === undefined && __DEV__ && !warned) {
|
|
27
|
+
logDevError(name[index] ?? '')
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (value === undefined && __DEV__ && !warned) {
|
|
33
|
+
logDevError(name as string)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return value
|
|
37
|
+
}
|
|
38
|
+
|
|
24
39
|
type IsGenericNumber<T> = T & 0 extends -1 ? false : true
|
|
25
40
|
type CreateArray<N extends number, Value, TAcc extends Array<Value> = []> = TAcc['length'] extends N ? TAcc : CreateArray<N, Value, [...TAcc, Value]>
|
|
26
41
|
|
|
27
|
-
type
|
|
42
|
+
export type GetCSSVariable = {
|
|
28
43
|
(name: string): string | number | undefined
|
|
29
44
|
<const T extends Array<string>>(
|
|
30
45
|
names: T,
|
|
@@ -36,9 +51,9 @@ type UseCSSVariable = {
|
|
|
36
51
|
* @param name Name / Array of names of the CSS variable.
|
|
37
52
|
* @returns Value / Values of the CSS variable. On web it is always a string (1rem, #ff0000, etc.), but on native it can be a string or a number (16px, #ff0000)
|
|
38
53
|
*/
|
|
39
|
-
export const useCSSVariable:
|
|
54
|
+
export const useCSSVariable: GetCSSVariable = (name: string | Array<string>) => {
|
|
40
55
|
const uniwindContext = useUniwindContext()
|
|
41
|
-
const [value, setValue] = useState(
|
|
56
|
+
const [value, setValue] = useState(getCSSVariable(name, uniwindContext))
|
|
42
57
|
const nameRef = useRef(name)
|
|
43
58
|
|
|
44
59
|
useLayoutEffect(() => {
|
|
@@ -47,20 +62,20 @@ export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) =>
|
|
|
47
62
|
return
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
setValue(
|
|
65
|
+
setValue(getCSSVariable(name, uniwindContext))
|
|
51
66
|
nameRef.current = name
|
|
52
67
|
|
|
53
68
|
return
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
if (name !== nameRef.current) {
|
|
57
|
-
setValue(
|
|
72
|
+
setValue(getCSSVariable(name, uniwindContext))
|
|
58
73
|
nameRef.current = name
|
|
59
74
|
}
|
|
60
75
|
}, [name])
|
|
61
76
|
|
|
62
77
|
useLayoutEffect(() => {
|
|
63
|
-
const updateValue = () => setValue(
|
|
78
|
+
const updateValue = () => setValue(getCSSVariable(nameRef.current, uniwindContext))
|
|
64
79
|
const dispose = UniwindListener.subscribe(
|
|
65
80
|
updateValue,
|
|
66
81
|
[StyleDependency.Theme, StyleDependency.Variables],
|
|
@@ -69,17 +84,5 @@ export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) =>
|
|
|
69
84
|
return dispose
|
|
70
85
|
}, [uniwindContext])
|
|
71
86
|
|
|
72
|
-
if (Array.isArray(value)) {
|
|
73
|
-
value.forEach((val, index) => {
|
|
74
|
-
if (val === undefined && __DEV__ && !warned) {
|
|
75
|
-
logDevError(name[index] ?? '')
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (value === undefined && __DEV__ && !warned) {
|
|
81
|
-
logDevError(name as string)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
87
|
return value as never
|
|
85
88
|
}
|
|
@@ -231,6 +231,7 @@ const cssToRNMap: Record<string, (value: any) => Record<string, any>> = {
|
|
|
231
231
|
|
|
232
232
|
const BORDER_WIDTH_KEYS = ['borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth']
|
|
233
233
|
const BORDER_COLOR_KEYS = ['borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor']
|
|
234
|
+
const BORDER_RADIUS_KEYS = ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius']
|
|
234
235
|
|
|
235
236
|
export class RN {
|
|
236
237
|
constructor(private readonly Processor: ProcessorBuilder) {}
|
|
@@ -249,6 +250,12 @@ export class RN {
|
|
|
249
250
|
.replace('Block', 'Vertical')
|
|
250
251
|
}
|
|
251
252
|
|
|
253
|
+
if (x.includes('border')) {
|
|
254
|
+
return x
|
|
255
|
+
.replace('InlineStart', 'Start')
|
|
256
|
+
.replace('InlineEnd', 'End')
|
|
257
|
+
}
|
|
258
|
+
|
|
252
259
|
return x
|
|
253
260
|
},
|
|
254
261
|
)
|
|
@@ -382,6 +389,18 @@ export class RN {
|
|
|
382
389
|
}
|
|
383
390
|
}
|
|
384
391
|
|
|
392
|
+
if (BORDER_RADIUS_KEYS.every(key => keys.includes(key))) {
|
|
393
|
+
const borderRadius = styles.borderTopLeftRadius
|
|
394
|
+
|
|
395
|
+
// Join border radius
|
|
396
|
+
if (BORDER_RADIUS_KEYS.every(key => styles[key] === borderRadius)) {
|
|
397
|
+
return {
|
|
398
|
+
...removeKeys(styles, BORDER_RADIUS_KEYS),
|
|
399
|
+
borderRadius,
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
385
404
|
return styles
|
|
386
405
|
}
|
|
387
406
|
}
|