react-native-linear-gradient-fabric 0.1.0

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.
Files changed (31) hide show
  1. package/README.md +132 -0
  2. package/android/build.gradle +107 -0
  3. package/android/gradle.properties +4 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/com/lineargradientfabric/LinearGradientFabricPackage.kt +17 -0
  7. package/android/src/main/java/com/lineargradientfabric/LinearGradientView.kt +128 -0
  8. package/android/src/newarch/LinearGradientViewManager.kt +92 -0
  9. package/android/src/oldarch/LinearGradientViewManager.kt +82 -0
  10. package/ios/LinearGradientView.h +13 -0
  11. package/ios/LinearGradientView.m +145 -0
  12. package/ios/LinearGradientViewComponentView.h +13 -0
  13. package/ios/LinearGradientViewComponentView.mm +181 -0
  14. package/ios/LinearGradientViewManager.h +5 -0
  15. package/ios/LinearGradientViewManager.m +56 -0
  16. package/lib/commonjs/LinearGradientNativeComponent.js +10 -0
  17. package/lib/commonjs/LinearGradientNativeComponent.js.map +1 -0
  18. package/lib/commonjs/index.js +73 -0
  19. package/lib/commonjs/index.js.map +1 -0
  20. package/lib/module/LinearGradientNativeComponent.js +3 -0
  21. package/lib/module/LinearGradientNativeComponent.js.map +1 -0
  22. package/lib/module/index.js +64 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/typescript/src/LinearGradientNativeComponent.d.ts +39 -0
  25. package/lib/typescript/src/LinearGradientNativeComponent.d.ts.map +1 -0
  26. package/lib/typescript/src/index.d.ts +54 -0
  27. package/lib/typescript/src/index.d.ts.map +1 -0
  28. package/package.json +145 -0
  29. package/react-native-linear-gradient-fabric.podspec +20 -0
  30. package/src/LinearGradientNativeComponent.ts +43 -0
  31. package/src/index.tsx +128 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAKrE,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;OAGG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAiCD,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,SAAS,EACT,KAAqB,EACrB,GAAiB,EACjB,QAAgB,EAChB,KAAS,EACT,WAAkC,EAClC,KAAK,EACL,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,mBAAmB,GAAG,KAAK,CAAC,YAAY,CA0B1C;AAED,eAAe,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,145 @@
