react-native-unistyles 2.0.0-alpha.7 → 2.0.0-alpha.9
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.cpp +24 -31
- package/cxx/UnistylesRuntime.h +11 -12
- package/ios/UnistylesModule.mm +20 -20
- package/lib/commonjs/{types/cxx.js → common.js} +6 -6
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/{UnistyleRegistry.js → core/UnistyleRegistry.js} +1 -8
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/{Unistyles.js → core/Unistyles.js} +2 -7
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/{UnistylesRuntime.js → core/UnistylesRuntime.js} +6 -6
- 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/hooks/index.js +10 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/{useInitialTheme.js → hooks/useInitialTheme.js} +6 -2
- 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 +10 -16
- 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 +4 -4
- 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 +7 -4
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js +18 -20
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/index.js +10 -38
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +67 -53
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/mqParser.js +86 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/{types/cxx.js → common.js} +8 -6
- package/lib/module/common.js.map +1 -0
- package/lib/module/{UnistyleRegistry.js → core/UnistyleRegistry.js} +1 -8
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/{Unistyles.js → core/Unistyles.js} +1 -6
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/{UnistylesRuntime.js → core/UnistylesRuntime.js} +2 -2
- 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/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 +11 -18
- 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 -1
- 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 +6 -3
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js +14 -16
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/index.js +2 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +65 -51
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/mqParser.js +79 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/src/common.d.ts +17 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/{UnistyleRegistry.d.ts → core/UnistyleRegistry.d.ts} +2 -3
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/{Unistyles.d.ts → core/Unistyles.d.ts} +0 -3
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/{UnistylesRuntime.d.ts → core/UnistylesRuntime.d.ts} +6 -6
- 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/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 +10 -12
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +5 -9
- 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 +9 -4
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +5 -4
- 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/{cxx.d.ts → unistyles.d.ts} +4 -23
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +8 -6
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +2 -2
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +15 -9
- package/lib/typescript/src/utils/mq.d.ts.map +1 -1
- 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.map +1 -1
- package/package.json +1 -1
- package/src/common.ts +19 -0
- package/src/{UnistyleRegistry.ts → core/UnistyleRegistry.ts} +3 -12
- package/src/{Unistyles.ts → core/Unistyles.ts} +2 -9
- package/src/{UnistylesRuntime.ts → core/UnistylesRuntime.ts} +4 -4
- package/src/core/index.ts +1 -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 +17 -20
- package/src/types/breakpoints.ts +6 -11
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +10 -4
- package/src/types/index.ts +5 -9
- package/src/types/mq.ts +3 -0
- package/src/types/{cxx.ts → unistyles.ts} +4 -28
- package/src/useStyles.ts +15 -8
- package/src/utils/breakpoints.ts +13 -12
- package/src/utils/index.ts +2 -9
- package/src/utils/mq.ts +75 -46
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/styles.ts +2 -2
- package/lib/commonjs/UnistyleRegistry.js.map +0 -1
- package/lib/commonjs/Unistyles.js.map +0 -1
- package/lib/commonjs/UnistylesEngine.js +0 -26
- package/lib/commonjs/UnistylesEngine.js.map +0 -1
- package/lib/commonjs/UnistylesModule.js.map +0 -1
- package/lib/commonjs/UnistylesRuntime.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/cxx.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/useInitialTheme.js.map +0 -1
- package/lib/commonjs/useUnistyles.js +0 -51
- package/lib/commonjs/useUnistyles.js.map +0 -1
- package/lib/commonjs/utils/mediaQueries.js +0 -98
- package/lib/commonjs/utils/mediaQueries.js.map +0 -1
- package/lib/module/UnistyleRegistry.js.map +0 -1
- package/lib/module/Unistyles.js.map +0 -1
- package/lib/module/UnistylesEngine.js +0 -19
- package/lib/module/UnistylesEngine.js.map +0 -1
- package/lib/module/UnistylesModule.js.map +0 -1
- package/lib/module/UnistylesRuntime.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/cxx.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/useInitialTheme.js +0 -6
- package/lib/module/useInitialTheme.js.map +0 -1
- package/lib/module/useUnistyles.js +0 -44
- package/lib/module/useUnistyles.js.map +0 -1
- package/lib/module/utils/mediaQueries.js +0 -85
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/typescript/src/UnistyleRegistry.d.ts.map +0 -1
- package/lib/typescript/src/Unistyles.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesEngine.d.ts +0 -11
- package/lib/typescript/src/UnistylesEngine.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesModule.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesRuntime.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/cxx.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -10
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/useInitialTheme.d.ts +0 -3
- package/lib/typescript/src/useInitialTheme.d.ts.map +0 -1
- package/lib/typescript/src/useUnistyles.d.ts +0 -10
- package/lib/typescript/src/useUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -11
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
- package/src/UnistylesEngine.ts +0 -24
- package/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -34
- package/src/types/mediaQueries.ts +0 -15
- package/src/useInitialTheme.ts +0 -7
- package/src/useUnistyles.ts +0 -61
- package/src/utils/mediaQueries.ts +0 -152
- /package/lib/commonjs/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
- /package/lib/module/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
- /package/lib/typescript/src/{UnistylesModule.d.ts → core/UnistylesModule.d.ts} +0 -0
- /package/src/{UnistylesModule.ts → core/UnistylesModule.ts} +0 -0
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useInitialTheme.d.ts","sourceRoot":"","sources":["../../../src/useInitialTheme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,eAAO,MAAM,eAAe,YAAa,MAAM,eAAe,SAE7D,CAAA"}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { ScreenSize } from './types';
|
2
|
-
import { ScreenOrientation } from './types';
|
3
|
-
import type { UnistylesBreakpoints } from './global';
|
4
|
-
export declare const useUnistyles: () => {
|
5
|
-
theme: never;
|
6
|
-
orientation: ScreenOrientation;
|
7
|
-
breakpoint: keyof UnistylesBreakpoints;
|
8
|
-
screenSize: ScreenSize;
|
9
|
-
};
|
10
|
-
//# sourceMappingURL=useUnistyles.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useUnistyles.d.ts","sourceRoot":"","sources":["../../../src/useUnistyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIR,UAAU,EAEb,MAAM,SAAS,CAAA;AAChB,OAAO,EAA0B,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAIpD,eAAO,MAAM,YAAY;;;;;CA6CxB,CAAA"}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { UnistylesBreakpoints } from 'react-native-unistyles';
|
2
|
-
import type { ScreenSize } from '../types';
|
3
|
-
import type { MediaQueries } from '../types';
|
4
|
-
export declare const extractValues: (pattern: string, breakpoints: UnistylesBreakpoints) => Array<number>;
|
5
|
-
export declare const isWithinBreakpoint: (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints) => boolean;
|
6
|
-
export declare const isWithinTheWidth: (query: string, width: number, breakpoints: UnistylesBreakpoints) => boolean;
|
7
|
-
export declare const isWithinTheHeight: (query: string, height: number, breakpoints: UnistylesBreakpoints) => boolean;
|
8
|
-
export declare const isWithinTheWidthAndHeight: (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints) => boolean;
|
9
|
-
export declare const isMediaQuery: (query: string) => boolean;
|
10
|
-
export declare const getKeyForCustomMediaQuery: (mediaQueries: Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints) => string | undefined;
|
11
|
-
//# sourceMappingURL=mediaQueries.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"mediaQueries.d.ts","sourceRoot":"","sources":["../../../../src/utils/mediaQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAyD5C,eAAO,MAAM,aAAa,YAAa,MAAM,eAAe,oBAAoB,KAAG,MAAM,MAAM,CAyB9F,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAW,MAAM,cAAc,UAAU,eAAe,oBAAoB,KAAG,OAiB7G,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAW,MAAM,SAAS,MAAM,eAAe,oBAAoB,KAAG,OAQlG,CAAA;AAED,eAAO,MAAM,iBAAiB,UAAW,MAAM,UAAU,MAAM,eAAe,oBAAoB,KAAG,OAQpG,CAAA;AAED,eAAO,MAAM,yBAAyB,UAAW,MAAM,cAAc,UAAU,eAAe,oBAAoB,KAAG,OAQpH,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,OAI5C,CAAA;AAED,eAAO,MAAM,yBAAyB,iBACpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,cACjF,UAAU,eACT,oBAAoB,KAClC,MAAM,GAAG,SAMX,CAAA"}
|
package/src/UnistylesEngine.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import type { UnistyleRegistry } from './UnistyleRegistry'
|
2
|
-
import type { UnistylesRuntime } from './UnistylesRuntime'
|
3
|
-
import { getKeyForCustomMediaQuery } from './utils'
|
4
|
-
import type { UnistylesEngine, NestedKeys } from './types'
|
5
|
-
|
6
|
-
export class UnistylesBuiltInEngine implements UnistylesEngine {
|
7
|
-
constructor(private registry: UnistyleRegistry, private runtime: UnistylesRuntime) {
|
8
|
-
this.registry = registry
|
9
|
-
this.runtime = runtime
|
10
|
-
}
|
11
|
-
|
12
|
-
public isMediaQuery = (key: string) => {
|
13
|
-
const regex = /(:w|:h)/
|
14
|
-
|
15
|
-
return key.length > 0 && regex.test(key)
|
16
|
-
}
|
17
|
-
|
18
|
-
public didMatchMediaQuery = (keys: NestedKeys) =>
|
19
|
-
getKeyForCustomMediaQuery(keys, this.runtime.screen, this.registry.breakpoints)
|
20
|
-
|
21
|
-
// UnistylesEngine.parseStyleSheet
|
22
|
-
// UnistylesEngine.parseStyle
|
23
|
-
// UnistylesEngine.proxify
|
24
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
2
|
-
import type { ScreenSize } from '../types'
|
3
|
-
|
4
|
-
export const useDimensions = (): ScreenSize => {
|
5
|
-
const timerRef = useRef<ReturnType<typeof setTimeout>>()
|
6
|
-
const [screenSize, setScreenSize] = useState<ScreenSize>({} as ScreenSize)
|
7
|
-
|
8
|
-
useLayoutEffect(() => {
|
9
|
-
setScreenSize({
|
10
|
-
width: window.innerWidth,
|
11
|
-
height: window.innerHeight
|
12
|
-
})
|
13
|
-
}, [])
|
14
|
-
|
15
|
-
useEffect(() => {
|
16
|
-
const handleResize = () => {
|
17
|
-
clearTimeout(timerRef.current)
|
18
|
-
|
19
|
-
timerRef.current = setTimeout(() => setScreenSize({
|
20
|
-
width: window.innerWidth,
|
21
|
-
height: window.innerHeight
|
22
|
-
}), 100)
|
23
|
-
}
|
24
|
-
|
25
|
-
window.addEventListener('resize', handleResize)
|
26
|
-
|
27
|
-
return () => {
|
28
|
-
window.removeEventListener('resize', handleResize)
|
29
|
-
clearTimeout(timerRef.current)
|
30
|
-
}
|
31
|
-
}, [])
|
32
|
-
|
33
|
-
return screenSize
|
34
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
type Optional<TOptional extends string> = TOptional | ''
|
2
|
-
type Separator = ',' | ', '
|
3
|
-
type OpeningBracket = '(' | '['
|
4
|
-
type ClosingBracket = ')' | ']'
|
5
|
-
|
6
|
-
type NumericMediaQuery =
|
7
|
-
| `${OpeningBracket}${Separator}${bigint}${ClosingBracket}`
|
8
|
-
| `${OpeningBracket}${bigint}${Optional<`${Separator}${bigint}`>}${ClosingBracket}`
|
9
|
-
|
10
|
-
type WidthMediaQuery = `:w${NumericMediaQuery}`
|
11
|
-
type HeightMediaQuery = `:h${NumericMediaQuery}`
|
12
|
-
|
13
|
-
export type MediaQueries =
|
14
|
-
| `${WidthMediaQuery}${Optional<HeightMediaQuery>}`
|
15
|
-
| `${HeightMediaQuery}${Optional<WidthMediaQuery>}`
|
package/src/useInitialTheme.ts
DELETED
package/src/useUnistyles.ts
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
import { NativeEventEmitter, NativeModules } from 'react-native'
|
2
|
-
import { useEffect, useState } from 'react'
|
3
|
-
import type {
|
4
|
-
UnistylesThemeEvent,
|
5
|
-
UnistylesMobileLayoutEvent,
|
6
|
-
UnistylesEvents,
|
7
|
-
ScreenSize,
|
8
|
-
UnistylesTheme
|
9
|
-
} from './types'
|
10
|
-
import { CxxUnistylesEventTypes, ScreenOrientation } from './types'
|
11
|
-
import { unistyles } from './Unistyles'
|
12
|
-
import type { UnistylesBreakpoints } from './global'
|
13
|
-
|
14
|
-
const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
|
15
|
-
|
16
|
-
export const useUnistyles = () => {
|
17
|
-
const [orientation, setOrientation] = useState<ScreenOrientation>(unistyles.runtime.orientation)
|
18
|
-
const [theme, setTheme] = useState<UnistylesTheme>(unistyles.runtime.getTheme(unistyles.runtime.themeName))
|
19
|
-
const [breakpoint, setBreakpoint] = useState<keyof UnistylesBreakpoints>(unistyles.runtime.breakpoint)
|
20
|
-
const [screenSize, setScreenSize] = useState<ScreenSize>({
|
21
|
-
width: unistyles.runtime.screen.width,
|
22
|
-
height: unistyles.runtime.screen.height
|
23
|
-
})
|
24
|
-
|
25
|
-
useEffect(() => {
|
26
|
-
const subscription = unistylesEvents.addListener(
|
27
|
-
'onChange',
|
28
|
-
(event: UnistylesEvents) => {
|
29
|
-
switch (event.type) {
|
30
|
-
case CxxUnistylesEventTypes.Theme: {
|
31
|
-
const themeEvent = event as UnistylesThemeEvent
|
32
|
-
|
33
|
-
setTheme(unistyles.runtime.getTheme(themeEvent.payload.themeName))
|
34
|
-
|
35
|
-
return
|
36
|
-
}
|
37
|
-
case CxxUnistylesEventTypes.Layout: {
|
38
|
-
const layoutEvent = event as UnistylesMobileLayoutEvent
|
39
|
-
|
40
|
-
setBreakpoint(layoutEvent.payload.breakpoint)
|
41
|
-
setOrientation(layoutEvent.payload.orientation)
|
42
|
-
setScreenSize(layoutEvent.payload.screen)
|
43
|
-
|
44
|
-
return
|
45
|
-
}
|
46
|
-
default:
|
47
|
-
return
|
48
|
-
}
|
49
|
-
}
|
50
|
-
)
|
51
|
-
|
52
|
-
return subscription.remove
|
53
|
-
}, [])
|
54
|
-
|
55
|
-
return {
|
56
|
-
theme,
|
57
|
-
orientation,
|
58
|
-
breakpoint,
|
59
|
-
screenSize
|
60
|
-
}
|
61
|
-
}
|
@@ -1,152 +0,0 @@
|
|
1
|
-
import type { UnistylesBreakpoints } from 'react-native-unistyles'
|
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
|
-
}
|
59
|
-
|
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
|
-
]
|
85
|
-
}
|
86
|
-
|
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)
|
93
|
-
}
|
94
|
-
|
95
|
-
if (hasWidthBreakpoint) {
|
96
|
-
return isWithinTheWidth(query, screenSize.width, breakpoints)
|
97
|
-
}
|
98
|
-
|
99
|
-
if (hasHeightBreakpoint) {
|
100
|
-
return isWithinTheHeight(query, screenSize.height, breakpoints)
|
101
|
-
}
|
102
|
-
|
103
|
-
return false
|
104
|
-
}
|
105
|
-
|
106
|
-
export const isWithinTheWidth = (query: string, width: number, breakpoints: UnistylesBreakpoints): boolean => {
|
107
|
-
const [minWidth, maxWidth] = extractValues(query, breakpoints) as [number, number | undefined]
|
108
|
-
|
109
|
-
if (maxWidth && width >= minWidth && width <= maxWidth) {
|
110
|
-
return true
|
111
|
-
}
|
112
|
-
|
113
|
-
return !maxWidth && width >= minWidth
|
114
|
-
}
|
115
|
-
|
116
|
-
export const isWithinTheHeight = (query: string, height: number, breakpoints: UnistylesBreakpoints): boolean => {
|
117
|
-
const [minHeight, maxHeight] = extractValues(query, breakpoints) as [number, number | undefined]
|
118
|
-
|
119
|
-
if (maxHeight && height >= minHeight && height <= maxHeight) {
|
120
|
-
return true
|
121
|
-
}
|
122
|
-
|
123
|
-
return !maxHeight && height >= minHeight
|
124
|
-
}
|
125
|
-
|
126
|
-
export const isWithinTheWidthAndHeight = (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints): boolean => {
|
127
|
-
const result = query
|
128
|
-
.split(':')
|
129
|
-
.filter(Boolean)
|
130
|
-
.map(q => isWithinBreakpoint(`:${q}`, screenSize, breakpoints))
|
131
|
-
.filter(Boolean)
|
132
|
-
|
133
|
-
return result.length === 2
|
134
|
-
}
|
135
|
-
|
136
|
-
export const isMediaQuery = (query: string): boolean => {
|
137
|
-
const regex = /(:w|:h)/
|
138
|
-
|
139
|
-
return query.length > 0 && regex.test(query)
|
140
|
-
}
|
141
|
-
|
142
|
-
export const getKeyForCustomMediaQuery = (
|
143
|
-
mediaQueries: Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>,
|
144
|
-
screenSize: ScreenSize,
|
145
|
-
breakpoints: UnistylesBreakpoints
|
146
|
-
): string | undefined => {
|
147
|
-
const [matchedQuery] = mediaQueries
|
148
|
-
.flatMap(([key]) => isWithinBreakpoint(key, screenSize, breakpoints) ? key : undefined)
|
149
|
-
.filter(Boolean)
|
150
|
-
|
151
|
-
return matchedQuery
|
152
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|