@mgcrea/react-native-tailwind 0.5.0 → 0.5.2

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.
@@ -1,12 +1,5 @@
1
- import { setPlatform } from "test/mocks/react-native";
2
- import { beforeEach, describe, expect, it } from "vitest";
3
- import { SHADOW_SCALE, parseShadow, rebuildShadowScale } from "./shadows";
4
-
5
- // Reset to iOS before each test
6
- beforeEach(() => {
7
- setPlatform("ios");
8
- rebuildShadowScale();
9
- });
1
+ import { describe, expect, it } from "vitest";
2
+ import { SHADOW_SCALE, parseShadow } from "./shadows";
10
3
 
11
4
  describe("SHADOW_SCALE", () => {
12
5
  it("should export complete shadow scale", () => {
@@ -71,10 +64,6 @@ describe("parseShadow - basic shadows", () => {
71
64
  });
72
65
 
73
66
  describe("parseShadow - shadow properties (iOS)", () => {
74
- beforeEach(() => {
75
- setPlatform("ios");
76
- });
77
-
78
67
  it("should have increasing shadow values for larger shadows", () => {
79
68
  const sm = parseShadow("shadow-sm");
80
69
  const md = parseShadow("shadow-md");
@@ -104,24 +93,28 @@ describe("parseShadow - shadow properties (iOS)", () => {
104
93
 
105
94
  it("should have proper shadowOffset structure", () => {
106
95
  const result = parseShadow("shadow");
107
- expect(result?.shadowOffset).toHaveProperty("width");
108
- expect(result?.shadowOffset).toHaveProperty("height");
109
- expect(typeof result?.shadowOffset?.width).toBe("number");
110
- expect(typeof result?.shadowOffset?.height).toBe("number");
96
+ const shadowOffset = result?.shadowOffset;
97
+ expect(shadowOffset).toHaveProperty("width");
98
+ expect(shadowOffset).toHaveProperty("height");
99
+ if (typeof shadowOffset === "object" && shadowOffset !== null) {
100
+ expect(typeof shadowOffset.width).toBe("number");
101
+ expect(typeof shadowOffset.height).toBe("number");
102
+ }
111
103
  });
112
104
 
113
- it("should not have elevation property on iOS", () => {
105
+ it("should include both iOS shadow and Android elevation properties", () => {
114
106
  const result = parseShadow("shadow");
115
- expect(result).not.toHaveProperty("elevation");
107
+ // iOS properties
108
+ expect(result).toHaveProperty("shadowColor");
109
+ expect(result).toHaveProperty("shadowOffset");
110
+ expect(result).toHaveProperty("shadowOpacity");
111
+ expect(result).toHaveProperty("shadowRadius");
112
+ // Android property
113
+ expect(result).toHaveProperty("elevation");
116
114
  });
117
115
  });
118
116
 
119
117
  describe("parseShadow - shadow properties (Android)", () => {
120
- beforeEach(() => {
121
- setPlatform("android");
122
- rebuildShadowScale();
123
- });
124
-
125
118
  it("should have increasing elevation values for larger shadows", () => {
126
119
  const sm = parseShadow("shadow-sm");
127
120
  const md = parseShadow("shadow-md");
@@ -136,12 +129,10 @@ describe("parseShadow - shadow properties (Android)", () => {
136
129
  expect(xxl?.elevation).toBeGreaterThan(xl?.elevation as number);
137
130
  });
138
131
 
139
- it("should not have shadow properties on Android", () => {
132
+ it("should include elevation property for Android", () => {
140
133
  const result = parseShadow("shadow");
141
- expect(result).not.toHaveProperty("shadowColor");
142
- expect(result).not.toHaveProperty("shadowOffset");
143
- expect(result).not.toHaveProperty("shadowOpacity");
144
- expect(result).not.toHaveProperty("shadowRadius");
134
+ expect(result).toHaveProperty("elevation");
135
+ expect(typeof result?.elevation).toBe("number");
145
136
  });
146
137
  });
147
138
 
@@ -3,117 +3,68 @@
3
3
  * iOS uses shadow* properties, Android uses elevation
4
4
  */
5
5
 
6
- import { Platform } from "react-native";
7
6
  import type { StyleObject } from "../types";
8
7
 
9
8
  /**
10
- * Shadow scale definitions (raw values, not platform-specific)
9
+ * Shadow scale definitions combining iOS and Android properties
11
10
  * Based on Tailwind CSS shadow scale, adapted for React Native
11
+ *
12
+ * Note: We include BOTH iOS shadow properties AND Android elevation in each style.
13
+ * React Native will automatically use the appropriate properties for each platform:
14
+ * - iOS uses shadowColor, shadowOffset, shadowOpacity, shadowRadius
15
+ * - Android uses elevation
12
16
  */
13
- const SHADOW_DEFINITIONS = {
17
+ const SHADOW_SCALE: Record<string, StyleObject> = {
14
18
  "shadow-sm": {
15
- ios: {
16
- shadowColor: "#000000",
17
- shadowOffset: { width: 0, height: 1 },
18
- shadowOpacity: 0.05,
19
- shadowRadius: 1,
20
- },
21
- android: {
22
- elevation: 1,
23
- },
19
+ shadowColor: "#000000",
20
+ shadowOffset: { width: 0, height: 1 },
21
+ shadowOpacity: 0.05,
22
+ shadowRadius: 1,
23
+ elevation: 1,
24
24
  },
25
25
  shadow: {
26
- ios: {
27
- shadowColor: "#000000",
28
- shadowOffset: { width: 0, height: 1 },
29
- shadowOpacity: 0.1,
30
- shadowRadius: 2,
31
- },
32
- android: {
33
- elevation: 2,
34
- },
26
+ shadowColor: "#000000",
27
+ shadowOffset: { width: 0, height: 1 },
28
+ shadowOpacity: 0.1,
29
+ shadowRadius: 2,
30
+ elevation: 2,
35
31
  },
36
32
  "shadow-md": {
37
- ios: {
38
- shadowColor: "#000000",
39
- shadowOffset: { width: 0, height: 3 },
40
- shadowOpacity: 0.15,
41
- shadowRadius: 4,
42
- },
43
- android: {
44
- elevation: 4,
45
- },
33
+ shadowColor: "#000000",
34
+ shadowOffset: { width: 0, height: 3 },
35
+ shadowOpacity: 0.15,
36
+ shadowRadius: 4,
37
+ elevation: 4,
46
38
  },
47
39
  "shadow-lg": {
48
- ios: {
49
- shadowColor: "#000000",
50
- shadowOffset: { width: 0, height: 6 },
51
- shadowOpacity: 0.2,
52
- shadowRadius: 8,
53
- },
54
- android: {
55
- elevation: 8,
56
- },
40
+ shadowColor: "#000000",
41
+ shadowOffset: { width: 0, height: 6 },
42
+ shadowOpacity: 0.2,
43
+ shadowRadius: 8,
44
+ elevation: 8,
57
45
  },
58
46
  "shadow-xl": {
59
- ios: {
60
- shadowColor: "#000000",
61
- shadowOffset: { width: 0, height: 10 },
62
- shadowOpacity: 0.25,
63
- shadowRadius: 12,
64
- },
65
- android: {
66
- elevation: 12,
67
- },
47
+ shadowColor: "#000000",
48
+ shadowOffset: { width: 0, height: 10 },
49
+ shadowOpacity: 0.25,
50
+ shadowRadius: 12,
51
+ elevation: 12,
68
52
  },
69
53
  "shadow-2xl": {
70
- ios: {
71
- shadowColor: "#000000",
72
- shadowOffset: { width: 0, height: 20 },
73
- shadowOpacity: 0.3,
74
- shadowRadius: 24,
75
- },
76
- android: {
77
- elevation: 16,
78
- },
54
+ shadowColor: "#000000",
55
+ shadowOffset: { width: 0, height: 20 },
56
+ shadowOpacity: 0.3,
57
+ shadowRadius: 24,
58
+ elevation: 16,
79
59
  },
80
60
  "shadow-none": {
81
- ios: {
82
- shadowColor: "transparent",
83
- shadowOffset: { width: 0, height: 0 },
84
- shadowOpacity: 0,
85
- shadowRadius: 0,
86
- },
87
- android: {
88
- elevation: 0,
89
- },
61
+ shadowColor: "transparent",
62
+ shadowOffset: { width: 0, height: 0 },
63
+ shadowOpacity: 0,
64
+ shadowRadius: 0,
65
+ elevation: 0,
90
66
  },
91
- } as const;
92
-
93
- /**
94
- * Helper function to build the shadow scale using Platform.select()
95
- * This allows tests to rebuild the scale after changing the platform mock
96
- */
97
- function buildShadowScale(): Record<string, StyleObject> {
98
- const scale: Record<string, StyleObject> = {};
99
- for (const [key, value] of Object.entries(SHADOW_DEFINITIONS)) {
100
- scale[key] = Platform.select<StyleObject>(value as never);
101
- }
102
- return scale;
103
- }
104
-
105
- /**
106
- * Computed shadow scale using Platform.select()
107
- * This is evaluated at module load time for production use
108
- */
109
- let SHADOW_SCALE = buildShadowScale();
110
-
111
- /**
112
- * Rebuild the shadow scale (useful for testing with platform mocks)
113
- */
114
- export function rebuildShadowScale() {
115
- SHADOW_SCALE = buildShadowScale();
116
- }
67
+ };
117
68
 
118
69
  /**
119
70
  * Parse shadow classes
@@ -129,5 +80,5 @@ export function parseShadow(cls: string): StyleObject | null {
129
80
  return null;
130
81
  }
131
82
 
132
- // Export shadow scale and builder for testing/advanced usage
133
- export { buildShadowScale, SHADOW_SCALE };
83
+ // Export shadow scale for testing/advanced usage
84
+ export { SHADOW_SCALE };
@@ -69,7 +69,7 @@ declare module "react-native" {
69
69
  className?: string;
70
70
  }
71
71
 
72
- interface FlatListProps<_ItemT> {
72
+ interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
73
73
  /**
74
74
  * Tailwind-like class names for styling
75
75
  * @example
package/src/types.ts CHANGED
@@ -6,9 +6,7 @@ import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
6
6
 
7
7
  export type RNStyle = ViewStyle | TextStyle | ImageStyle;
8
8
 
9
- export type StyleObject = Record<Exclude<string, "shadowOffset">, string | number | undefined> & {
10
- shadowOffset?: { width: number; height: number };
11
- };
9
+ export type StyleObject = Record<string, string | number | { width: number; height: number } | undefined>;
12
10
 
13
11
  export type SpacingValue = number;
14
12
  export type ColorValue = string;