1
+ {
2
+ "name": "react-native-linear-gradient-fabric",
3
+ "version": "0.1.0",
4
+ "description": "A modern replacement for react-native-linear-gradient with full Fabric support",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/src/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!ios/build",
18
+ "!android/build",
19
+ "!android/.gradle",
20
+ "!android/.idea",
21
+ "!**/__tests__",
22
+ "!**/__fixtures__",
23
+ "!**/__mocks__",
24
+ "!**/.*"
25
+ ],
26
+ "scripts": {
27
+ "example:ios": "cd example && bun run ios",
28
+ "example:android": "cd example && bun run android",
29
+ "test": "jest",
30
+ "typecheck": "tsc --noEmit",
31
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
32
+ "lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
33
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
34
+ "prepare": "bob build",
35
+ "release": "release-it",
36
+ "release:beta": "release-it --preRelease=beta",
37
+ "release:dry": "release-it --dry-run"
38
+ },
39
+ "keywords": [
40
+ "react-native",
41
+ "ios",
42
+ "android",
43
+ "react-native-linear-gradient",
44
+ "linear-gradient",
45
+ "gradient",
46
+ "fabric",
47
+ "new-architecture"
48
+ ],
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/Yoon-SeungHwan/react-native-linear-gradient-fabric.git"
52
+ },
53
+ "author": "Seunghwan Yoon <hwani6736@gmail.com> (https://github.com/Yoon-SeungHwan)",
54
+ "license": "MIT",
55
+ "bugs": {
56
+ "url": "https://github.com/Yoon-SeungHwan/react-native-linear-gradient-fabric/issues"
57
+ },
58
+ "homepage": "https://github.com/Yoon-SeungHwan/react-native-linear-gradient-fabric#readme",
59
+ "publishConfig": {
60
+ "registry": "https://registry.npmjs.org/"
61
+ },
62
+ "devDependencies": {
63
+ "@commitlint/config-conventional": "^17.0.2",
64
+ "@evilmartians/lefthook": "^1.5.0",
65
+ "@react-native/eslint-config": "^0.73.1",
66
+ "@release-it/conventional-changelog": "^5.0.0",
67
+ "@types/jest": "^29.5.5",
68
+ "@types/react": "^18.2.44",
69
+ "commitlint": "^17.0.2",
70
+ "del-cli": "^5.1.0",
71
+ "eslint": "^8.51.0",
72
+ "eslint-config-prettier": "^9.0.0",
73
+ "eslint-plugin-import": "^2.29.0",
74
+ "eslint-plugin-prettier": "^5.0.1",
75
+ "jest": "^29.7.0",
76
+ "prettier": "^3.0.3",
77
+ "react": "18.2.0",
78
+ "react-native": "0.73.2",
79
+ "react-native-builder-bob": "^0.23.2",
80
+ "release-it": "^15.0.0",
81
+ "typescript": "^5.2.2"
82
+ },
83
+ "overrides": {
84
+ "execa": "^5.1.1"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "*",
88
+ "react-native": "*"
89
+ },
90
+ "jest": {
91
+ "preset": "react-native",
92
+ "modulePathIgnorePatterns": [
93
+ "<rootDir>/example/node_modules",
94
+ "<rootDir>/lib/"
95
+ ]
96
+ },
97
+ "commitlint": {
98
+ "extends": [
99
+ "@commitlint/config-conventional"
100
+ ]
101
+ },
102
+ "release-it": {
103
+ "git": {
104
+ "commitMessage": "chore: release ${version}",
105
+ "tagName": "v${version}"
106
+ },
107
+ "npm": {
108
+ "publish": true
109
+ },
110
+ "github": {
111
+ "release": true
112
+ },
113
+ "plugins": {
114
+ "@release-it/conventional-changelog": {
115
+ "preset": "angular"
116
+ }
117
+ },
118
+ "hooks": {
119
+ "before:init": [
120
+ "bun run lint",
121
+ "bun run typecheck"
122
+ ],
123
+ "after:bump": "bun run prepare"
124
+ }
125
+ },
126
+ "react-native-builder-bob": {
127
+ "source": "src",
128
+ "output": "lib",
129
+ "targets": [
130
+ "commonjs",
131
+ "module",
132
+ [
133
+ "typescript",
134
+ {
135
+ "project": "tsconfig.build.json"
136
+ }
137
+ ]
138
+ ]
139
+ },
140
+ "codegenConfig": {
141
+ "name": "RNLinearGradientFabricSpec",
142
+ "type": "components",
143
+ "jsSrcsDir": "src"
144
+ }
145
+ }
@@ -0,0 +1,20 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-linear-gradient-fabric"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => min_ios_version_supported }
15
+ s.source = { :git => "https://github.com/seunghwanyoon/react-native-linear-gradient-fabric.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm}"
18
+
19
+ install_modules_dependencies(s)
20
+ end
@@ -0,0 +1,43 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
3
+ import type { Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
4
+
5
+ export interface NativeLinearGradientPoint {
6
+ x: Float;
7
+ y: Float;
8
+ }
9
+
10
+ export interface NativeLinearGradientProps extends ViewProps {
11
+ /**
12
+ * An array of colors in integer format (processed by processColor)
13
+ */
14
+ colors: ReadonlyArray<Int32>;
15
+ /**
16
+ * An array of locations for each color stop, values should be between 0 and 1
17
+ */
18
+ locations?: ReadonlyArray<Float>;
19
+ /**
20
+ * The start point of the gradient (x: 0 = left, 1 = right; y: 0 = top, 1 = bottom)
21
+ */
22
+ startPoint?: NativeLinearGradientPoint;
23
+ /**
24
+ * The end point of the gradient (x: 0 = left, 1 = right; y: 0 = top, 1 = bottom)
25
+ */
26
+ endPoint?: NativeLinearGradientPoint;
27
+ /**
28
+ * If true, use angle instead of start/end points
29
+ */
30
+ useAngle?: boolean;
31
+ /**
32
+ * Angle of the gradient in degrees (0 = up, 90 = right, 180 = down, 270 = left)
33
+ */
34
+ angle?: Float;
35
+ /**
36
+ * The center point for the angle rotation
37
+ */
38
+ angleCenter?: NativeLinearGradientPoint;
39
+ }
40
+
41
+ export default codegenNativeComponent<NativeLinearGradientProps>(
42
+ 'LinearGradientView'
43
+ );
package/src/index.tsx ADDED
@@ -0,0 +1,128 @@
1
+ import * as React from 'react';
2
+ import type { ColorValue, StyleProp, ViewStyle } from 'react-native';
3
+ import { processColor, StyleSheet } from 'react-native';
4
+
5
+ import LinearGradientNativeComponent from './LinearGradientNativeComponent';
6
+
7
+ export interface Point {
8
+ x: number;
9
+ y: number;
10
+ }
11
+
12
+ export interface LinearGradientProps {
13
+ /**
14
+ * An array of at least 2 colors that represent gradient colors
15
+ */
16
+ colors: ColorValue[];
17
+ /**
18
+ * An array of locations for each color stop, values should be between 0 and 1
19
+ * The array length must match the colors array length
20
+ */
21
+ locations?: number[];
22
+ /**
23
+ * The start point of the gradient
24
+ * Default: { x: 0.5, y: 0 } (top center)
25
+ */
26
+ start?: Point;
27
+ /**
28
+ * The end point of the gradient
29
+ * Default: { x: 0.5, y: 1 } (bottom center)
30
+ */
31
+ end?: Point;
32
+ /**
33
+ * If true, use angle instead of start/end points
34
+ * Default: false
35
+ */
36
+ useAngle?: boolean;
37
+ /**
38
+ * Angle of the gradient in degrees (0 = up, 90 = right, 180 = down, 270 = left)
39
+ * Only used when useAngle is true
40
+ * Default: 0
41
+ */
42
+ angle?: number;
43
+ /**
44
+ * The center point for the angle rotation
45
+ * Default: { x: 0.5, y: 0.5 }
46
+ */
47
+ angleCenter?: Point;
48
+ /**
49
+ * Style for the gradient view
50
+ */
51
+ style?: StyleProp<ViewStyle>;
52
+ /**
53
+ * Children elements to render on top of the gradient
54
+ */
55
+ children?: React.ReactNode;
56
+ }
57
+
58
+ const DEFAULT_START: Point = { x: 0.5, y: 0 };
59
+ const DEFAULT_END: Point = { x: 0.5, y: 1 };
60
+ const DEFAULT_ANGLE_CENTER: Point = { x: 0.5, y: 0.5 };
61
+
62
+ function processColors(colors: ColorValue[]): number[] {
63
+ return colors.map((color) => {
64
+ const processed = processColor(color);
65
+ if (processed === null || processed === undefined) {
66
+ throw new Error(`Invalid color value: ${String(color)}`);
67
+ }
68
+ return typeof processed === 'number' ? processed : 0;
69
+ });
70
+ }
71
+
72
+ function validateLocations(
73
+ locations: number[] | undefined,
74
+ colorsLength: number
75
+ ): number[] | undefined {
76
+ if (!locations) {
77
+ return undefined;
78
+ }
79
+
80
+ if (locations.length !== colorsLength) {
81
+ console.warn(
82
+ `LinearGradient: locations array length (${locations.length}) does not match colors array length (${colorsLength})`
83
+ );
84
+ }
85
+
86
+ return locations;
87
+ }
88
+
89
+ export function LinearGradient({
90
+ colors,
91
+ locations,
92
+ start = DEFAULT_START,
93
+ end = DEFAULT_END,
94
+ useAngle = false,
95
+ angle = 0,
96
+ angleCenter = DEFAULT_ANGLE_CENTER,
97
+ style,
98
+ children,
99
+ ...rest
100
+ }: LinearGradientProps): React.ReactElement {
101
+ if (colors.length < 2) {
102
+ throw new Error('LinearGradient requires at least 2 colors');
103
+ }
104
+
105
+ const processedColors = React.useMemo(() => processColors(colors), [colors]);
106
+ const validatedLocations = React.useMemo(
107
+ () => validateLocations(locations, colors.length),
108
+ [locations, colors.length]
109
+ );
110
+
111
+ return (
112
+ <LinearGradientNativeComponent
113
+ {...rest}
114
+ style={StyleSheet.flatten(style)}
115
+ colors={processedColors}
116
+ locations={validatedLocations}
117
+ startPoint={start}
118
+ endPoint={end}
119
+ useAngle={useAngle}
120
+ angle={angle}
121
+ angleCenter={angleCenter}
122
+ >
123
+ {children}
124
+ </LinearGradientNativeComponent>
125
+ );
126
+ }
127
+
128
+ export default LinearGradient;