react-native-unistyles 2.0.0-alpha.4 → 2.0.0-alpha.6
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.cpp +262 -0
- package/cxx/UnistylesRuntime.h +61 -0
- package/ios/UnistylesModule.mm +8 -3
- package/lib/commonjs/Unistyles.js +1 -1
- package/lib/commonjs/Unistyles.js.map +1 -1
- package/lib/commonjs/UnistylesEngine.js +9 -5
- package/lib/commonjs/UnistylesEngine.js.map +1 -1
- package/lib/commonjs/createStyleSheet.js.map +1 -1
- package/lib/commonjs/types/cxx.js +1 -2
- package/lib/commonjs/types/cxx.js.map +1 -1
- package/lib/commonjs/useStyles.js +0 -2
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/useUnistyles.js +9 -15
- package/lib/commonjs/useUnistyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js +23 -70
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/common.js +8 -1
- package/lib/commonjs/utils/common.js.map +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mediaQueries.js +58 -149
- package/lib/commonjs/utils/mediaQueries.js.map +1 -1
- package/lib/commonjs/utils/styles.js +11 -51
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/Unistyles.js +2 -2
- package/lib/module/Unistyles.js.map +1 -1
- package/lib/module/UnistylesEngine.js +7 -3
- package/lib/module/UnistylesEngine.js.map +1 -1
- package/lib/module/createStyleSheet.js.map +1 -1
- package/lib/module/types/cxx.js +1 -2
- package/lib/module/types/cxx.js.map +1 -1
- package/lib/module/useStyles.js +0 -3
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/useUnistyles.js +9 -15
- package/lib/module/useUnistyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js +24 -71
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/common.js +7 -0
- package/lib/module/utils/common.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mediaQueries.js +58 -149
- package/lib/module/utils/mediaQueries.js.map +1 -1
- package/lib/module/utils/styles.js +10 -51
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/src/Unistyles.d.ts +2 -2
- package/lib/typescript/src/Unistyles.d.ts.map +1 -1
- package/lib/typescript/src/UnistylesEngine.d.ts +4 -1
- package/lib/typescript/src/UnistylesEngine.d.ts.map +1 -1
- package/lib/typescript/src/UnistylesRuntime.d.ts +2 -2
- package/lib/typescript/src/UnistylesRuntime.d.ts.map +1 -1
- package/lib/typescript/src/createStyleSheet.d.ts +2 -5
- package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
- package/lib/typescript/src/global.d.ts +2 -1
- package/lib/typescript/src/global.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +2 -1
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +18 -16
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/cxx.d.ts +15 -14
- package/lib/typescript/src/types/cxx.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +1 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +5 -3
- package/lib/typescript/src/types/mediaQueries.d.ts.map +1 -1
- package/lib/typescript/src/useStyles.d.ts +2 -4
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/useUnistyles.d.ts +3 -1
- package/lib/typescript/src/useUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts +2 -60
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/common.d.ts +7 -0
- package/lib/typescript/src/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +8 -127
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts +1 -46
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +10 -1
- package/src/Unistyles.ts +3 -3
- package/src/UnistylesEngine.ts +12 -3
- package/src/createStyleSheet.ts +2 -5
- package/src/global.ts +2 -1
- package/src/types/breakpoints.ts +6 -3
- package/src/types/core.ts +25 -22
- package/src/types/cxx.ts +17 -16
- package/src/types/index.ts +1 -1
- package/src/types/mediaQueries.ts +9 -4
- package/src/useStyles.ts +5 -8
- package/src/useUnistyles.ts +12 -24
- package/src/utils/breakpoints.ts +31 -74
- package/src/utils/common.ts +8 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/mediaQueries.ts +105 -154
- package/src/utils/styles.ts +13 -55
@@ -1,80 +1,110 @@
|
|
1
|
+
import type { UnistylesBreakpoints } from 'react-native-unistyles'
|
1
2
|
import type { ScreenSize } from '../types'
|
3
|
+
import type { MediaQueries } from '../types'
|
4
|
+
|
5
|
+
const parseLhs = (lhs: string, breakpoints: UnistylesBreakpoints, hasRhs: boolean) => {
|
6
|
+
const matches = lhs.match(/([([])|([^[\]()]+)|([\])])/g)
|
7
|
+
|
8
|
+
if (!hasRhs) {
|
9
|
+
const [openBracket, value, closeBracket] = matches as [string, string, string]
|
10
|
+
const spacelessValue = value?.trim()
|
11
|
+
const parsedNumber = Number(spacelessValue)
|
12
|
+
|
13
|
+
const parsedValue = isNaN(parsedNumber)
|
14
|
+
? breakpoints[spacelessValue as keyof UnistylesBreakpoints] as number
|
15
|
+
: parsedNumber
|
16
|
+
|
17
|
+
return [
|
18
|
+
Number(openBracket === '('),
|
19
|
+
closeBracket === ')'
|
20
|
+
? parsedValue - 1
|
21
|
+
: parsedValue
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
const [openBracket, value] = matches as [string, string]
|
26
|
+
|
27
|
+
if (!value) {
|
28
|
+
return [Number(openBracket === '(')]
|
29
|
+
}
|
30
|
+
|
31
|
+
const spacelessValue = value?.trim()
|
32
|
+
const parsedNumber = Number(spacelessValue)
|
33
|
+
|
34
|
+
const parsedValue = isNaN(parsedNumber)
|
35
|
+
? breakpoints[spacelessValue as keyof UnistylesBreakpoints] as number
|
36
|
+
: parsedNumber
|
37
|
+
|
38
|
+
return openBracket === '('
|
39
|
+
? [parsedValue - 1]
|
40
|
+
: [parsedValue]
|
41
|
+
}
|
42
|
+
|
43
|
+
const parseRhs = (rhs: string, breakpoints: UnistylesBreakpoints) => {
|
44
|
+
const matches = rhs.match(/([([])|([^[\]()]+)|([\])])/g)
|
45
|
+
const [value, closeBrackets] = matches as [string, string]
|
46
|
+
const spacelessValue = value.trim()
|
47
|
+
const parsedNumber = Number(spacelessValue)
|
48
|
+
|
49
|
+
const parsedValue = isNaN(parsedNumber)
|
50
|
+
? breakpoints[spacelessValue as keyof UnistylesBreakpoints] as number
|
51
|
+
: parsedNumber
|
52
|
+
|
53
|
+
return [
|
54
|
+
closeBrackets === ')'
|
55
|
+
? parsedValue - 1
|
56
|
+
: parsedValue
|
57
|
+
]
|
58
|
+
}
|
2
59
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
60
|
+
export const extractValues = (pattern: string, breakpoints: UnistylesBreakpoints): Array<number> => {
|
61
|
+
const [lhs, rhs] = pattern
|
62
|
+
.replace(/(:w|:h)/g, '')
|
63
|
+
.split(',') as [string, string | undefined]
|
64
|
+
|
65
|
+
if (!rhs) {
|
66
|
+
return parseLhs(lhs, breakpoints, false)
|
67
|
+
}
|
68
|
+
|
69
|
+
const [parsedLhs] = parseLhs(lhs, breakpoints, true)
|
70
|
+
|
71
|
+
if (parsedLhs === undefined || isNaN(parsedLhs)) {
|
72
|
+
return []
|
73
|
+
}
|
74
|
+
|
75
|
+
const [parsedRhs] = parseRhs(rhs, breakpoints)
|
76
|
+
|
77
|
+
if (parsedRhs === undefined || isNaN(parsedRhs)) {
|
78
|
+
return []
|
79
|
+
}
|
80
|
+
|
81
|
+
return [
|
82
|
+
parsedLhs,
|
83
|
+
parsedRhs
|
84
|
+
]
|
26
85
|
}
|
27
86
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
*
|
35
|
-
* @param {string} query - The breakpoint query string. Examples: 'w[100,200]', 'h[300]', 'w[100,200]h[300,400]'.
|
36
|
-
* @param {ScreenSize} screenSize - The screen size to check against the breakpoint query.
|
37
|
-
* @returns {boolean} True if the screen size matches the breakpoint query, false otherwise.
|
38
|
-
*
|
39
|
-
* @example
|
40
|
-
* const screenSize = { width: 150, height: 350 }
|
41
|
-
* isWithinBreakpoint('w[100,200]', screenSize) // returns true
|
42
|
-
* isWithinBreakpoint('h[400]', screenSize) // returns false
|
43
|
-
*/
|
44
|
-
export const isWithinBreakpoint = (query: string, screenSize: ScreenSize): boolean => {
|
45
|
-
if (query.includes('w') && query.includes('h')) {
|
46
|
-
return isWithinTheWidthAndHeight(query, screenSize)
|
87
|
+
export const isWithinBreakpoint = (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints): boolean => {
|
88
|
+
const hasWidthBreakpoint = query.includes(':w')
|
89
|
+
const hasHeightBreakpoint = query.includes(':h')
|
90
|
+
|
91
|
+
if (hasWidthBreakpoint && hasHeightBreakpoint) {
|
92
|
+
return isWithinTheWidthAndHeight(query, screenSize, breakpoints)
|
47
93
|
}
|
48
94
|
|
49
|
-
if (
|
50
|
-
return isWithinTheWidth(query, screenSize.width)
|
95
|
+
if (hasWidthBreakpoint) {
|
96
|
+
return isWithinTheWidth(query, screenSize.width, breakpoints)
|
51
97
|
}
|
52
98
|
|
53
|
-
if (
|
54
|
-
return isWithinTheHeight(query, screenSize.height)
|
99
|
+
if (hasHeightBreakpoint) {
|
100
|
+
return isWithinTheHeight(query, screenSize.height, breakpoints)
|
55
101
|
}
|
56
102
|
|
57
103
|
return false
|
58
104
|
}
|
59
105
|
|
60
|
-
|
61
|
-
|
62
|
-
*
|
63
|
-
* The function checks if the provided width falls within the range specified by the query.
|
64
|
-
* The query specifies a width range using a format like 'w[100,200]'. If only one value is provided,
|
65
|
-
* it's treated as a minimum width.
|
66
|
-
*
|
67
|
-
* @param {string} query - The width query string. Examples: 'w[100,200]' or 'w[100]'.
|
68
|
-
* @param {number} width - The width to check against the query.
|
69
|
-
* @returns {boolean} True if the width matches the query range, false otherwise.
|
70
|
-
*
|
71
|
-
* @example
|
72
|
-
* isWithinTheWidth('w[100,200]', 150) // returns true
|
73
|
-
* isWithinTheWidth('w[100]', 50) // returns false
|
74
|
-
* isWithinTheWidth('w[100]', 150) // returns true
|
75
|
-
*/
|
76
|
-
export const isWithinTheWidth = (query: string, width: number): boolean => {
|
77
|
-
const [minWidth, maxWidth] = extractValues(query) as [number, number | undefined]
|
106
|
+
export const isWithinTheWidth = (query: string, width: number, breakpoints: UnistylesBreakpoints): boolean => {
|
107
|
+
const [minWidth, maxWidth] = extractValues(query, breakpoints) as [number, number | undefined]
|
78
108
|
|
79
109
|
if (maxWidth && width >= minWidth && width <= maxWidth) {
|
80
110
|
return true
|
@@ -83,24 +113,8 @@ export const isWithinTheWidth = (query: string, width: number): boolean => {
|
|
83
113
|
return !maxWidth && width >= minWidth
|
84
114
|
}
|
85
115
|
|
86
|
-
|
87
|
-
|
88
|
-
*
|
89
|
-
* The function checks if the provided height falls within the range specified by the query.
|
90
|
-
* The query specifies a height range using a format like 'h[100,200]'. If only one value is provided,
|
91
|
-
* it's treated as a minimum height.
|
92
|
-
*
|
93
|
-
* @param {string} query - The height query string. Examples: 'h[100,200]' or 'h[100]'.
|
94
|
-
* @param {number} height - The height to check against the query.
|
95
|
-
* @returns {boolean} True if the height matches the query range, false otherwise.
|
96
|
-
*
|
97
|
-
* @example
|
98
|
-
* isWithinTheHeight('h[100,200]', 150) // returns true
|
99
|
-
* isWithinTheHeight('h[100]', 50) // returns false
|
100
|
-
* isWithinTheHeight('h[100]', 150) // returns true
|
101
|
-
*/
|
102
|
-
export const isWithinTheHeight = (query: string, height: number): boolean => {
|
103
|
-
const [minHeight, maxHeight] = extractValues(query) as [number, number | undefined]
|
116
|
+
export const isWithinTheHeight = (query: string, height: number, breakpoints: UnistylesBreakpoints): boolean => {
|
117
|
+
const [minHeight, maxHeight] = extractValues(query, breakpoints) as [number, number | undefined]
|
104
118
|
|
105
119
|
if (maxHeight && height >= minHeight && height <= maxHeight) {
|
106
120
|
return true
|
@@ -109,92 +123,29 @@ export const isWithinTheHeight = (query: string, height: number): boolean => {
|
|
109
123
|
return !maxHeight && height >= minHeight
|
110
124
|
}
|
111
125
|
|
112
|
-
|
113
|
-
* Determines if the given screen size matches both the specified width and height ranges in the query.
|
114
|
-
*
|
115
|
-
* The function checks if the provided screen size (both width and height) falls within the ranges
|
116
|
-
* specified by the query. The query can specify both width and height using a format like 'w[100,200]:h[300,400]'.
|
117
|
-
*
|
118
|
-
* @param {string} query - The combined width and height query string. Example: 'w[100,200]:h[300,400]'.
|
119
|
-
* @param {ScreenSize} screenSize - The screen size to check against the query.
|
120
|
-
* @returns {boolean} True if the screen size matches both the width and height ranges in the query, false otherwise.
|
121
|
-
*
|
122
|
-
* @example
|
123
|
-
* const screenSize = { width: 150, height: 350 }
|
124
|
-
* isWithinTheWidthAndHeight('w[100,200]:h[300,400]', screenSize) // returns true
|
125
|
-
* isWithinTheWidthAndHeight('w[100,200]:h[400,500]', screenSize) // returns false
|
126
|
-
*/
|
127
|
-
export const isWithinTheWidthAndHeight = (query: string, screenSize: ScreenSize): boolean => {
|
126
|
+
export const isWithinTheWidthAndHeight = (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints): boolean => {
|
128
127
|
const result = query
|
129
128
|
.split(':')
|
130
129
|
.filter(Boolean)
|
131
|
-
.map(q => isWithinBreakpoint(q,
|
130
|
+
.map(q => isWithinBreakpoint(`:${q}`, screenSize, breakpoints))
|
132
131
|
.filter(Boolean)
|
133
132
|
|
134
133
|
return result.length === 2
|
135
134
|
}
|
136
135
|
|
137
|
-
/**
|
138
|
-
* Checks if the given query string is a valid custom media query.
|
139
|
-
*
|
140
|
-
* The valid custom media query formats include:
|
141
|
-
* - :w[200]
|
142
|
-
* - :w[0, 200]
|
143
|
-
* - :w[, 300]
|
144
|
-
* - :h[200]
|
145
|
-
* - :h[0, 500]
|
146
|
-
* - :h[,200]
|
147
|
-
* - :w[100, 300]:h[200,500]
|
148
|
-
* - :h[200,500]:w[100, 300]
|
149
|
-
*
|
150
|
-
* @param {string} query - The query string to be checked.
|
151
|
-
* @returns {boolean} Returns `true` if the query is a valid custom media query, otherwise `false`.
|
152
|
-
* @example
|
153
|
-
*
|
154
|
-
* isMediaQuery(':w[200]') // true
|
155
|
-
* isMediaQuery(':w100]') // false
|
156
|
-
*/
|
157
136
|
export const isMediaQuery = (query: string): boolean => {
|
158
|
-
const regex =
|
137
|
+
const regex = /(:w|:h)/
|
159
138
|
|
160
139
|
return query.length > 0 && regex.test(query)
|
161
140
|
}
|
162
141
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
* - w[200]
|
169
|
-
* - w[0, 200]
|
170
|
-
* - w[, 300]
|
171
|
-
* - h[200]
|
172
|
-
* - h[0, 500]
|
173
|
-
* - h[,200]
|
174
|
-
* - w[100, 300]:h[200,500]
|
175
|
-
* - h[200,500]:w[100, 300]
|
176
|
-
*
|
177
|
-
* @param {Array<[string, string | number]>} mediaQueries - An array of tuples containing media query keys and associated values.
|
178
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
179
|
-
* @returns {string | undefined} Returns the first matching media query key or `undefined` if no match is found.
|
180
|
-
* @example
|
181
|
-
*
|
182
|
-
* const queries = [[':w[200]', 'value1'], [':h[300,500]', 'value2']]
|
183
|
-
* const size = { width: 250, height: 400 }
|
184
|
-
* getKeyForCustomMediaQuery(queries, size) // ':w[200]
|
185
|
-
*/
|
186
|
-
export const getKeyForCustomMediaQuery = (mediaQueries: Array<[string, string | number | undefined]>, screenSize: ScreenSize): string | undefined => {
|
142
|
+
export const getKeyForCustomMediaQuery = (
|
143
|
+
mediaQueries: Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>,
|
144
|
+
screenSize: ScreenSize,
|
145
|
+
breakpoints: UnistylesBreakpoints
|
146
|
+
): string | undefined => {
|
187
147
|
const [matchedQuery] = mediaQueries
|
188
|
-
.flatMap(([key]) =>
|
189
|
-
if (key.includes('w') && key.includes('h')) {
|
190
|
-
return isWithinBreakpoint(key, screenSize) ? key : undefined
|
191
|
-
}
|
192
|
-
|
193
|
-
return key
|
194
|
-
.split(':')
|
195
|
-
.filter(Boolean)
|
196
|
-
.map(query => isWithinBreakpoint(query, screenSize) ? key : undefined)
|
197
|
-
})
|
148
|
+
.flatMap(([key]) => isWithinBreakpoint(key, screenSize, breakpoints) ? key : undefined)
|
198
149
|
.filter(Boolean)
|
199
150
|
|
200
151
|
return matchedQuery
|
package/src/utils/styles.ts
CHANGED
@@ -1,30 +1,9 @@
|
|
1
|
-
import type { CustomNamedStyles, ScreenSize } from '../types'
|
1
|
+
import type { CustomNamedStyles, MediaQueries, ScreenSize } from '../types'
|
2
2
|
import { getValueForBreakpoint } from './breakpoints'
|
3
3
|
import { normalizeStyles } from './normalizeStyles'
|
4
|
-
import { isWeb } from './common'
|
5
4
|
import type { UnistylesBreakpoints } from '../global'
|
5
|
+
import { isAndroid, isIOS, isWeb } from './common'
|
6
6
|
|
7
|
-
/**
|
8
|
-
* Proxies a function to parse its return value for custom media queries or breakpoints.
|
9
|
-
*
|
10
|
-
* @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
|
11
|
-
*
|
12
|
-
* @param {Function} fn - The function to be proxified.
|
13
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
14
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
15
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
16
|
-
*
|
17
|
-
* @returns {Function} Returns the proxified function
|
18
|
-
*
|
19
|
-
* @example
|
20
|
-
*
|
21
|
-
* const myFunction = () => ({ ':w[200]': 'value1', sm: 'value2' })
|
22
|
-
* const screenSize = { width: 250, height: 400 }
|
23
|
-
* const breakpoints = { sm: 300, md: 600 }
|
24
|
-
*
|
25
|
-
* const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
|
26
|
-
* proxifiedFunction() // parsed style based on screenSize and breakpoints
|
27
|
-
*/
|
28
7
|
export const proxifyFunction = (
|
29
8
|
fn: Function, breakpoint: keyof UnistylesBreakpoints & string,
|
30
9
|
screenSize: ScreenSize
|
@@ -33,37 +12,20 @@ export const proxifyFunction = (
|
|
33
12
|
parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize)
|
34
13
|
})
|
35
14
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
*
|
45
|
-
* @param {CustomNamedStyles<T, B>} style - The style object to be parsed.
|
46
|
-
* @param {keyof B & string} breakpoint - The breakpoint name to check against.
|
47
|
-
* @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
|
48
|
-
* @param breakpointPairs - sorted pairs of breakpoints
|
49
|
-
*
|
50
|
-
* @returns {Record<string, string | number | Function>} Returns the parsed style object with resolved custom media queries or breakpoints.
|
51
|
-
*
|
52
|
-
* @example
|
53
|
-
*
|
54
|
-
* const style = { fontSize: { sm: '12px', md: '16px' } }
|
55
|
-
* const screenSize = { width: 300, height: 400 }
|
56
|
-
* const breakpoints = { xs: 0, sm: 300, md: 600 }
|
57
|
-
*
|
58
|
-
* const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
|
59
|
-
* // { fontSize: '12px' }
|
60
|
-
*/
|
15
|
+
export const isPlatformColor = <T extends {}>(value: T): boolean => {
|
16
|
+
if (isIOS) {
|
17
|
+
return 'semantic' in value && typeof value.semantic === 'object'
|
18
|
+
}
|
19
|
+
|
20
|
+
return isAndroid && 'resource_paths' in value && typeof value.resource_paths === 'object'
|
21
|
+
}
|
22
|
+
|
61
23
|
export const parseStyle = <T>(
|
62
24
|
style: CustomNamedStyles<T>,
|
63
25
|
breakpoint: keyof UnistylesBreakpoints & string,
|
64
26
|
screenSize: ScreenSize
|
65
27
|
): T => {
|
66
|
-
const entries = Object.entries(style) as [[
|
28
|
+
const entries = Object.entries(style || {}) as [[
|
67
29
|
keyof T,
|
68
30
|
CustomNamedStyles<T> | Record<keyof UnistylesBreakpoints & string, string | number | undefined>]
|
69
31
|
]
|
@@ -90,7 +52,7 @@ export const parseStyle = <T>(
|
|
90
52
|
}
|
91
53
|
|
92
54
|
const isDynamicFunction = typeof value === 'function'
|
93
|
-
const isValidStyle = typeof value !== 'object'
|
55
|
+
const isValidStyle = typeof value !== 'object' || isPlatformColor(value)
|
94
56
|
|
95
57
|
if (isDynamicFunction || isValidStyle) {
|
96
58
|
return [key, value]
|
@@ -98,11 +60,7 @@ export const parseStyle = <T>(
|
|
98
60
|
|
99
61
|
return [
|
100
62
|
key,
|
101
|
-
getValueForBreakpoint(
|
102
|
-
value as Record<keyof UnistylesBreakpoints & string, string | number | undefined>,
|
103
|
-
breakpoint,
|
104
|
-
screenSize
|
105
|
-
)
|
63
|
+
getValueForBreakpoint(value as Record<keyof UnistylesBreakpoints | MediaQueries, string | number | undefined>)
|
106
64
|
]
|
107
65
|
})
|
108
66
|
)
|