Explorar o código

Bugfix: webStyle type problems fixed.

lfabl hai 3 semanas
pai
achega
53746505ec
Modificáronse 4 ficheiros con 37 adicións e 3 borrados
  1. 2 1
      package.json
  2. 11 0
      src/index.tsx
  3. 17 1
      src/types/index.ts
  4. 7 1
      src/utils/index.ts

+ 2 - 1
package.json

@@ -37,7 +37,8 @@
         "clean": "del-cli lib",
         "lint": "eslint . --ext .ts,.tsx --fix",
         "prepare": "bob build && copyfiles -u 1 \"src/variants/**/*.json\" lib/typescript/src/ && node version.mjs",
-        "typecheck": "tsc -p tsconfig.build.json",
+        "type-check-build": "tsc -p tsconfig.build.json",
+        "type-check": "tsc --project tsconfig.json --noEmit",
         "release": "release-it --only-version",
         "build": "yarn clean && yarn lint && yarn typecheck && yarn prepare && npm publish"
     },

+ 11 - 0
src/index.tsx

@@ -120,10 +120,13 @@ export type {
     NCoreUIKitIcon,
     ModalDataType,
     SharpnessType,
+    PureWebStyles,
+    PureRNStyles,
     LocalizeType,
     PaletteType,
     ThemesType,
     LocaleType,
+    AllStyles,
     ThemeType,
     ModalType,
     Mutable
@@ -133,3 +136,11 @@ export {
     Portal,
     Host
 } from "./helpers/portalize";
+
+export {
+    androidTypographyFixer,
+    windowHeight,
+    windowWidth,
+    webStyle,
+    uuid
+} from "./utils";

+ 17 - 1
src/types/index.ts

@@ -1,6 +1,12 @@
 import {
-    type ForwardRefRenderFunction
+    type ForwardRefRenderFunction,
+    type CSSProperties
 } from "react";
+import type {
+    ImageStyle,
+    TextStyle,
+    ViewStyle
+} from "react-native";
 import {
     type INCoreUIKitIconCallbackProps
 } from "./icon";
@@ -57,6 +63,16 @@ export type {
     ThemeType
 };
 
+export type PureRNStyles = Omit<ViewStyle & TextStyle & ImageStyle, "position" | "cursor" | "filter">;
+
+export type PureWebStyles = Omit<CSSProperties, "position" | "cursor" | "filter">;
+
+export type AllStyles = PureRNStyles & PureWebStyles & {
+    position?: CSSProperties["position"];
+    cursor?: CSSProperties["cursor"];
+    filter?: string;
+};
+
 export type RecursiveRecord = {
   [key: string]: string | RecursiveRecord;
 };

+ 7 - 1
src/utils/index.ts

@@ -1,14 +1,20 @@
 import {
+    type ViewStyle,
     Dimensions,
     Platform
 } from "react-native";
+import type {
+    AllStyles
+} from "../types";
 
 const dimensions = Dimensions.get("window");
 
 export const windowHeight = dimensions.height;
 export const windowWidth = dimensions.width;
 
-export const webStyle = (styles: Record<string, unknown>): Record<string, unknown> => Platform.OS === "web" ? styles : {};
+export const webStyle = <T extends AllStyles>(styles: T): ViewStyle => {
+    return (Platform.OS === "web" ? styles : {}) as unknown as ViewStyle;
+};
 
 export const uuid = () => {
     return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {