@codeandmoney/soelma 0.0.0-dev.1 → 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/.eslintignore +1 -0
- package/.eslintrc.js +27 -0
- package/.github/workflows/nodejs.yml +33 -0
- package/.size-limit.json +6 -0
- package/babel.config.js +3 -0
- package/biome.jsonc +73 -0
- package/docs/api.md +103 -0
- package/docs/appearance.md +54 -0
- package/docs/dark-mode.md +46 -0
- package/docs/dimensions.md +29 -0
- package/docs/i18n.md +67 -0
- package/docs/logo.png +0 -0
- package/docs/media-query.md +274 -0
- package/docs/orientation.md +44 -0
- package/docs/safe-area.md +62 -0
- package/docs/testting.md +51 -0
- package/docs/ts.md +127 -0
- package/example/AppStyleX/.watchmanconfig +1 -0
- package/example/AppStyleX/android/build.gradle +26 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/example/AppStyleX/android/gradle.properties +53 -0
- package/example/AppStyleX/android/gradlew +249 -0
- package/example/AppStyleX/android/gradlew.bat +92 -0
- package/example/AppStyleX/android/settings.gradle +12 -0
- package/example/AppStyleX/app.json +16 -0
- package/example/AppStyleX/babel.config.js +3 -0
- package/example/AppStyleX/index.js +9 -0
- package/example/AppStyleX/ios/Podfile +7 -0
- package/example/AppStyleX/ios/Podfile.lock +1252 -0
- package/example/AppStyleX/metro.config.js +51 -0
- package/example/AppStyleX/package.json +43 -0
- package/example/AppStyleX/react-native.config.js +23 -0
- package/example/AppStyleX/src/App.tsx +22 -0
- package/example/AppStyleX/src/BottomNav/index.tsx +26 -0
- package/example/AppStyleX/src/BottomNav/styles.ts +42 -0
- package/example/AppStyleX/src/Circle/index.tsx +53 -0
- package/example/AppStyleX/src/Circle/styles.ts +22 -0
- package/example/AppStyleX/src/Root/index.tsx +35 -0
- package/example/AppStyleX/src/Root/styles.ts +18 -0
- package/example/AppStyleX/src/ToggleButton/index.tsx +52 -0
- package/example/AppStyleX/src/ToggleButton/styles.ts +67 -0
- package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +5 -0
- package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +5 -0
- package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +8 -0
- package/example/AppStyleX/src/style-system/palette.ts +11 -0
- package/example/AppStyleX/src/style-system/theme.ts +14 -0
- package/example/AppStyleX/src/style-system/utils.ts +8 -0
- package/example/AppStyleX/src/stylex.d.ts +6 -0
- package/example/AppStyleX/tsconfig.json +3 -0
- package/example/AppStyleX/yarn.lock +6767 -0
- package/jest.config.js +19 -0
- package/package.json +38 -3
- package/src/appearance/index.ts +30 -0
- package/src/appearance/init.ts +12 -0
- package/{context.js → src/context.ts} +4 -1
- package/src/create-event-emitter.ts +26 -0
- package/src/dark-mode/index.ts +26 -0
- package/src/dark-mode/init.ts +19 -0
- package/{dark-mode/state.js → src/dark-mode/state.ts} +2 -1
- package/src/default-theme.ts +4 -0
- package/src/dependency-registry.ts +21 -0
- package/src/dependency-usage.ts +21 -0
- package/src/dimensions/index.ts +20 -0
- package/src/dimensions/init.ts +32 -0
- package/src/dimensions/utils.ts +9 -0
- package/src/i18n.ts +15 -0
- package/src/index.ts +7 -0
- package/{makeUseStyles/createUseStylesTheme.js → src/make-use-styles/create-use-styles-theme.js} +23 -6
- package/src/make-use-styles/create-use-styles-theme.test.js +137 -0
- package/{makeUseStyles/createUseStylesWithoutTheme.js → src/make-use-styles/create-use-styles-without-theme.js} +20 -4
- package/src/make-use-styles/create-use-styles-without-theme.test.js +63 -0
- package/src/make-use-styles/index.d.ts +20 -0
- package/src/make-use-styles/index.js +12 -0
- package/src/make-use-styles/index.test.js +28 -0
- package/src/make-use-styles/types.ts +43 -0
- package/{makeUseStyles → src/make-use-styles}/utils.js +5 -10
- package/src/media-query/base.ts +32 -0
- package/src/media-query/breakpoints.ts +96 -0
- package/src/media-query/index.ts +12 -0
- package/src/orientation.ts +13 -0
- package/{safe-area/eventEmitter.js → src/safe-area/event-emitter.ts} +2 -1
- package/src/safe-area/index.tsx +16 -0
- package/src/safe-area/init.tsx +6 -0
- package/src/safe-area/safe-area-provider.tsx +18 -0
- package/{safe-area/state.js → src/safe-area/state.ts} +7 -5
- package/src/safe-area/stylex-save-area-consumer.ts +22 -0
- package/{safe-area/types.d.ts → src/safe-area/types.ts} +7 -6
- package/src/tests/createBreakpoints.test.ts +152 -0
- package/src/tests/createBreakpointsMatcher.test.ts +188 -0
- package/src/tests/createBreakpointsMatcher.types-test.ts +81 -0
- package/src/tests/createEventEmitter.test.ts +37 -0
- package/src/tests/dark-mode.test.ts +56 -0
- package/src/tests/dependencyRegistry.test.ts +16 -0
- package/src/tests/dependencyUsage.test.ts +13 -0
- package/src/tests/dimensions.test.ts +33 -0
- package/src/tests/makeUseStyles.types-test.ts +69 -0
- package/src/tests/media-query.test.ts +196 -0
- package/src/tests/orientation.test.ts +61 -0
- package/src/tests/useTheme.test.ts +26 -0
- package/src/tests/withStyles.types-test.tsx +172 -0
- package/src/use-color-transition.ts +50 -0
- package/src/use-theme.ts +14 -0
- package/src/with-styles.tsx +22 -0
- package/tsconfig.build.json +31 -0
- package/tsconfig.json +30 -0
- package/DefaultTheme.d.ts +0 -2
- package/DefaultTheme.js +0 -1
- package/appearance/consts.d.ts +0 -1
- package/appearance/index.d.ts +0 -8
- package/appearance/index.js +0 -18
- package/appearance/init.d.ts +0 -1
- package/appearance/init.js +0 -7
- package/context.d.ts +0 -4
- package/createEventEmitter.d.ts +0 -8
- package/createEventEmitter.js +0 -11
- package/dark-mode/consts.d.ts +0 -1
- package/dark-mode/index.d.ts +0 -7
- package/dark-mode/index.js +0 -16
- package/dark-mode/init.d.ts +0 -1
- package/dark-mode/init.js +0 -13
- package/dark-mode/state.d.ts +0 -3
- package/dependencyRegistry.d.ts +0 -5
- package/dependencyRegistry.js +0 -12
- package/dependencyUsage.d.ts +0 -7
- package/dependencyUsage.js +0 -10
- package/dimensions/consts.d.ts +0 -2
- package/dimensions/index.d.ts +0 -4
- package/dimensions/index.js +0 -13
- package/dimensions/init.d.ts +0 -1
- package/dimensions/init.js +0 -21
- package/dimensions/utils.d.ts +0 -1
- package/dimensions/utils.js +0 -7
- package/i18n.d.ts +0 -7
- package/i18n.js +0 -9
- package/index.d.ts +0 -7
- package/index.js +0 -5
- package/makeUseStyles/index.d.ts +0 -7
- package/makeUseStyles/index.js +0 -12
- package/media-query/base.d.ts +0 -12
- package/media-query/base.js +0 -18
- package/media-query/breakpoints.d.ts +0 -18
- package/media-query/breakpoints.js +0 -60
- package/media-query/index.d.ts +0 -2
- package/media-query/index.js +0 -2
- package/orientation.d.ts +0 -7
- package/orientation.js +0 -7
- package/safe-area/SafeAreaProvider.d.ts +0 -3
- package/safe-area/SafeAreaProvider.js +0 -9
- package/safe-area/StylexSaveAreaConsumer.d.ts +0 -2
- package/safe-area/StylexSaveAreaConsumer.js +0 -15
- package/safe-area/consts.d.ts +0 -1
- package/safe-area/eventEmitter.d.ts +0 -1
- package/safe-area/index.d.ts +0 -5
- package/safe-area/index.js +0 -10
- package/safe-area/init.d.ts +0 -1
- package/safe-area/init.js +0 -4
- package/safe-area/state.d.ts +0 -8
- package/safe-area/types.js +0 -1
- package/useColorTransition.d.ts +0 -5
- package/useColorTransition.js +0 -38
- package/useTheme.d.ts +0 -2
- package/useTheme.js +0 -9
- package/withStyles.d.ts +0 -7
- package/withStyles.js +0 -13
- /package/{appearance/consts.js → src/appearance/consts.ts} +0 -0
- /package/{dark-mode/consts.js → src/dark-mode/consts.ts} +0 -0
- /package/{dimensions/consts.js → src/dimensions/consts.ts} +0 -0
- /package/{makeUseStyles → src/make-use-styles}/test-type.js +0 -0
- /package/{safe-area/consts.js → src/safe-area/consts.ts} +0 -0
package/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { useTheme } from "./useTheme";
|
|
2
|
-
export { withStyles } from "./withStyles";
|
|
3
|
-
export { ThemeProvider, ThemeConsumer } from "./context";
|
|
4
|
-
export { useColorTransition } from "./useColorTransition";
|
|
5
|
-
export { makeUseStyles } from "./makeUseStyles";
|
|
6
|
-
export type { DefaultTheme } from "./DefaultTheme";
|
|
7
|
-
export type { InferInjectedStyledProps } from "./withStyles";
|
package/index.js
DELETED
package/makeUseStyles/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from "react-native";
|
|
2
|
-
import { DefaultTheme } from "../DefaultTheme";
|
|
3
|
-
|
|
4
|
-
export function makeUseStyles<
|
|
5
|
-
Theme extends DefaultTheme,
|
|
6
|
-
T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>,
|
|
7
|
-
>(getStyles: (theme: Theme) => T | StyleSheet.NamedStyles<T>): () => T;
|
package/makeUseStyles/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createUseStylesWithoutTheme } from "./createUseStylesWithoutTheme";
|
|
2
|
-
import { createUseStylesTheme } from "./createUseStylesTheme";
|
|
3
|
-
|
|
4
|
-
export function makeUseStyles(getStyles) {
|
|
5
|
-
const hasThemeDependency = getStyles.length === 1;
|
|
6
|
-
|
|
7
|
-
if (!hasThemeDependency) {
|
|
8
|
-
return createUseStylesWithoutTheme(getStyles);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return createUseStylesTheme(getStyles);
|
|
12
|
-
}
|
package/media-query/base.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ScaledSize } from "react-native";
|
|
2
|
-
export declare const createDimensionQueryHelper: <Value>(queryFunction: (options: {
|
|
3
|
-
value: Value;
|
|
4
|
-
dimensions: ScaledSize;
|
|
5
|
-
}) => boolean) => <T>(value: Value, styles: T) => T | null;
|
|
6
|
-
export declare const maxHeight: <T>(value: number, styles: T) => T | null;
|
|
7
|
-
export declare const maxWidth: <T>(value: number, styles: T) => T | null;
|
|
8
|
-
export declare const minHeight: <T>(value: number, styles: T) => T | null;
|
|
9
|
-
export declare const minWidth: <T>(value: number, styles: T) => T | null;
|
|
10
|
-
export declare const minAspectRatio: <T>(value: number, styles: T) => T | null;
|
|
11
|
-
export declare const maxAspectRatio: <T>(value: number, styles: T) => T | null;
|
|
12
|
-
export declare const aspectRatio: <T>(value: number, styles: T) => T | null;
|
package/media-query/base.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { getWindowDimensions } from "../dimensions";
|
|
2
|
-
export const createDimensionQueryHelper = (queryFunction) => (value, styles) => {
|
|
3
|
-
const isMatched = queryFunction({
|
|
4
|
-
value,
|
|
5
|
-
dimensions: getWindowDimensions(),
|
|
6
|
-
});
|
|
7
|
-
if (isMatched) {
|
|
8
|
-
return styles;
|
|
9
|
-
}
|
|
10
|
-
return null;
|
|
11
|
-
};
|
|
12
|
-
export const maxHeight = createDimensionQueryHelper(({ value, dimensions }) => value >= dimensions.height);
|
|
13
|
-
export const maxWidth = createDimensionQueryHelper(({ value, dimensions }) => value >= dimensions.width);
|
|
14
|
-
export const minHeight = createDimensionQueryHelper(({ value, dimensions }) => value <= dimensions.height);
|
|
15
|
-
export const minWidth = createDimensionQueryHelper(({ value, dimensions }) => value <= dimensions.width);
|
|
16
|
-
export const minAspectRatio = createDimensionQueryHelper(({ value, dimensions: { width, height } }) => value <= width / height);
|
|
17
|
-
export const maxAspectRatio = createDimensionQueryHelper(({ value, dimensions: { width, height } }) => value >= width / height);
|
|
18
|
-
export const aspectRatio = createDimensionQueryHelper(({ value, dimensions: { width, height } }) => value === width / height);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface BreakpointsMatcher<TBreakpoints> {
|
|
2
|
-
<T>(values: {
|
|
3
|
-
[mode in keyof TBreakpoints]?: T;
|
|
4
|
-
}): T | undefined;
|
|
5
|
-
<T>(values: {
|
|
6
|
-
[mode in keyof TBreakpoints]?: T;
|
|
7
|
-
} & {
|
|
8
|
-
default: T;
|
|
9
|
-
}): T;
|
|
10
|
-
}
|
|
11
|
-
export declare function createBreakpointsMatcher<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints, matchFunction?: <T>(value: number, styles: T) => T | null): BreakpointsMatcher<TBreakpoints>;
|
|
12
|
-
export declare function createBreakpoints<TBreakpoints extends Record<string, number>>(breakpoints: TBreakpoints): {
|
|
13
|
-
up: <T>(key: keyof TBreakpoints, value: T) => T | null;
|
|
14
|
-
down: <T_1>(key: keyof TBreakpoints, value: T_1) => T_1 | null;
|
|
15
|
-
only: <T_2>(key: keyof TBreakpoints, value: T_2) => T_2 | null;
|
|
16
|
-
between: <T_3>(start: keyof TBreakpoints, end: keyof TBreakpoints, value: T_3) => T_3 | null;
|
|
17
|
-
};
|
|
18
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { minAspectRatio, minWidth, minHeight, maxWidth } from "./base";
|
|
2
|
-
const orderByMin = [minWidth, minAspectRatio, minHeight];
|
|
3
|
-
const toOrderedBreakpointNames = (values, breakpoints, matchFunction) => {
|
|
4
|
-
const result = Object.keys(values)
|
|
5
|
-
.filter((e) => e !== "default")
|
|
6
|
-
.sort((a, b) => breakpoints[a] - breakpoints[b]);
|
|
7
|
-
if (orderByMin.includes(matchFunction)) {
|
|
8
|
-
return result.slice().reverse();
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
/*
|
|
13
|
-
* To debug use analog on CSS: https://codepen.io/retyui/pen/dyOzKzV
|
|
14
|
-
*/
|
|
15
|
-
export function createBreakpointsMatcher(breakpoints, matchFunction = minWidth) {
|
|
16
|
-
return function breakpointsMatcher(values) {
|
|
17
|
-
/* istanbul ignore next */
|
|
18
|
-
// @ts-expect-error: was removed
|
|
19
|
-
if (process.env.NODE_ENV !== "production") {
|
|
20
|
-
const invalidKeys = Object.keys(values).filter((key) => {
|
|
21
|
-
return key !== "default" && breakpoints[key] === undefined;
|
|
22
|
-
});
|
|
23
|
-
if (invalidKeys.length > 0) {
|
|
24
|
-
console.warn(`[react-native-stylex]: Invalid values was passed to 'breakpointsMatcher' function
|
|
25
|
-
|
|
26
|
-
allowed keys: ${Object.keys(breakpoints).join(", ")}
|
|
27
|
-
unexpected keys: ${invalidKeys.join(", ")}
|
|
28
|
-
`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const orderedBreakpointNames = toOrderedBreakpointNames(values, breakpoints, matchFunction);
|
|
32
|
-
const key = orderedBreakpointNames.find((breakpointName) => matchFunction(breakpoints[breakpointName], values[breakpointName])) || "default";
|
|
33
|
-
return values[key] || null;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function getNextByKey(breakpoints, key) {
|
|
37
|
-
const breakpointsKeys = Object.keys(breakpoints).sort((a, b) => breakpoints[a] - breakpoints[b]);
|
|
38
|
-
const index = breakpointsKeys.indexOf(key);
|
|
39
|
-
const nextKey = breakpointsKeys[index + 1];
|
|
40
|
-
return nextKey;
|
|
41
|
-
}
|
|
42
|
-
export function createBreakpoints(breakpoints) {
|
|
43
|
-
function up(key, value) {
|
|
44
|
-
return minWidth(breakpoints[key], value);
|
|
45
|
-
}
|
|
46
|
-
function down(key, value) {
|
|
47
|
-
return maxWidth(breakpoints[key], value);
|
|
48
|
-
}
|
|
49
|
-
function only(key, value) {
|
|
50
|
-
const nextKey = getNextByKey(breakpoints, key);
|
|
51
|
-
if (nextKey !== undefined) {
|
|
52
|
-
return minWidth(breakpoints[key], maxWidth(breakpoints[nextKey] - 0.05, value));
|
|
53
|
-
}
|
|
54
|
-
return minWidth(breakpoints[key], value);
|
|
55
|
-
}
|
|
56
|
-
function between(start, end, value) {
|
|
57
|
-
return minWidth(breakpoints[start], maxWidth(breakpoints[end] - 0.05, value));
|
|
58
|
-
}
|
|
59
|
-
return { up, down, only, between };
|
|
60
|
-
}
|
package/media-query/index.d.ts
DELETED
package/media-query/index.js
DELETED
package/orientation.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type OrientationType = "portrait" | "landscape";
|
|
2
|
-
export declare function orientation<T>(spec: {
|
|
3
|
-
[orientation in OrientationType]?: T;
|
|
4
|
-
}): T | undefined;
|
|
5
|
-
export declare const portraitOrientation: <T>(portraitStyles: T) => T | undefined;
|
|
6
|
-
export declare const landscapeOrientation: <T>(landscapeStyles: T) => T | undefined;
|
|
7
|
-
export {};
|
package/orientation.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { getScreenDimensions } from "./dimensions";
|
|
2
|
-
export function orientation(spec) {
|
|
3
|
-
const { height, width } = getScreenDimensions();
|
|
4
|
-
return width <= height ? spec.portrait : spec.landscape;
|
|
5
|
-
}
|
|
6
|
-
export const portraitOrientation = (portraitStyles) => orientation({ portrait: portraitStyles });
|
|
7
|
-
export const landscapeOrientation = (landscapeStyles) => orientation({ landscape: landscapeStyles });
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { SafeAreaProvider as CoreSafeAreaProvider, initialWindowMetrics, initialWindowSafeAreaInsets, } from "react-native-safe-area-context";
|
|
3
|
-
import { StylexSaveAreaConsumer } from "./StylexSaveAreaConsumer";
|
|
4
|
-
export function SafeAreaProvider(props) {
|
|
5
|
-
return (<CoreSafeAreaProvider initialSafeAreaInsets={props.initialSafeAreaInsets || initialWindowSafeAreaInsets} initialMetrics={props.initialMetrics || initialWindowMetrics} {...props}>
|
|
6
|
-
{props.children}
|
|
7
|
-
<StylexSaveAreaConsumer />
|
|
8
|
-
</CoreSafeAreaProvider>);
|
|
9
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
|
-
import { emit } from "./eventEmitter";
|
|
3
|
-
import { state } from "./state";
|
|
4
|
-
import { useLayoutEffect } from "react";
|
|
5
|
-
export function StylexSaveAreaConsumer() {
|
|
6
|
-
const insets = useSafeAreaInsets();
|
|
7
|
-
useLayoutEffect(() => {
|
|
8
|
-
const isChanged = Object.entries(insets).some(([key, value]) => state.insets[key] !== value);
|
|
9
|
-
if (isChanged) {
|
|
10
|
-
state.insets = insets;
|
|
11
|
-
emit();
|
|
12
|
-
}
|
|
13
|
-
}, [insets]);
|
|
14
|
-
return null;
|
|
15
|
-
}
|
package/safe-area/consts.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SAFE_AREA_DEPENDENCY_KEY = "react-native-safe-area-context";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const emit: () => void, on: (callback: () => void) => () => void;
|
package/safe-area/index.d.ts
DELETED
package/safe-area/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import "./init";
|
|
2
|
-
import { onUse } from "../dependencyUsage";
|
|
3
|
-
import { SAFE_AREA_DEPENDENCY_KEY } from "./consts";
|
|
4
|
-
import { state } from "./state";
|
|
5
|
-
export { StylexSaveAreaConsumer } from "./StylexSaveAreaConsumer";
|
|
6
|
-
export { SafeAreaProvider } from "./SafeAreaProvider";
|
|
7
|
-
export function getSafeArea() {
|
|
8
|
-
onUse(SAFE_AREA_DEPENDENCY_KEY);
|
|
9
|
-
return state.insets;
|
|
10
|
-
}
|
package/safe-area/init.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/safe-area/init.js
DELETED
package/safe-area/state.d.ts
DELETED
package/safe-area/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/useColorTransition.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Animated } from "react-native";
|
|
2
|
-
import { DefaultTheme } from "./DefaultTheme";
|
|
3
|
-
export declare function useColorTransition<Theme = DefaultTheme>(colorGetterFn: (theme: Theme) => string, options?: {
|
|
4
|
-
duration: number;
|
|
5
|
-
}): Animated.AnimatedInterpolation<string>;
|
package/useColorTransition.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
-
import { Animated } from "react-native";
|
|
3
|
-
import { useTheme } from "./useTheme";
|
|
4
|
-
const { Value, timing } = Animated;
|
|
5
|
-
const INITIAL_VALUE = 0;
|
|
6
|
-
const defaultOptions = { duration: 250 };
|
|
7
|
-
export function useColorTransition(colorGetterFn, options = defaultOptions) {
|
|
8
|
-
const theme = useTheme();
|
|
9
|
-
const currentColor = colorGetterFn(theme);
|
|
10
|
-
const animatedValue = useRef(new Value(INITIAL_VALUE));
|
|
11
|
-
const colors = useRef({
|
|
12
|
-
toValue: INITIAL_VALUE,
|
|
13
|
-
prev: currentColor,
|
|
14
|
-
current: currentColor,
|
|
15
|
-
});
|
|
16
|
-
if (currentColor !== colors.current.current) {
|
|
17
|
-
colors.current = {
|
|
18
|
-
toValue: colors.current.toValue === 0 ? 1 : 0,
|
|
19
|
-
prev: colors.current.current,
|
|
20
|
-
current: currentColor,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const { toValue, prev, current } = colors.current;
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
timing(animatedValue.current, {
|
|
26
|
-
toValue,
|
|
27
|
-
useNativeDriver: false,
|
|
28
|
-
...options,
|
|
29
|
-
}).start();
|
|
30
|
-
}, [toValue]);
|
|
31
|
-
return useMemo(() => {
|
|
32
|
-
const outputRange = toValue === 1 ? [prev, current] : [current, prev];
|
|
33
|
-
return animatedValue.current.interpolate({
|
|
34
|
-
inputRange: [0, 1],
|
|
35
|
-
outputRange,
|
|
36
|
-
});
|
|
37
|
-
}, [prev, current]);
|
|
38
|
-
}
|
package/useTheme.d.ts
DELETED
package/useTheme.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { themeContext } from "./context";
|
|
3
|
-
export const useTheme = () => {
|
|
4
|
-
const contextValue = useContext(themeContext);
|
|
5
|
-
if (!contextValue) {
|
|
6
|
-
throw new Error("[react-native-stylex]: Please make sure that you wrapped your component with <ThemeProvider/>.");
|
|
7
|
-
}
|
|
8
|
-
return contextValue;
|
|
9
|
-
};
|
package/withStyles.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
interface InjectedStyledProps<Styles> {
|
|
3
|
-
styles: Styles;
|
|
4
|
-
}
|
|
5
|
-
export type InferInjectedStyledProps<Fn extends (...args: any) => any> = InjectedStyledProps<ReturnType<Fn>>;
|
|
6
|
-
export declare function withStyles<Styles>(useStyles: () => Styles): <TComponent extends React.ComponentType<any>>(Component: TComponent) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Omit<React.ComponentProps<TComponent>, "styles">> & React.RefAttributes<React.ElementRef<TComponent>>>;
|
|
7
|
-
export {};
|
package/withStyles.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import React, { forwardRef, } from "react";
|
|
3
|
-
export function withStyles(useStyles) {
|
|
4
|
-
function WithStyles(Component) {
|
|
5
|
-
const renderComponent = (props, ref) => {
|
|
6
|
-
const styles = useStyles();
|
|
7
|
-
// @ts-expect-error: 'ref' as never
|
|
8
|
-
return <Component {...props} ref={ref} styles={styles}/>;
|
|
9
|
-
};
|
|
10
|
-
return forwardRef(renderComponent);
|
|
11
|
-
}
|
|
12
|
-
return WithStyles;
|
|
13
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|