@codeandmoney/soelma 0.0.0-dev.0 → 0.0.0-dev.10
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/.eslintrc.js +1 -5
- package/biome.jsonc +73 -0
- package/example/AppStyleX/app.json +4 -16
- package/example/AppStyleX/babel.config.js +1 -1
- package/example/AppStyleX/index.js +3 -3
- package/example/AppStyleX/metro.config.js +1 -4
- package/example/AppStyleX/src/App.tsx +7 -10
- package/example/AppStyleX/src/BottomNav/index.tsx +9 -15
- package/example/AppStyleX/src/Circle/index.tsx +6 -6
- package/example/AppStyleX/src/Circle/styles.ts +4 -4
- package/example/AppStyleX/src/Root/index.tsx +12 -18
- package/example/AppStyleX/src/Root/styles.ts +5 -5
- package/example/AppStyleX/src/ToggleButton/index.tsx +10 -24
- package/example/AppStyleX/src/ToggleButton/styles.ts +13 -15
- package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +2 -2
- package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +2 -2
- package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +2 -2
- package/example/AppStyleX/src/style-system/palette.ts +6 -6
- package/example/AppStyleX/src/style-system/theme.ts +2 -2
- package/example/AppStyleX/src/style-system/utils.ts +4 -7
- package/example/AppStyleX/src/stylex.d.ts +3 -3
- package/package.json +15 -11
- package/src/appearance/index.ts +5 -12
- package/src/appearance/init.ts +2 -2
- package/src/context.ts +2 -5
- package/src/dark-mode/index.ts +2 -5
- package/src/dark-mode/init.ts +2 -2
- package/src/{dependencyUsage.ts → dependency-usage.ts} +0 -10
- package/src/dimensions/index.ts +1 -1
- package/src/dimensions/init.ts +5 -10
- package/src/dimensions/utils.ts +1 -3
- package/src/i18n.ts +1 -4
- package/src/index.ts +6 -6
- package/src/{makeUseStyles/createUseStylesTheme.js → make-use-styles/create-use-styles-theme.js} +23 -6
- package/src/{makeUseStyles/createUseStylesTheme.test.js → make-use-styles/create-use-styles-theme.test.js} +1 -1
- package/src/{makeUseStyles/createUseStylesWithoutTheme.js → make-use-styles/create-use-styles-without-theme.js} +20 -4
- package/src/make-use-styles/index.d.ts +20 -0
- package/src/make-use-styles/index.js +12 -0
- package/src/make-use-styles/types.ts +43 -0
- package/src/{makeUseStyles → make-use-styles}/utils.js +7 -12
- package/src/media-query/base.ts +19 -30
- package/src/media-query/breakpoints.ts +12 -37
- package/src/orientation.ts +3 -7
- package/src/safe-area/{eventEmitter.ts → event-emitter.ts} +1 -1
- package/src/safe-area/index.tsx +3 -3
- package/src/safe-area/init.tsx +2 -2
- package/src/safe-area/safe-area-provider.tsx +18 -0
- package/src/safe-area/{StylexSaveAreaConsumer.ts → stylex-save-area-consumer.ts} +4 -5
- package/src/safe-area/types.ts +2 -2
- package/src/{__tests__ → tests}/createEventEmitter.test.ts +1 -1
- package/src/{__tests__ → tests}/dependencyRegistry.test.ts +1 -1
- package/src/{__tests__ → tests}/dependencyUsage.test.ts +1 -1
- package/src/{__tests__ → tests}/dimensions.test.ts +4 -7
- package/src/{__tests__ → tests}/makeUseStyles.types-test.ts +1 -1
- package/src/{__tests__ → tests}/media-query.test.ts +1 -9
- package/src/{__tests__ → tests}/useTheme.test.ts +1 -1
- package/src/{__tests__ → tests}/withStyles.types-test.tsx +7 -8
- package/src/{useColorTransition.ts → use-color-transition.ts} +3 -3
- package/src/{useTheme.ts → use-theme.ts} +2 -4
- package/src/with-styles.tsx +22 -0
- package/tsconfig.build.json +31 -0
- package/src/makeUseStyles/index.d.ts +0 -7
- package/src/makeUseStyles/index.js +0 -12
- package/src/safe-area/SafeAreaProvider.tsx +0 -17
- package/src/withStyles.tsx +0 -35
- /package/src/{createEventEmitter.ts → create-event-emitter.ts} +0 -0
- /package/src/{DefaultTheme.ts → default-theme.ts} +0 -0
- /package/src/{dependencyRegistry.ts → dependency-registry.ts} +0 -0
- /package/src/{makeUseStyles/createUseStylesWithoutTheme.test.js → make-use-styles/create-use-styles-without-theme.test.js} +0 -0
- /package/src/{makeUseStyles → make-use-styles}/index.test.js +0 -0
- /package/src/{makeUseStyles → make-use-styles}/test-type.js +0 -0
- /package/src/{__tests__ → tests}/createBreakpoints.test.ts +0 -0
- /package/src/{__tests__ → tests}/createBreakpointsMatcher.test.ts +0 -0
- /package/src/{__tests__ → tests}/createBreakpointsMatcher.types-test.ts +0 -0
- /package/src/{__tests__ → tests}/dark-mode.test.ts +0 -0
- /package/src/{__tests__ → tests}/orientation.test.ts +0 -0
package/src/dark-mode/index.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import "./init";
|
|
2
2
|
|
|
3
|
-
import { onUse } from "../
|
|
3
|
+
import { onUse } from "../dependency-usage";
|
|
4
4
|
|
|
5
5
|
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
6
6
|
import { state } from "./state";
|
|
7
7
|
|
|
8
8
|
export type UiType = "dark" | "light";
|
|
9
9
|
|
|
10
|
-
export function uiMode<T>({
|
|
11
|
-
dark,
|
|
12
|
-
light,
|
|
13
|
-
}: { [mode in UiType]?: T }): T | undefined {
|
|
10
|
+
export function uiMode<T>({ dark, light }: { [mode in UiType]?: T }): T | undefined {
|
|
14
11
|
onUse(UI_MODE_DEPENDENCY_KEY);
|
|
15
12
|
|
|
16
13
|
if (state.mode === "dark") {
|
package/src/dark-mode/init.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { eventEmitter, Mode } from "react-native-dark-mode";
|
|
2
2
|
|
|
3
|
-
import { addDependency } from "../
|
|
4
|
-
import { createEventEmitter } from "../
|
|
3
|
+
import { addDependency } from "../dependency-registry";
|
|
4
|
+
import { createEventEmitter } from "../create-event-emitter";
|
|
5
5
|
|
|
6
6
|
import { UI_MODE_DEPENDENCY_KEY } from "./consts";
|
|
7
7
|
import { state } from "./state";
|
|
@@ -19,13 +19,3 @@ export function getUsing(): UsingSpec {
|
|
|
19
19
|
export function onUse(name: string): void {
|
|
20
20
|
ref.current[name] = true;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
interface Button {
|
|
24
|
-
variant: "primary" | "danger"
|
|
25
|
-
onAction: () => void
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// onAction -> onClick
|
|
29
|
-
// onAction -> onPress
|
|
30
|
-
|
|
31
|
-
|
package/src/dimensions/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import "./init";
|
|
|
2
2
|
|
|
3
3
|
import { Dimensions, ScaledSize } from "react-native";
|
|
4
4
|
|
|
5
|
-
import { onUse } from "../
|
|
5
|
+
import { onUse } from "../dependency-usage";
|
|
6
6
|
import { WINDOW_DEPENDENCY_KEY, SCREEN_DEPENDENCY_KEY } from "./consts";
|
|
7
7
|
|
|
8
8
|
const get = (dim: "window" | "screen") => Dimensions.get(dim);
|
package/src/dimensions/init.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dimensions, ScaledSize } from "react-native";
|
|
2
2
|
|
|
3
|
-
import { createEventEmitter } from "../
|
|
4
|
-
import { addDependency } from "../
|
|
3
|
+
import { createEventEmitter } from "../create-event-emitter";
|
|
4
|
+
import { addDependency } from "../dependency-registry";
|
|
5
5
|
import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
|
|
6
6
|
|
|
7
7
|
const { get, addEventListener } = Dimensions;
|
|
@@ -11,16 +11,11 @@ const state = { window: get("window"), screen: get("screen") };
|
|
|
11
11
|
const windowEventEmitter = createEventEmitter(WINDOW_DEPENDENCY_KEY);
|
|
12
12
|
const screenEventEmitter = createEventEmitter(SCREEN_DEPENDENCY_KEY);
|
|
13
13
|
|
|
14
|
-
const isNotEqual = (a: ScaledSize, b: ScaledSize) =>
|
|
15
|
-
a.width !== b.width || a.height !== b.height;
|
|
14
|
+
const isNotEqual = (a: ScaledSize, b: ScaledSize) => a.width !== b.width || a.height !== b.height;
|
|
16
15
|
|
|
17
|
-
addDependency(WINDOW_DEPENDENCY_KEY, (handler: () => void) =>
|
|
18
|
-
windowEventEmitter.on(handler)
|
|
19
|
-
);
|
|
16
|
+
addDependency(WINDOW_DEPENDENCY_KEY, (handler: () => void) => windowEventEmitter.on(handler));
|
|
20
17
|
|
|
21
|
-
addDependency(SCREEN_DEPENDENCY_KEY, (handler: () => void) =>
|
|
22
|
-
screenEventEmitter.on(handler)
|
|
23
|
-
);
|
|
18
|
+
addDependency(SCREEN_DEPENDENCY_KEY, (handler: () => void) => screenEventEmitter.on(handler));
|
|
24
19
|
|
|
25
20
|
addEventListener("change", ({ window, screen }) => {
|
|
26
21
|
if (isNotEqual(screen, state.screen)) {
|
package/src/dimensions/utils.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
|
|
2
2
|
|
|
3
|
-
export const optimizeDependencies = (
|
|
4
|
-
keys: Record<string, boolean>
|
|
5
|
-
): Record<string, boolean> => {
|
|
3
|
+
export const optimizeDependencies = (keys: Record<string, boolean>): Record<string, boolean> => {
|
|
6
4
|
if (keys[WINDOW_DEPENDENCY_KEY] && keys[SCREEN_DEPENDENCY_KEY]) {
|
|
7
5
|
delete keys[SCREEN_DEPENDENCY_KEY];
|
|
8
6
|
}
|
package/src/i18n.ts
CHANGED
|
@@ -2,10 +2,7 @@ import { I18nManager } from "react-native";
|
|
|
2
2
|
|
|
3
3
|
type LayoutDirectionType = "rtl" | "ltr";
|
|
4
4
|
|
|
5
|
-
export function i18n<T>({
|
|
6
|
-
rtl,
|
|
7
|
-
ltr,
|
|
8
|
-
}: { [direction in LayoutDirectionType]?: T }): T | undefined {
|
|
5
|
+
export function i18n<T>({ rtl, ltr }: { [direction in LayoutDirectionType]?: T }): T | undefined {
|
|
9
6
|
if (I18nManager.isRTL) {
|
|
10
7
|
return rtl;
|
|
11
8
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { useTheme } from "./
|
|
2
|
-
export { withStyles } from "./
|
|
1
|
+
export { useTheme } from "./use-theme";
|
|
2
|
+
export { withStyles } from "./with-styles";
|
|
3
3
|
export { ThemeProvider, ThemeConsumer } from "./context";
|
|
4
|
-
export { useColorTransition } from "./
|
|
5
|
-
export { makeUseStyles } from "./
|
|
6
|
-
export type { DefaultTheme } from "./
|
|
7
|
-
export type { InferInjectedStyledProps } from "./
|
|
4
|
+
export { useColorTransition } from "./use-color-transition";
|
|
5
|
+
export { makeUseStyles } from "./make-use-styles";
|
|
6
|
+
export type { DefaultTheme } from "./default-theme";
|
|
7
|
+
export type { InferInjectedStyledProps } from "./with-styles";
|
package/src/{makeUseStyles/createUseStylesTheme.js → make-use-styles/create-use-styles-theme.js}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { StyleSheet } from "react-native";
|
|
2
|
-
import { useTheme } from "../
|
|
3
|
-
import { resetUsing } from "../
|
|
2
|
+
import { useTheme } from "../use-theme";
|
|
3
|
+
import { resetUsing } from "../dependency-usage";
|
|
4
4
|
import { getDependenciesKeys, useForceUpdate, subscribe } from "./utils";
|
|
5
5
|
|
|
6
|
-
export function createUseStylesTheme(getStyles) {
|
|
6
|
+
export function createUseStylesTheme(getStyles, getVariants) {
|
|
7
7
|
const scope = {
|
|
8
8
|
styles: new WeakMap(),
|
|
9
9
|
forceUpdate: [],
|
|
@@ -20,7 +20,7 @@ export function createUseStylesTheme(getStyles) {
|
|
|
20
20
|
scope.unsubscribe();
|
|
21
21
|
resetUsing();
|
|
22
22
|
|
|
23
|
-
const style = StyleSheet.create(getStyles(theme));
|
|
23
|
+
const style = StyleSheet.create(getStyles?.(theme) ?? {});
|
|
24
24
|
const keys = getDependenciesKeys();
|
|
25
25
|
|
|
26
26
|
scope.unsubscribe = subscribe(keys, onUpdate);
|
|
@@ -28,7 +28,7 @@ export function createUseStylesTheme(getStyles) {
|
|
|
28
28
|
return style;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
function useStyles(variants) {
|
|
32
32
|
const theme = useTheme();
|
|
33
33
|
|
|
34
34
|
useForceUpdate(scope);
|
|
@@ -37,6 +37,23 @@ export function createUseStylesTheme(getStyles) {
|
|
|
37
37
|
scope.styles.set(theme, initStyle(theme));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
if (getVariants) {
|
|
41
|
+
const configVariants = getVariants(theme);
|
|
42
|
+
const requestedVarians = {};
|
|
43
|
+
|
|
44
|
+
for (const key in variants) {
|
|
45
|
+
const value = configVariants[key][variants[key]];
|
|
46
|
+
Object.assign(requestedVarians, value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
...scope.styles.get(theme),
|
|
51
|
+
...StyleSheet.create({ variants: requestedVarians }),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
return scope.styles.get(theme);
|
|
41
|
-
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return useStyles;
|
|
42
59
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { StyleSheet } from "react-native";
|
|
2
|
-
import { resetUsing } from "../
|
|
2
|
+
import { resetUsing } from "../dependency-usage";
|
|
3
3
|
import { getDependenciesKeys, subscribe, useForceUpdate } from "./utils";
|
|
4
4
|
|
|
5
|
-
export function createUseStylesWithoutTheme(getStyles) {
|
|
5
|
+
export function createUseStylesWithoutTheme(getStyles, getVariants) {
|
|
6
6
|
const scope = {
|
|
7
7
|
style: null,
|
|
8
|
+
variants: null,
|
|
8
9
|
forceUpdate: [],
|
|
9
10
|
unsubscribe: () => {},
|
|
10
11
|
};
|
|
@@ -19,7 +20,7 @@ export function createUseStylesWithoutTheme(getStyles) {
|
|
|
19
20
|
scope.unsubscribe();
|
|
20
21
|
resetUsing();
|
|
21
22
|
|
|
22
|
-
scope.style = StyleSheet.create(getStyles());
|
|
23
|
+
scope.style = StyleSheet.create(getStyles?.() ?? {});
|
|
23
24
|
|
|
24
25
|
const keys = getDependenciesKeys();
|
|
25
26
|
|
|
@@ -28,9 +29,24 @@ export function createUseStylesWithoutTheme(getStyles) {
|
|
|
28
29
|
|
|
29
30
|
initStyle();
|
|
30
31
|
|
|
31
|
-
function useStyles() {
|
|
32
|
+
function useStyles(variants) {
|
|
32
33
|
useForceUpdate(scope);
|
|
33
34
|
|
|
35
|
+
if (getVariants) {
|
|
36
|
+
const configVariants = getVariants();
|
|
37
|
+
const requestedVarians = {};
|
|
38
|
+
|
|
39
|
+
for (const key in variants) {
|
|
40
|
+
const value = configVariants[key][variants[key]];
|
|
41
|
+
Object.assign(requestedVarians, value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...scope.style,
|
|
46
|
+
...StyleSheet.create({ variants: requestedVarians }),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
34
50
|
return scope.style;
|
|
35
51
|
}
|
|
36
52
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { DefaultTheme } from "../default-theme";
|
|
3
|
+
|
|
4
|
+
export function makeUseStyles<
|
|
5
|
+
Theme extends DefaultTheme,
|
|
6
|
+
T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>,
|
|
7
|
+
VariantsConfig extends Record<string, StyleSheet.NamedStyles<any>> | undefined = undefined,
|
|
8
|
+
>(config: {
|
|
9
|
+
styles?: (theme: Theme) => T | StyleSheet.NamedStyles<T>;
|
|
10
|
+
variants?: ((theme: Theme) => VariantsConfig) | undefined;
|
|
11
|
+
}): <Variants extends { [Key in keyof VariantsConfig]: keyof VariantsConfig[Key] }>(
|
|
12
|
+
variants?: Partial<Variants>,
|
|
13
|
+
) => T &
|
|
14
|
+
(VariantsConfig extends undefined
|
|
15
|
+
? {}
|
|
16
|
+
: {
|
|
17
|
+
variants: {
|
|
18
|
+
[VKey in keyof Variants]: VKey extends keyof VariantsConfig ? VariantsConfig[VKey][Variants[VKey]] : never;
|
|
19
|
+
}[keyof Variants];
|
|
20
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createUseStylesWithoutTheme } from "./create-use-styles-without-theme";
|
|
2
|
+
import { createUseStylesTheme } from "./create-use-styles-theme";
|
|
3
|
+
|
|
4
|
+
export function makeUseStyles({ styles, variants }) {
|
|
5
|
+
const hasThemeDependency = styles?.length === 1;
|
|
6
|
+
|
|
7
|
+
if (!hasThemeDependency) {
|
|
8
|
+
return createUseStylesWithoutTheme(styles, variants);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return createUseStylesTheme(styles);
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// import { StyleSheet } from "react-native";
|
|
2
|
+
// import { DefaultTheme } from "../DefaultTheme";
|
|
3
|
+
|
|
4
|
+
// // // Source - https://stackoverflow.com/a/50375286
|
|
5
|
+
// // // Posted by jcalz, modified by community. See post 'Timeline' for change history
|
|
6
|
+
// // // Retrieved 2026-01-07, License - CC BY-SA 4.0
|
|
7
|
+
|
|
8
|
+
// // type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
|
|
9
|
+
// // x: infer I,
|
|
10
|
+
// // ) => void
|
|
11
|
+
// // ? I
|
|
12
|
+
// // : never;
|
|
13
|
+
|
|
14
|
+
// export function makeUseStyles<
|
|
15
|
+
// Theme extends DefaultTheme,
|
|
16
|
+
// T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>,
|
|
17
|
+
// V extends Record<string, StyleSheet.NamedStyles<any>>,
|
|
18
|
+
// >(
|
|
19
|
+
// getStyles: (theme: Theme) => T | StyleSheet.NamedStyles<T>,
|
|
20
|
+
// variants: V,
|
|
21
|
+
// ): <Variants extends { [Key in keyof V]: keyof V[Key] }>(
|
|
22
|
+
// variants?: Partial<Variants>,
|
|
23
|
+
// ) => T & {
|
|
24
|
+
// variants: {
|
|
25
|
+
// [VKey in keyof Variants]: VKey extends keyof V
|
|
26
|
+
// ? V[VKey][Variants[VKey]]
|
|
27
|
+
// : never;
|
|
28
|
+
// }[keyof Variants];
|
|
29
|
+
// } {
|
|
30
|
+
// return ((variants: any) => {}) as any;
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// const useStyles = makeUseStyles(() => ({ some: { alignContent: "center" } }), {
|
|
34
|
+
// other: {
|
|
35
|
+
// one: { alignContent: "flex-end", fontStyle: "italic", fontFamily: "Inter" },
|
|
36
|
+
// two: { alignContent: "flex-end" },
|
|
37
|
+
// },
|
|
38
|
+
// more: {
|
|
39
|
+
// lol: { color: "red", width: 123 },
|
|
40
|
+
// },
|
|
41
|
+
// });
|
|
42
|
+
|
|
43
|
+
// const res = useStyles({ more: "lol"});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { optimizeDependencies } from "../dimensions/utils";
|
|
2
|
-
import { getUsing } from "../
|
|
3
|
-
import { getDependency } from "../
|
|
2
|
+
import { getUsing } from "../dependency-usage";
|
|
3
|
+
import { getDependency } from "../dependency-registry";
|
|
4
4
|
|
|
5
5
|
import { useEffect, useRef, useState } from "react";
|
|
6
6
|
|
|
@@ -17,9 +17,7 @@ export const useForceUpdate = (scope) => {
|
|
|
17
17
|
scope.forceUpdate = scope.forceUpdate.concat(forceRerender);
|
|
18
18
|
|
|
19
19
|
unsubscribeRef.current = () => {
|
|
20
|
-
scope.forceUpdate = scope.forceUpdate.filter(
|
|
21
|
-
(fn) => fn !== forceRerender
|
|
22
|
-
);
|
|
20
|
+
scope.forceUpdate = scope.forceUpdate.filter((fn) => fn !== forceRerender);
|
|
23
21
|
};
|
|
24
22
|
}
|
|
25
23
|
|
|
@@ -28,12 +26,11 @@ export const useForceUpdate = (scope) => {
|
|
|
28
26
|
unsubscribeRef.current();
|
|
29
27
|
unsubscribeRef.current = noop;
|
|
30
28
|
},
|
|
31
|
-
[]
|
|
29
|
+
[],
|
|
32
30
|
);
|
|
33
31
|
};
|
|
34
32
|
|
|
35
|
-
export const getDependenciesKeys = () =>
|
|
36
|
-
Object.keys(optimizeDependencies(getUsing())).sort();
|
|
33
|
+
export const getDependenciesKeys = () => Object.keys(optimizeDependencies(getUsing())).sort();
|
|
37
34
|
|
|
38
35
|
export const subscribe = (dependenciesKeys, handler) => {
|
|
39
36
|
if (dependenciesKeys.length === 0) {
|
|
@@ -50,14 +47,12 @@ export const subscribe = (dependenciesKeys, handler) => {
|
|
|
50
47
|
const dependencyName = dependenciesKeys[index];
|
|
51
48
|
|
|
52
49
|
if (!onChange) {
|
|
53
|
-
console.warn(
|
|
54
|
-
`[react-native-stylex] Could not find onChange handler for ${dependencyName}!`
|
|
55
|
-
);
|
|
50
|
+
console.warn(`[react-native-stylex] Could not find onChange handler for ${dependencyName}!`);
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
return !!onChange;
|
|
59
54
|
}
|
|
60
|
-
: Boolean
|
|
55
|
+
: Boolean,
|
|
61
56
|
)
|
|
62
57
|
.map((onChange) => onChange(handler));
|
|
63
58
|
|
package/src/media-query/base.ts
CHANGED
|
@@ -2,42 +2,31 @@ import { ScaledSize } from "react-native";
|
|
|
2
2
|
|
|
3
3
|
import { getWindowDimensions } from "../dimensions";
|
|
4
4
|
|
|
5
|
-
export const createDimensionQueryHelper =
|
|
6
|
-
queryFunction: (options: { value: Value; dimensions: ScaledSize }) => boolean
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export const createDimensionQueryHelper =
|
|
6
|
+
<Value>(queryFunction: (options: { value: Value; dimensions: ScaledSize }) => boolean) =>
|
|
7
|
+
<T>(value: Value, styles: T): null | T => {
|
|
8
|
+
const isMatched = queryFunction({
|
|
9
|
+
value,
|
|
10
|
+
dimensions: getWindowDimensions(),
|
|
11
|
+
});
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
if (isMatched) {
|
|
14
|
+
return styles;
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
};
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
16
19
|
|
|
17
|
-
export const maxHeight = createDimensionQueryHelper<number>(
|
|
18
|
-
({ value, dimensions }) => value >= dimensions.height
|
|
19
|
-
);
|
|
20
|
+
export const maxHeight = createDimensionQueryHelper<number>(({ value, dimensions }) => value >= dimensions.height);
|
|
20
21
|
|
|
21
|
-
export const maxWidth = createDimensionQueryHelper<number>(
|
|
22
|
-
({ value, dimensions }) => value >= dimensions.width
|
|
23
|
-
);
|
|
22
|
+
export const maxWidth = createDimensionQueryHelper<number>(({ value, dimensions }) => value >= dimensions.width);
|
|
24
23
|
|
|
25
|
-
export const minHeight = createDimensionQueryHelper<number>(
|
|
26
|
-
({ value, dimensions }) => value <= dimensions.height
|
|
27
|
-
);
|
|
24
|
+
export const minHeight = createDimensionQueryHelper<number>(({ value, dimensions }) => value <= dimensions.height);
|
|
28
25
|
|
|
29
|
-
export const minWidth = createDimensionQueryHelper<number>(
|
|
30
|
-
({ value, dimensions }) => value <= dimensions.width
|
|
31
|
-
);
|
|
26
|
+
export const minWidth = createDimensionQueryHelper<number>(({ value, dimensions }) => value <= dimensions.width);
|
|
32
27
|
|
|
33
|
-
export const minAspectRatio = createDimensionQueryHelper<number>(
|
|
34
|
-
({ value, dimensions: { width, height } }) => value <= width / height
|
|
35
|
-
);
|
|
28
|
+
export const minAspectRatio = createDimensionQueryHelper<number>(({ value, dimensions: { width, height } }) => value <= width / height);
|
|
36
29
|
|
|
37
|
-
export const maxAspectRatio = createDimensionQueryHelper<number>(
|
|
38
|
-
({ value, dimensions: { width, height } }) => value >= width / height
|
|
39
|
-
);
|
|
30
|
+
export const maxAspectRatio = createDimensionQueryHelper<number>(({ value, dimensions: { width, height } }) => value >= width / height);
|
|
40
31
|
|
|
41
|
-
export const aspectRatio = createDimensionQueryHelper<number>(
|
|
42
|
-
({ value, dimensions: { width, height } }) => value === width / height
|
|
43
|
-
);
|
|
32
|
+
export const aspectRatio = createDimensionQueryHelper<number>(({ value, dimensions: { width, height } }) => value === width / height);
|
|
@@ -10,7 +10,7 @@ const orderByMin = [minWidth, minAspectRatio, minHeight];
|
|
|
10
10
|
const toOrderedBreakpointNames = <TBreakpoints extends Record<string, number>>(
|
|
11
11
|
values: any,
|
|
12
12
|
breakpoints: any,
|
|
13
|
-
matchFunction: any
|
|
13
|
+
matchFunction: any,
|
|
14
14
|
): Array<keyof TBreakpoints> => {
|
|
15
15
|
const result = Object.keys(values)
|
|
16
16
|
.filter((e) => e !== "default")
|
|
@@ -26,15 +26,13 @@ const toOrderedBreakpointNames = <TBreakpoints extends Record<string, number>>(
|
|
|
26
26
|
/*
|
|
27
27
|
* To debug use analog on CSS: https://codepen.io/retyui/pen/dyOzKzV
|
|
28
28
|
*/
|
|
29
|
-
export function createBreakpointsMatcher<
|
|
30
|
-
TBreakpoints extends Record<string, number>
|
|
31
|
-
>(
|
|
29
|
+
export function createBreakpointsMatcher<TBreakpoints extends Record<string, number>>(
|
|
32
30
|
breakpoints: TBreakpoints,
|
|
33
|
-
matchFunction = minWidth
|
|
31
|
+
matchFunction = minWidth,
|
|
34
32
|
): BreakpointsMatcher<TBreakpoints> {
|
|
35
33
|
return function breakpointsMatcher(values: any) {
|
|
36
34
|
/* istanbul ignore next */
|
|
37
|
-
// @ts-expect-error
|
|
35
|
+
// @ts-expect-error
|
|
38
36
|
if (process.env.NODE_ENV !== "production") {
|
|
39
37
|
const invalidKeys = Object.keys(values).filter((key) => {
|
|
40
38
|
return key !== "default" && breakpoints[key] === undefined;
|
|
@@ -46,47 +44,30 @@ export function createBreakpointsMatcher<
|
|
|
46
44
|
|
|
47
45
|
allowed keys: ${Object.keys(breakpoints).join(", ")}
|
|
48
46
|
unexpected keys: ${invalidKeys.join(", ")}
|
|
49
|
-
|
|
47
|
+
`,
|
|
50
48
|
);
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
const orderedBreakpointNames = toOrderedBreakpointNames<TBreakpoints>(
|
|
55
|
-
values,
|
|
56
|
-
breakpoints,
|
|
57
|
-
matchFunction
|
|
58
|
-
);
|
|
52
|
+
const orderedBreakpointNames = toOrderedBreakpointNames<TBreakpoints>(values, breakpoints, matchFunction);
|
|
59
53
|
|
|
60
|
-
const key =
|
|
61
|
-
orderedBreakpointNames.find((breakpointName) =>
|
|
62
|
-
matchFunction(
|
|
63
|
-
breakpoints[breakpointName] as number,
|
|
64
|
-
values[breakpointName]
|
|
65
|
-
)
|
|
66
|
-
) || "default";
|
|
54
|
+
const key = orderedBreakpointNames.find((breakpointName) => matchFunction(breakpoints[breakpointName] as number, values[breakpointName])) || "default";
|
|
67
55
|
|
|
68
56
|
return values[key] || null;
|
|
69
57
|
};
|
|
70
58
|
}
|
|
71
59
|
|
|
72
|
-
function getNextByKey<TBreakpoints extends Record<string, number>>(
|
|
73
|
-
breakpoints: TBreakpoints,
|
|
74
|
-
key: keyof TBreakpoints
|
|
75
|
-
) {
|
|
60
|
+
function getNextByKey<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints, key: keyof TBreakpoints) {
|
|
76
61
|
type Keys = keyof TBreakpoints;
|
|
77
62
|
|
|
78
|
-
const breakpointsKeys: Array<Keys> = Object.keys(breakpoints).sort(
|
|
79
|
-
(a: Keys, b: Keys) => breakpoints[a]! - breakpoints[b]!
|
|
80
|
-
);
|
|
63
|
+
const breakpointsKeys: Array<Keys> = Object.keys(breakpoints).sort((a: Keys, b: Keys) => breakpoints[a]! - breakpoints[b]!);
|
|
81
64
|
const index = breakpointsKeys.indexOf(key);
|
|
82
65
|
const nextKey: Keys | undefined = breakpointsKeys[index + 1];
|
|
83
66
|
|
|
84
67
|
return nextKey;
|
|
85
68
|
}
|
|
86
69
|
|
|
87
|
-
export function createBreakpoints<TBreakpoints extends Record<string, number>>(
|
|
88
|
-
breakpoints: TBreakpoints
|
|
89
|
-
) {
|
|
70
|
+
export function createBreakpoints<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints) {
|
|
90
71
|
type Keys = keyof TBreakpoints;
|
|
91
72
|
|
|
92
73
|
function up<T>(key: Keys, value: T): T | null {
|
|
@@ -101,20 +82,14 @@ export function createBreakpoints<TBreakpoints extends Record<string, number>>(
|
|
|
101
82
|
const nextKey = getNextByKey<TBreakpoints>(breakpoints, key);
|
|
102
83
|
|
|
103
84
|
if (nextKey !== undefined) {
|
|
104
|
-
return minWidth(
|
|
105
|
-
breakpoints[key] as number,
|
|
106
|
-
maxWidth(breakpoints[nextKey]! - 0.05, value)
|
|
107
|
-
);
|
|
85
|
+
return minWidth(breakpoints[key] as number, maxWidth(breakpoints[nextKey]! - 0.05, value));
|
|
108
86
|
}
|
|
109
87
|
|
|
110
88
|
return minWidth(breakpoints[key] as number, value);
|
|
111
89
|
}
|
|
112
90
|
|
|
113
91
|
function between<T>(start: Keys, end: Keys, value: T): T | null {
|
|
114
|
-
return minWidth(
|
|
115
|
-
breakpoints[start] as number,
|
|
116
|
-
maxWidth(breakpoints[end]! - 0.05, value)
|
|
117
|
-
);
|
|
92
|
+
return minWidth(breakpoints[start] as number, maxWidth(breakpoints[end]! - 0.05, value));
|
|
118
93
|
}
|
|
119
94
|
|
|
120
95
|
return { up, down, only, between };
|
package/src/orientation.ts
CHANGED
|
@@ -2,16 +2,12 @@ import { getScreenDimensions } from "./dimensions";
|
|
|
2
2
|
|
|
3
3
|
type OrientationType = "portrait" | "landscape";
|
|
4
4
|
|
|
5
|
-
export function orientation<T>(
|
|
6
|
-
spec: { [orientation in OrientationType]?: T }
|
|
7
|
-
): T | undefined {
|
|
5
|
+
export function orientation<T>(spec: { [orientation in OrientationType]?: T }): T | undefined {
|
|
8
6
|
const { height, width } = getScreenDimensions();
|
|
9
7
|
|
|
10
8
|
return width <= height ? spec.portrait : spec.landscape;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
export const portraitOrientation = <T>(portraitStyles: T): T | undefined =>
|
|
14
|
-
orientation<T>({ portrait: portraitStyles });
|
|
11
|
+
export const portraitOrientation = <T>(portraitStyles: T): T | undefined => orientation<T>({ portrait: portraitStyles });
|
|
15
12
|
|
|
16
|
-
export const landscapeOrientation = <T>(landscapeStyles: T): T | undefined =>
|
|
17
|
-
orientation<T>({ landscape: landscapeStyles });
|
|
13
|
+
export const landscapeOrientation = <T>(landscapeStyles: T): T | undefined => orientation<T>({ landscape: landscapeStyles });
|
package/src/safe-area/index.tsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "./init";
|
|
2
2
|
|
|
3
|
-
import { onUse } from "../
|
|
3
|
+
import { onUse } from "../dependency-usage";
|
|
4
4
|
|
|
5
5
|
import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
|
|
6
6
|
import { EdgeInsets } from "./types";
|
|
7
7
|
import { state } from "./state";
|
|
8
8
|
|
|
9
|
-
export { StylexSaveAreaConsumer } from "./
|
|
10
|
-
export { SafeAreaProvider } from "./
|
|
9
|
+
export { StylexSaveAreaConsumer } from "./stylex-save-area-consumer";
|
|
10
|
+
export { SafeAreaProvider } from "./safe-area-provider";
|
|
11
11
|
|
|
12
12
|
export function getSafeArea(): EdgeInsets {
|
|
13
13
|
onUse(SAFE_AREA_DEPENDENCY_KEY);
|
package/src/safe-area/init.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { addDependency } from "../
|
|
1
|
+
import { addDependency } from "../dependency-registry";
|
|
2
2
|
|
|
3
3
|
import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
|
|
4
|
-
import { on } from "./
|
|
4
|
+
import { on } from "./event-emitter";
|
|
5
5
|
|
|
6
6
|
addDependency(SAFE_AREA_DEPENDENCY_KEY, (handler: () => void) => on(handler));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SafeAreaProvider as CoreSafeAreaProvider, initialWindowMetrics, initialWindowSafeAreaInsets } from "react-native-safe-area-context";
|
|
3
|
+
|
|
4
|
+
import { StylexSaveAreaConsumer } from "./stylex-save-area-consumer";
|
|
5
|
+
import { SafeAreaViewProps } from "./types";
|
|
6
|
+
|
|
7
|
+
export function SafeAreaProvider(props: SafeAreaViewProps): React.JSX.Element | null {
|
|
8
|
+
return (
|
|
9
|
+
<CoreSafeAreaProvider
|
|
10
|
+
initialSafeAreaInsets={props.initialSafeAreaInsets || initialWindowSafeAreaInsets}
|
|
11
|
+
initialMetrics={props.initialMetrics || initialWindowMetrics}
|
|
12
|
+
{...props}
|
|
13
|
+
>
|
|
14
|
+
{props.children}
|
|
15
|
+
<StylexSaveAreaConsumer />
|
|
16
|
+
</CoreSafeAreaProvider>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
2
|
import { EdgeInsets } from "./types";
|
|
3
3
|
|
|
4
|
-
import { emit } from "./
|
|
4
|
+
import { emit } from "./event-emitter";
|
|
5
5
|
import { state } from "./state";
|
|
6
6
|
import { useLayoutEffect } from "react";
|
|
7
|
+
import type React from "react";
|
|
7
8
|
|
|
8
|
-
export function StylexSaveAreaConsumer(): JSX.Element | null {
|
|
9
|
+
export function StylexSaveAreaConsumer(): React.JSX.Element | null {
|
|
9
10
|
const insets: EdgeInsets = useSafeAreaInsets();
|
|
10
11
|
|
|
11
12
|
useLayoutEffect(() => {
|
|
12
|
-
const isChanged = Object.entries(insets).some(
|
|
13
|
-
([key, value]) => state.insets[key as keyof EdgeInsets] !== value
|
|
14
|
-
);
|
|
13
|
+
const isChanged = Object.entries(insets).some(([key, value]) => state.insets[key as keyof EdgeInsets] !== value);
|
|
15
14
|
|
|
16
15
|
if (isChanged) {
|
|
17
16
|
state.insets = insets;
|
package/src/safe-area/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {SafeAreaProviderProps} from "react-native-safe-area-context";
|
|
1
|
+
import { SafeAreaProviderProps } from "react-native-safe-area-context";
|
|
2
2
|
|
|
3
3
|
export interface EdgeInsets {
|
|
4
4
|
top: number;
|
|
@@ -7,4 +7,4 @@ export interface EdgeInsets {
|
|
|
7
7
|
left: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export interface SafeAreaViewProps extends SafeAreaProviderProps {
|
|
10
|
+
export interface SafeAreaViewProps extends SafeAreaProviderProps {}
|