expo-linear-gradient 10.0.2 → 11.2.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 (35) hide show
  1. package/CHANGELOG.md +17 -2
  2. package/README.md +3 -3
  3. package/android/build.gradle +8 -4
  4. package/android/src/main/java/expo/modules/lineargradient/LinearGradientModule.kt +39 -0
  5. package/android/src/main/java/expo/modules/lineargradient/LinearGradientView.java +25 -39
  6. package/build/LinearGradient.d.ts +5 -0
  7. package/build/LinearGradient.d.ts.map +1 -0
  8. package/build/LinearGradient.js.map +1 -1
  9. package/build/NativeLinearGradient.android.d.ts +1 -0
  10. package/build/NativeLinearGradient.android.d.ts.map +1 -0
  11. package/build/NativeLinearGradient.d.ts +1 -0
  12. package/build/NativeLinearGradient.d.ts.map +1 -0
  13. package/build/NativeLinearGradient.ios.d.ts +1 -0
  14. package/build/NativeLinearGradient.ios.d.ts.map +1 -0
  15. package/build/NativeLinearGradient.types.d.ts +1 -0
  16. package/build/NativeLinearGradient.types.d.ts.map +1 -0
  17. package/build/NativeLinearGradient.web.d.ts +1 -0
  18. package/build/NativeLinearGradient.web.d.ts.map +1 -0
  19. package/expo-module.config.json +3 -0
  20. package/ios/{EXLinearGradient.podspec → ExpoLinearGradient.podspec} +5 -4
  21. package/ios/LinearGradientLayer.swift +107 -0
  22. package/ios/LinearGradientModule.swift +32 -0
  23. package/ios/LinearGradientView.swift +13 -0
  24. package/package.json +5 -5
  25. package/src/LinearGradient.tsx +4 -0
  26. package/android/src/main/java/expo/modules/lineargradient/LinearGradientManager.java +0 -60
  27. package/android/src/main/java/expo/modules/lineargradient/LinearGradientPackage.java +0 -16
  28. package/ios/EXLinearGradient/EXLinearGradient.h +0 -12
  29. package/ios/EXLinearGradient/EXLinearGradient.m +0 -53
  30. package/ios/EXLinearGradient/EXLinearGradientLayer.h +0 -14
  31. package/ios/EXLinearGradient/EXLinearGradientLayer.m +0 -110
  32. package/ios/EXLinearGradient/EXLinearGradientManager.h +0 -8
  33. package/ios/EXLinearGradient/EXLinearGradientManager.m +0 -45
  34. package/ios/EXLinearGradient/LinearGradientModule.swift +0 -29
  35. package/unimodule.json +0 -4
package/CHANGELOG.md CHANGED
@@ -10,9 +10,24 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 10.0.22021-10-15
13
+ ## 11.2.0 — 2022-01-26
14
14
 
15
- _This version does not introduce any user-facing changes._
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix display issue on iOS when more than 2 colors are used without explicit locations. ([#15955](https://github.com/expo/expo/pull/15955) by [@kbrandwijk](https://github.com/kbrandwijk))
18
+
19
+ ## 11.1.0 — 2022-01-26
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - Prevent crashes by adding unimplemented `CALayer` initializer `init(layer:)`. ([#15843](https://github.com/expo/expo/pull/15843) by [@dillonhafer](https://github.com/dillonhafer))
24
+
25
+ ## 11.0.0 — 2021-12-03
26
+
27
+ ### 💡 Others
28
+
29
+ - Rewrote code to Swift, removed legacy Objective-C module implementation and changed the pod name to `ExpoLinearGradient`. ([#15168](https://github.com/expo/expo/pull/15168) by [@tsapeta](https://github.com/tsapeta))
30
+ - Rewrote module using Sweet API on Android. ([#15166](https://github.com/expo/expo/pull/15166) by [@lukmccall](https://github.com/lukmccall))
16
31
 
17
32
  ## 10.0.1 — 2021-10-01
18
33
 
package/README.md CHANGED
@@ -4,16 +4,16 @@ Provides a React component that renders a gradient view.
4
4
 
5
5
  # API documentation
6
6
 
7
- - [Documentation for the master branch](https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/sdk/linear-gradient.md)
7
+ - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/linear-gradient.md)
8
8
  - [Documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/linear-gradient/)
9
9
 
10
10
  # Installation in managed Expo projects
11
11
 
12
- For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/linear-gradient/).
12
+ For [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/linear-gradient/).
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Add the package to your npm dependencies
19
19
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '10.0.2'
6
+ version = '11.2.0'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -16,7 +16,7 @@ buildscript {
16
16
  }
17
17
 
18
18
  dependencies {
19
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
19
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.6.10')}")
20
20
  }
21
21
  }
22
22
 
@@ -53,11 +53,15 @@ android {
53
53
  targetCompatibility JavaVersion.VERSION_1_8
54
54
  }
55
55
 
56
+ kotlinOptions {
57
+ jvmTarget = JavaVersion.VERSION_1_8
58
+ }
59
+
56
60
  defaultConfig {
57
61
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
62
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
63
  versionCode 17
60
- versionName "10.0.2"
64
+ versionName "11.2.0"
61
65
  }
62
66
  lintOptions {
63
67
  abortOnError false
@@ -67,5 +71,5 @@ android {
67
71
  dependencies {
68
72
  implementation project(':expo-modules-core')
69
73
 
70
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
74
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.6.10')}"
71
75
  }
@@ -0,0 +1,39 @@
1
+ package expo.modules.lineargradient
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+
6
+ typealias ViewType = LinearGradientView
7
+
8
+ class LinearGradientModule : Module() {
9
+ override fun definition() = ModuleDefinition {
10
+ name("ExpoLinearGradient")
11
+ viewManager {
12
+ view { context ->
13
+ LinearGradientView(context)
14
+ }
15
+
16
+ prop("colors") { view: ViewType, colors: IntArray ->
17
+ view.setColors(colors)
18
+ }
19
+
20
+ prop("locations") { view: ViewType, locations: FloatArray? ->
21
+ locations?.let {
22
+ view.setLocations(it)
23
+ }
24
+ }
25
+
26
+ prop("startPoint") { view: ViewType, startPoint: Pair<Float, Float>? ->
27
+ view.setStartPosition(startPoint?.first ?: 0.5f, startPoint?.second ?: 0f)
28
+ }
29
+
30
+ prop("endPoint") { view: ViewType, endPoint: Pair<Float, Float>? ->
31
+ view.setEndPosition(endPoint?.first ?: 0.5f, endPoint?.second ?: 1f)
32
+ }
33
+
34
+ prop("borderRadii") { view: ViewType, borderRadii: FloatArray? ->
35
+ view.setBorderRadii(borderRadii ?: FloatArray(8) { 0f })
36
+ }
37
+ }
38
+ }
39
+ }
@@ -1,7 +1,5 @@
1
1
  package expo.modules.lineargradient;
2
2
 
3
- import java.util.ArrayList;
4
-
5
3
  import android.content.Context;
6
4
  import android.graphics.Canvas;
7
5
  import android.graphics.LinearGradient;
@@ -28,43 +26,31 @@ public class LinearGradientView extends View {
28
26
  super(context);
29
27
  }
30
28
 
31
- public void setStartPosition(final ArrayList<Double> startPos) {
32
- mStartPos = new float[]{startPos.get(0).floatValue(), startPos.get(1).floatValue()};
29
+ public void setStartPosition(final float x, final float y) {
30
+ mStartPos = new float[]{x, y};
33
31
  drawGradient();
34
32
  }
35
33
 
36
- public void setEndPosition(final ArrayList<Double> endPos) {
37
- mEndPos = new float[]{endPos.get(0).floatValue(), endPos.get(1).floatValue()};
34
+ public void setEndPosition(final float x, final float y) {
35
+ mEndPos = new float[]{x, y};
38
36
  drawGradient();
39
37
  }
40
38
 
41
- public void setColors(final ArrayList<Double> colors) {
42
- int[] _colors = new int[colors.size()];
43
- for (int i=0; i < _colors.length; i++)
44
- {
45
- _colors[i] = colors.get(i).intValue();
46
- }
47
- mColors = _colors;
39
+ public void setColors(final int[] colors) {
40
+ mColors = colors;
48
41
  drawGradient();
49
42
  }
50
43
 
51
- public void setLocations(final ArrayList<Double> locations) {
52
- float[] _locations = new float[locations.size()];
53
- for (int i=0; i < _locations.length; i++)
54
- {
55
- _locations[i] = locations.get(i).floatValue();
56
- }
57
- mLocations = _locations;
44
+ public void setLocations(final float[] locations) {
45
+ mLocations = locations;
58
46
  drawGradient();
59
47
  }
60
48
 
61
- public void setBorderRadii(final ArrayList<Double> borderRadii) {
62
- float[] _radii = new float[borderRadii.size()];
63
- for (int i=0; i < _radii.length; i++)
64
- {
65
- _radii[i] = toPixelFromDIP(borderRadii.get(i).floatValue());
49
+ public void setBorderRadii(final float[] borderRadii) {
50
+ for (int i = 0; i < borderRadii.length; i++) {
51
+ borderRadii[i] = toPixelFromDIP(borderRadii[i]);
66
52
  }
67
- mBorderRadii = _radii;
53
+ mBorderRadii = borderRadii;
68
54
  updatePath();
69
55
  drawGradient();
70
56
  }
@@ -74,9 +60,9 @@ public class LinearGradientView extends View {
74
60
  // having code similar to this littered throughout modules
75
61
  private float toPixelFromDIP(float value) {
76
62
  return TypedValue.applyDimension(
77
- TypedValue.COMPLEX_UNIT_DIP,
78
- value,
79
- getContext().getResources().getDisplayMetrics()
63
+ TypedValue.COMPLEX_UNIT_DIP,
64
+ value,
65
+ getContext().getResources().getDisplayMetrics()
80
66
  );
81
67
  }
82
68
 
@@ -92,13 +78,13 @@ public class LinearGradientView extends View {
92
78
  if (mColors == null || (mLocations != null && mColors.length != mLocations.length))
93
79
  return;
94
80
  LinearGradient mShader = new LinearGradient(
95
- mStartPos[0] * mSize[0],
96
- mStartPos[1] * mSize[1],
97
- mEndPos[0] * mSize[0],
98
- mEndPos[1] * mSize[1],
99
- mColors,
100
- mLocations,
101
- Shader.TileMode.CLAMP);
81
+ mStartPos[0] * mSize[0],
82
+ mStartPos[1] * mSize[1],
83
+ mEndPos[0] * mSize[0],
84
+ mEndPos[1] * mSize[1],
85
+ mColors,
86
+ mLocations,
87
+ Shader.TileMode.CLAMP);
102
88
  mPaint.setShader(mShader);
103
89
  invalidate();
104
90
  }
@@ -111,9 +97,9 @@ public class LinearGradientView extends View {
111
97
  mPathForBorderRadius.reset();
112
98
  mTempRectForBorderRadius.set(0f, 0f, (float) mSize[0], (float) mSize[1]);
113
99
  mPathForBorderRadius.addRoundRect(
114
- mTempRectForBorderRadius,
115
- mBorderRadii,
116
- Path.Direction.CW);
100
+ mTempRectForBorderRadius,
101
+ mBorderRadii,
102
+ Path.Direction.CW);
117
103
  }
118
104
 
119
105
  @Override
@@ -25,6 +25,7 @@ export declare type LinearGradientProps = ViewProps & {
25
25
  /**
26
26
  * An array that contains `number`s ranging from `0` to `1`, inclusive, and is the same length as the `colors` property.
27
27
  * Each number indicates a color-stop location where each respective color should be located.
28
+ * If not specified, the colors will be distributed evenly across the gradient.
28
29
  *
29
30
  * For example, `[0.5, 0.8]` would render:
30
31
  * - the first color, solid, from the beginning of the gradient view to 50% through (the middle);
@@ -32,18 +33,21 @@ export declare type LinearGradientProps = ViewProps & {
32
33
  * - the second color, solid, from the 80% point to the end of the gradient view.
33
34
  *
34
35
  * > The color-stop locations must be ascending from least to greatest.
36
+ * @default []
35
37
  */
36
38
  locations?: number[] | null;
37
39
  /**
38
40
  * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will start `10%` from the left and `20%` from the top.
39
41
  *
40
42
  * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the starting position.
43
+ * @default { x: 0.5, y: 0.0 }
41
44
  */
42
45
  start?: LinearGradientPoint | null;
43
46
  /**
44
47
  * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will end `10%` from the left and `20%` from the bottom.
45
48
  *
46
49
  * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the end position.
50
+ * @default { x: 0.5, y: 1.0 }
47
51
  */
48
52
  end?: LinearGradientPoint | null;
49
53
  };
@@ -53,3 +57,4 @@ export declare type LinearGradientProps = ViewProps & {
53
57
  export declare class LinearGradient extends React.Component<LinearGradientProps> {
54
58
  render(): JSX.Element;
55
59
  }
60
+ //# sourceMappingURL=LinearGradient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinearGradient.d.ts","sourceRoot":"","sources":["../src/LinearGradient.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAA0B,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAGzE;;;;GAIG;AACH,oBAAY,mBAAmB,GAC3B;IACE;;OAEG;IACH,CAAC,EAAE,MAAM,CAAC;IACV;;OAEG;IACH,CAAC,EAAE,MAAM,CAAC;CACX,GACD,yBAAyB,CAAC;AAG9B,oBAAY,mBAAmB,GAAG,SAAS,GAAG;IAC5C;;;OAGG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC5B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACnC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;IACtE,MAAM;CAqBP"}
@@ -1 +1 @@
1
- {"version":3,"file":"LinearGradient.js","sourceRoot":"","sources":["../src/LinearGradient.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAa,MAAM,cAAc,CAAC;AAEjE,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAuD1D;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK,CAAC,SAA8B;IACtE,MAAM;QACJ,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC/D,IAAI,iBAAiB,GAAG,SAAS,CAAC;QAClC,IAAI,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE;YACnD,OAAO,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAC;YAC9F,iBAAiB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SACvD;QAED,OAAO,CACL,oBAAC,oBAAoB,OACf,KAAK,EACT,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;gBACtB,GAAG,EAAE,MAAa;gBAClB,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC;aAClC,CAAC,EACF,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,EAClC,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,GAC9B,CACH,CAAC;IACJ,CAAC;CACF;AAED,SAAS,eAAe,CACtB,KAA6C;IAE7C,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9C,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC7F,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import * as React from 'react';\nimport { Platform, processColor, ViewProps } from 'react-native';\n\nimport NativeLinearGradient from './NativeLinearGradient';\nimport { NativeLinearGradientPoint } from './NativeLinearGradient.types';\n\n// @needsAudit\n/**\n * An object `{ x: number; y: number }` or array `[x, y]` that represents the point\n * at which the gradient starts or ends, as a fraction of the overall size of the gradient ranging\n * from `0` to `1`, inclusive.\n */\nexport type LinearGradientPoint =\n | {\n /**\n * A number ranging from `0` to `1`, representing the position of gradient transformation.\n */\n x: number;\n /**\n * A number ranging from `0` to `1`, representing the position of gradient transformation.\n */\n y: number;\n }\n | NativeLinearGradientPoint;\n\n// @needsAudit\nexport type LinearGradientProps = ViewProps & {\n /**\n * An array of colors that represent stops in the gradient. At least two colors are required\n * (for a single-color background, use the `style.backgroundColor` prop on a `View` component).\n */\n colors: string[];\n /**\n * An array that contains `number`s ranging from `0` to `1`, inclusive, and is the same length as the `colors` property.\n * Each number indicates a color-stop location where each respective color should be located.\n *\n * For example, `[0.5, 0.8]` would render:\n * - the first color, solid, from the beginning of the gradient view to 50% through (the middle);\n * - a gradient from the first color to the second from the 50% point to the 80% point; and\n * - the second color, solid, from the 80% point to the end of the gradient view.\n *\n * > The color-stop locations must be ascending from least to greatest.\n */\n locations?: number[] | null;\n /**\n * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will start `10%` from the left and `20%` from the top.\n *\n * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the starting position.\n */\n start?: LinearGradientPoint | null;\n /**\n * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will end `10%` from the left and `20%` from the bottom.\n *\n * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the end position.\n */\n end?: LinearGradientPoint | null;\n};\n\n/**\n * Renders a native view that transitions between multiple colors in a linear direction.\n */\nexport class LinearGradient extends React.Component<LinearGradientProps> {\n render() {\n const { colors, locations, start, end, ...props } = this.props;\n let resolvedLocations = locations;\n if (locations && colors.length !== locations.length) {\n console.warn('LinearGradient colors and locations props should be arrays of the same length');\n resolvedLocations = locations.slice(0, colors.length);\n }\n\n return (\n <NativeLinearGradient\n {...props}\n colors={Platform.select({\n web: colors as any,\n default: colors.map(processColor),\n })}\n locations={resolvedLocations}\n startPoint={_normalizePoint(start)}\n endPoint={_normalizePoint(end)}\n />\n );\n }\n}\n\nfunction _normalizePoint(\n point: LinearGradientPoint | null | undefined\n): NativeLinearGradientPoint | undefined {\n if (!point) {\n return undefined;\n }\n\n if (Array.isArray(point) && point.length !== 2) {\n console.warn('start and end props for LinearGradient must be of the format [x,y] or {x, y}');\n return undefined;\n }\n\n return Array.isArray(point) ? point : [point.x, point.y];\n}\n"]}
1
+ {"version":3,"file":"LinearGradient.js","sourceRoot":"","sources":["../src/LinearGradient.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAa,MAAM,cAAc,CAAC;AAEjE,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AA2D1D;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK,CAAC,SAA8B;IACtE,MAAM;QACJ,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC/D,IAAI,iBAAiB,GAAG,SAAS,CAAC;QAClC,IAAI,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE;YACnD,OAAO,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAC;YAC9F,iBAAiB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SACvD;QAED,OAAO,CACL,oBAAC,oBAAoB,OACf,KAAK,EACT,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;gBACtB,GAAG,EAAE,MAAa;gBAClB,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC;aAClC,CAAC,EACF,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,EAClC,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,GAC9B,CACH,CAAC;IACJ,CAAC;CACF;AAED,SAAS,eAAe,CACtB,KAA6C;IAE7C,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9C,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC7F,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import * as React from 'react';\nimport { Platform, processColor, ViewProps } from 'react-native';\n\nimport NativeLinearGradient from './NativeLinearGradient';\nimport { NativeLinearGradientPoint } from './NativeLinearGradient.types';\n\n// @needsAudit\n/**\n * An object `{ x: number; y: number }` or array `[x, y]` that represents the point\n * at which the gradient starts or ends, as a fraction of the overall size of the gradient ranging\n * from `0` to `1`, inclusive.\n */\nexport type LinearGradientPoint =\n | {\n /**\n * A number ranging from `0` to `1`, representing the position of gradient transformation.\n */\n x: number;\n /**\n * A number ranging from `0` to `1`, representing the position of gradient transformation.\n */\n y: number;\n }\n | NativeLinearGradientPoint;\n\n// @needsAudit\nexport type LinearGradientProps = ViewProps & {\n /**\n * An array of colors that represent stops in the gradient. At least two colors are required\n * (for a single-color background, use the `style.backgroundColor` prop on a `View` component).\n */\n colors: string[];\n /**\n * An array that contains `number`s ranging from `0` to `1`, inclusive, and is the same length as the `colors` property.\n * Each number indicates a color-stop location where each respective color should be located.\n * If not specified, the colors will be distributed evenly across the gradient.\n *\n * For example, `[0.5, 0.8]` would render:\n * - the first color, solid, from the beginning of the gradient view to 50% through (the middle);\n * - a gradient from the first color to the second from the 50% point to the 80% point; and\n * - the second color, solid, from the 80% point to the end of the gradient view.\n *\n * > The color-stop locations must be ascending from least to greatest.\n * @default []\n */\n locations?: number[] | null;\n /**\n * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will start `10%` from the left and `20%` from the top.\n *\n * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the starting position.\n * @default { x: 0.5, y: 0.0 }\n */\n start?: LinearGradientPoint | null;\n /**\n * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will end `10%` from the left and `20%` from the bottom.\n *\n * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the end position.\n * @default { x: 0.5, y: 1.0 }\n */\n end?: LinearGradientPoint | null;\n};\n\n/**\n * Renders a native view that transitions between multiple colors in a linear direction.\n */\nexport class LinearGradient extends React.Component<LinearGradientProps> {\n render() {\n const { colors, locations, start, end, ...props } = this.props;\n let resolvedLocations = locations;\n if (locations && colors.length !== locations.length) {\n console.warn('LinearGradient colors and locations props should be arrays of the same length');\n resolvedLocations = locations.slice(0, colors.length);\n }\n\n return (\n <NativeLinearGradient\n {...props}\n colors={Platform.select({\n web: colors as any,\n default: colors.map(processColor),\n })}\n locations={resolvedLocations}\n startPoint={_normalizePoint(start)}\n endPoint={_normalizePoint(end)}\n />\n );\n }\n}\n\nfunction _normalizePoint(\n point: LinearGradientPoint | null | undefined\n): NativeLinearGradientPoint | undefined {\n if (!point) {\n return undefined;\n }\n\n if (Array.isArray(point) && point.length !== 2) {\n console.warn('start and end props for LinearGradient must be of the format [x,y] or {x, y}');\n return undefined;\n }\n\n return Array.isArray(point) ? point : [point.x, point.y];\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { NativeLinearGradientProps } from './NativeLinearGradient.types';
3
3
  export default function NativeLinearGradient({ colors, locations, startPoint, endPoint, children, style, ...props }: NativeLinearGradientProps): React.ReactElement;
4
+ //# sourceMappingURL=NativeLinearGradient.android.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLinearGradient.android.d.ts","sourceRoot":"","sources":["../src/NativeLinearGradient.android.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,GAAG,KAAK,EACT,EAAE,yBAAyB,GAAG,KAAK,CAAC,YAAY,CAgChD"}
@@ -1,3 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { NativeLinearGradientProps } from './NativeLinearGradient.types';
3
3
  export default function NativeLinearGradient(props: NativeLinearGradientProps): React.ReactElement;
4
+ //# sourceMappingURL=NativeLinearGradient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLinearGradient.d.ts","sourceRoot":"","sources":["../src/NativeLinearGradient.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAIzE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,KAAK,CAAC,YAAY,CAIjG"}
@@ -2,3 +2,4 @@ import * as React from 'react';
2
2
  import { NativeLinearGradientProps } from './NativeLinearGradient.types';
3
3
  declare const NativeLinearGradient: React.FC<NativeLinearGradientProps>;
4
4
  export default NativeLinearGradient;
5
+ //# sourceMappingURL=NativeLinearGradient.ios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLinearGradient.ios.d.ts","sourceRoot":"","sources":["../src/NativeLinearGradient.ios.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,QAAA,MAAM,oBAAoB,qCAEc,CAAC;AAEzC,eAAe,oBAAoB,CAAC"}
@@ -7,3 +7,4 @@ export declare type NativeLinearGradientProps = ViewProps & PropsWithChildren<{
7
7
  endPoint?: NativeLinearGradientPoint | null;
8
8
  }>;
9
9
  export declare type NativeLinearGradientPoint = [number, number];
10
+ //# sourceMappingURL=NativeLinearGradient.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLinearGradient.types.d.ts","sourceRoot":"","sources":["../src/NativeLinearGradient.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAY,yBAAyB,GAAG,SAAS,GAC/C,iBAAiB,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAC7C,CAAC,CAAC;AAEL,oBAAY,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { NativeLinearGradientProps } from './NativeLinearGradient.types';
3
3
  export default function NativeLinearGradient({ colors, locations, startPoint, endPoint, ...props }: NativeLinearGradientProps): React.ReactElement;
4
+ //# sourceMappingURL=NativeLinearGradient.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeLinearGradient.web.d.ts","sourceRoot":"","sources":["../src/NativeLinearGradient.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAA6B,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEpG,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,yBAAyB,GAAG,KAAK,CAAC,YAAY,CAgFhD"}
@@ -3,5 +3,8 @@
3
3
  "platforms": ["ios", "android"],
4
4
  "ios": {
5
5
  "modulesClassNames": ["LinearGradientModule"]
6
+ },
7
+ "android": {
8
+ "modulesClassNames": ["expo.modules.lineargradient.LinearGradientModule"]
6
9
  }
7
10
  }
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'EXLinearGradient'
6
+ s.name = 'ExpoLinearGradient'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.description = package['description']
@@ -19,13 +19,14 @@ Pod::Spec.new do |s|
19
19
 
20
20
  # Swift/Objective-C compatibility
21
21
  s.pod_target_xcconfig = {
22
- 'DEFINES_MODULE' => 'YES'
22
+ 'DEFINES_MODULE' => 'YES',
23
+ 'SWIFT_COMPILATION_MODE' => 'wholemodule'
23
24
  }
24
25
 
25
26
  if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
26
- s.source_files = "#{s.name}/**/*.h"
27
+ s.source_files = "**/*.h"
27
28
  s.vendored_frameworks = "#{s.name}.xcframework"
28
29
  else
29
- s.source_files = "#{s.name}/**/*.{h,m,swift}"
30
+ s.source_files = "**/*.{h,m,swift}"
30
31
  end
31
32
  end
@@ -0,0 +1,107 @@
1
+ // Copyright 2021-present 650 Industries. All rights reserved.
2
+
3
+ import QuartzCore
4
+ import CoreGraphics
5
+
6
+ var defaultStartPoint = CGPoint(x: 0.5, y: 0.0)
7
+ var defaultEndPoint = CGPoint(x: 0.5, y: 1.0)
8
+ var defaultLocations: [CGFloat] = []
9
+
10
+ final class LinearGradientLayer: CALayer {
11
+ var colors = [CGColor]()
12
+ var startPoint = defaultStartPoint
13
+ var endPoint = defaultEndPoint
14
+ var locations = defaultLocations
15
+
16
+ override init() {
17
+ super.init()
18
+ self.needsDisplayOnBoundsChange = true
19
+ self.masksToBounds = true
20
+ }
21
+
22
+ override init(layer: Any) {
23
+ super.init(layer: layer)
24
+ self.needsDisplayOnBoundsChange = true
25
+ self.masksToBounds = true
26
+ }
27
+
28
+ required init?(coder: NSCoder) {
29
+ fatalError("init(coder:) has not been implemented")
30
+ }
31
+
32
+ func setColors(_ colors: [CGColor]) {
33
+ self.colors = colors
34
+ setNeedsDisplay()
35
+ }
36
+
37
+ func setStartPoint(_ startPoint: CGPoint?) {
38
+ self.startPoint = startPoint ?? defaultStartPoint
39
+ setNeedsDisplay()
40
+ }
41
+
42
+ func setEndPoint(_ endPoint: CGPoint?) {
43
+ self.endPoint = endPoint ?? defaultEndPoint
44
+ setNeedsDisplay()
45
+ }
46
+
47
+ func setLocations(_ locations: [CGFloat]?) {
48
+ self.locations = locations ?? defaultLocations
49
+ setNeedsDisplay()
50
+ }
51
+
52
+ override func display() {
53
+ super.display()
54
+
55
+ if colors.isEmpty || bounds.size.width.isZero || bounds.size.height.isZero {
56
+ return
57
+ }
58
+ let hasAlpha = colors.reduce(false) { result, color in
59
+ return result || color.alpha < 1.0
60
+ }
61
+
62
+ UIGraphicsBeginImageContextWithOptions(bounds.size, !hasAlpha, 0.0)
63
+
64
+ guard let contextRef = UIGraphicsGetCurrentContext() else {
65
+ return
66
+ }
67
+
68
+ draw(in: contextRef)
69
+
70
+ guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
71
+ return
72
+ }
73
+
74
+ self.contents = image.cgImage
75
+ self.contentsScale = image.scale
76
+
77
+ UIGraphicsEndImageContext()
78
+ }
79
+
80
+ override func draw(in ctx: CGContext) {
81
+ super.draw(in: ctx)
82
+
83
+ ctx.saveGState()
84
+
85
+ let colorSpace = CGColorSpaceCreateDeviceRGB()
86
+ let locations = colors.enumerated().map { (offset: Int, _: CGColor) -> CGFloat in
87
+ if self.locations.count > offset {
88
+ return self.locations[offset]
89
+ } else {
90
+ return CGFloat(offset) / CGFloat(colors.count - 1)
91
+ }
92
+ }
93
+
94
+ if let gradient = CGGradient(colorsSpace: colorSpace, colors: colors as CFArray, locations: locations) {
95
+ let size = bounds.size
96
+
97
+ ctx.drawLinearGradient(
98
+ gradient,
99
+ start: CGPoint(x: startPoint.x * size.width, y: startPoint.y * size.height),
100
+ end: CGPoint(x: endPoint.x * size.width, y: endPoint.y * size.height),
101
+ options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]
102
+ )
103
+ }
104
+
105
+ ctx.restoreGState()
106
+ }
107
+ }
@@ -0,0 +1,32 @@
1
+ // Copyright 2021-present 650 Industries. All rights reserved.
2
+
3
+ import CoreGraphics
4
+ import ExpoModulesCore
5
+
6
+ public class LinearGradientModule: Module {
7
+ public func definition() -> ModuleDefinition {
8
+ name("ExpoLinearGradient")
9
+
10
+ viewManager {
11
+ view {
12
+ LinearGradientView()
13
+ }
14
+
15
+ prop("colors") { (view: LinearGradientView, colors: [CGColor]) in
16
+ view.gradientLayer.setColors(colors)
17
+ }
18
+
19
+ prop("startPoint") { (view: LinearGradientView, startPoint: CGPoint?) in
20
+ view.gradientLayer.setStartPoint(startPoint)
21
+ }
22
+
23
+ prop("endPoint") { (view: LinearGradientView, endPoint: CGPoint?) in
24
+ view.gradientLayer.setEndPoint(endPoint)
25
+ }
26
+
27
+ prop("locations") { (view: LinearGradientView, locations: [CGFloat]?) in
28
+ view.gradientLayer.setLocations(locations)
29
+ }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2021-present 650 Industries. All rights reserved.
2
+
3
+ import UIKit
4
+
5
+ final class LinearGradientView: UIView {
6
+ override class var layerClass: AnyClass {
7
+ return LinearGradientLayer.self
8
+ }
9
+
10
+ public var gradientLayer: LinearGradientLayer {
11
+ return layer as! LinearGradientLayer
12
+ }
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-linear-gradient",
3
- "version": "10.0.2",
3
+ "version": "11.2.0",
4
4
  "description": "Provides a React component that renders a gradient view.",
5
5
  "main": "build/LinearGradient.js",
6
6
  "types": "build/LinearGradient.d.ts",
@@ -33,11 +33,11 @@
33
33
  "author": "650 Industries, Inc.",
34
34
  "license": "MIT",
35
35
  "homepage": "https://docs.expo.dev/versions/latest/sdk/linear-gradient/",
36
- "dependencies": {
37
- "expo-modules-core": "~0.4.3"
38
- },
39
36
  "devDependencies": {
40
37
  "expo-module-scripts": "^2.0.0"
41
38
  },
42
- "gitHead": "d23e1ac491da96b51c25eb2533efcd56499ee287"
39
+ "peerDependencies": {
40
+ "expo": "*"
41
+ },
42
+ "gitHead": "d05ba10029249a228fed69288f4af17a52c58ec0"
43
43
  }
@@ -33,6 +33,7 @@ export type LinearGradientProps = ViewProps & {
33
33
  /**
34
34
  * An array that contains `number`s ranging from `0` to `1`, inclusive, and is the same length as the `colors` property.
35
35
  * Each number indicates a color-stop location where each respective color should be located.
36
+ * If not specified, the colors will be distributed evenly across the gradient.
36
37
  *
37
38
  * For example, `[0.5, 0.8]` would render:
38
39
  * - the first color, solid, from the beginning of the gradient view to 50% through (the middle);
@@ -40,18 +41,21 @@ export type LinearGradientProps = ViewProps & {
40
41
  * - the second color, solid, from the 80% point to the end of the gradient view.
41
42
  *
42
43
  * > The color-stop locations must be ascending from least to greatest.
44
+ * @default []
43
45
  */
44
46
  locations?: number[] | null;
45
47
  /**
46
48
  * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will start `10%` from the left and `20%` from the top.
47
49
  *
48
50
  * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the starting position.
51
+ * @default { x: 0.5, y: 0.0 }
49
52
  */
50
53
  start?: LinearGradientPoint | null;
51
54
  /**
52
55
  * For example, `{ x: 0.1, y: 0.2 }` means that the gradient will end `10%` from the left and `20%` from the bottom.
53
56
  *
54
57
  * **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the end position.
58
+ * @default { x: 0.5, y: 1.0 }
55
59
  */
56
60
  end?: LinearGradientPoint | null;
57
61
  };
@@ -1,60 +0,0 @@
1
- package expo.modules.lineargradient;
2
-
3
- import android.content.Context;
4
-
5
- import expo.modules.core.ViewManager;
6
- import expo.modules.core.interfaces.ExpoProp;
7
-
8
- import java.util.ArrayList;
9
-
10
- public class LinearGradientManager extends ViewManager<LinearGradientView> {
11
- public static final String VIEW_CLASS_NAME = "ExpoLinearGradient";
12
- public static final String PROP_COLORS = "colors";
13
- public static final String PROP_LOCATIONS = "locations";
14
- public static final String PROP_START_POS = "startPoint";
15
- public static final String PROP_END_POS = "endPoint";
16
- public static final String PROP_BORDER_RADII = "borderRadii";
17
-
18
- @Override
19
- public String getName() {
20
- return VIEW_CLASS_NAME;
21
- }
22
- @Override
23
- public LinearGradientView createViewInstance(Context context) {
24
- return new LinearGradientView(context);
25
- }
26
-
27
- @Override
28
- public ViewManagerType getViewManagerType() {
29
- return ViewManagerType.SIMPLE;
30
- }
31
-
32
- @ExpoProp(name = PROP_COLORS)
33
- public void setColors(LinearGradientView view, final ArrayList<Double> colors) {
34
- view.setColors(colors);
35
- }
36
-
37
- @ExpoProp(name = PROP_LOCATIONS)
38
- public void setLocations(LinearGradientView view, final ArrayList<Double> locations) {
39
- if (locations != null) {
40
- view.setLocations(locations);
41
- }
42
- }
43
-
44
- @ExpoProp(name = PROP_START_POS)
45
- public void setStartPosition(LinearGradientView view, final ArrayList<Double> startPos) {
46
- view.setStartPosition(startPos);
47
- }
48
-
49
- @ExpoProp(name = PROP_END_POS)
50
- public void setEndPosition(LinearGradientView view, final ArrayList<Double> endPos) {
51
- view.setEndPosition(endPos);
52
- }
53
-
54
- // temporary solution until following issue is resolved:
55
- // https://github.com/facebook/react-native/issues/3198
56
- @ExpoProp(name = PROP_BORDER_RADII)
57
- public void setBorderRadii(LinearGradientView view, final ArrayList<Double> borderRadii) {
58
- view.setBorderRadii(borderRadii);
59
- }
60
- }
@@ -1,16 +0,0 @@
1
- package expo.modules.lineargradient;
2
-
3
- import android.content.Context;
4
-
5
- import java.util.Collections;
6
- import java.util.List;
7
-
8
- import expo.modules.core.BasePackage;
9
- import expo.modules.core.ViewManager;
10
-
11
- public class LinearGradientPackage extends BasePackage {
12
- @Override
13
- public List<ViewManager> createViewManagers(Context context) {
14
- return Collections.singletonList((ViewManager) new LinearGradientManager());
15
- }
16
- }
@@ -1,12 +0,0 @@
1
- // Copyright 2015-present 650 Industries. All rights reserved.
2
-
3
- #import <UIKit/UIKit.h>
4
-
5
- @interface EXLinearGradient : UIView
6
-
7
- - (void)setColors:(NSArray *)colorStrings;
8
- - (void)setLocations:(NSArray *)locations;
9
- - (void)setStartPoint:(CGPoint)start;
10
- - (void)setEndPoint:(CGPoint)end;
11
-
12
- @end
@@ -1,53 +0,0 @@
1
- // Copyright 2015-present 650 Industries. All rights reserved.
2
-
3
- #import <EXLinearGradient/EXLinearGradient.h>
4
- #import <EXLinearGradient/EXLinearGradientLayer.h>
5
- #import <UIKit/UIKit.h>
6
- #import <ExpoModulesCore/EXModuleRegistry.h>
7
- #import <ExpoModulesCore/EXAppLifecycleListener.h>
8
- #import <ExpoModulesCore/EXUtilities.h>
9
-
10
- @interface EXLinearGradient ()
11
-
12
- @end
13
-
14
- @implementation EXLinearGradient
15
-
16
- + (Class)layerClass
17
- {
18
- return [EXLinearGradientLayer class];
19
- }
20
-
21
- - (EXLinearGradientLayer *)gradientLayer
22
- {
23
- return (EXLinearGradientLayer *)self.layer;
24
- }
25
-
26
- - (void)setColors:(NSArray *)colorStrings
27
- {
28
- NSMutableArray *colors = [NSMutableArray arrayWithCapacity:colorStrings.count];
29
- for (NSString *colorString in colorStrings) {
30
- UIColor *convertedColor = [EXUtilities UIColor:colorString];
31
- if (convertedColor) {
32
- [colors addObject:convertedColor];
33
- }
34
- }
35
- self.gradientLayer.colors = colors;
36
- }
37
-
38
- - (void)setStartPoint:(CGPoint)start
39
- {
40
- self.gradientLayer.startPoint = start;
41
- }
42
-
43
- - (void)setEndPoint:(CGPoint)end
44
- {
45
- self.gradientLayer.endPoint = end;
46
- }
47
-
48
- - (void)setLocations:(NSArray *)locations
49
- {
50
- self.gradientLayer.locations = locations;
51
- }
52
-
53
- @end
@@ -1,14 +0,0 @@
1
- // Copyright 2018-present 650 Industries. All rights reserved.
2
-
3
- #import <Foundation/Foundation.h>
4
- #import <QuartzCore/QuartzCore.h>
5
- #import <UIKit/UIKit.h>
6
-
7
- @interface EXLinearGradientLayer : CALayer
8
-
9
- @property (nullable, nonatomic, copy) NSArray<UIColor *> *colors;
10
- @property (nullable, nonatomic, copy) NSArray<NSNumber *> *locations;
11
- @property (nonatomic) CGPoint startPoint;
12
- @property (nonatomic) CGPoint endPoint;
13
-
14
- @end
@@ -1,110 +0,0 @@
1
- // Copyright 2018-present 650 Industries. All rights reserved.
2
-
3
- #import <EXLinearGradient/EXLinearGradientLayer.h>
4
-
5
- @implementation EXLinearGradientLayer
6
-
7
- - (instancetype)init
8
- {
9
- self = [super init];
10
-
11
- if (self) {
12
- self.needsDisplayOnBoundsChange = YES;
13
- self.masksToBounds = YES;
14
- _startPoint = CGPointMake(0.5, 0.0);
15
- _endPoint = CGPointMake(0.5, 1.0);
16
- }
17
-
18
- return self;
19
- }
20
-
21
- - (void)setColors:(NSArray<id> *)colors
22
- {
23
- _colors = colors;
24
- [self setNeedsDisplay];
25
- }
26
-
27
- - (void)setLocations:(NSArray<NSNumber *> *)locations
28
- {
29
- _locations = locations;
30
- [self setNeedsDisplay];
31
- }
32
-
33
- - (void)setStartPoint:(CGPoint)startPoint
34
- {
35
- _startPoint = startPoint;
36
- [self setNeedsDisplay];
37
- }
38
-
39
- - (void)setEndPoint:(CGPoint)endPoint
40
- {
41
- _endPoint = endPoint;
42
- [self setNeedsDisplay];
43
- }
44
-
45
- - (void)display {
46
- [super display];
47
-
48
- BOOL hasAlpha = NO;
49
-
50
- for (NSInteger i = 0; i < self.colors.count; i++) {
51
- hasAlpha = hasAlpha || CGColorGetAlpha(self.colors[i].CGColor) < 1.0;
52
- }
53
-
54
- UIGraphicsBeginImageContextWithOptions(self.bounds.size, !hasAlpha, 0.0);
55
- CGContextRef ref = UIGraphicsGetCurrentContext();
56
- [self drawInContext:ref];
57
-
58
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
59
- self.contents = (__bridge id _Nullable)(image.CGImage);
60
- self.contentsScale = image.scale;
61
-
62
- UIGraphicsEndImageContext();
63
- }
64
-
65
- - (void)drawInContext:(CGContextRef)ctx
66
- {
67
- [super drawInContext:ctx];
68
-
69
- CGContextSaveGState(ctx);
70
-
71
- CGSize size = self.bounds.size;
72
- if (!self.colors || self.colors.count == 0 || size.width == 0.0 || size.height == 0.0)
73
- return;
74
-
75
-
76
- CGFloat *locations = nil;
77
-
78
- locations = malloc(sizeof(CGFloat) * self.colors.count);
79
-
80
- for (NSInteger i = 0; i < self.colors.count; i++) {
81
- if (self.locations.count > i) {
82
- locations[i] = self.locations[i].floatValue;
83
- } else {
84
- locations[i] = (1.0 / (self.colors.count - 1)) * i;
85
- }
86
- }
87
-
88
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
89
- NSMutableArray *colors = [[NSMutableArray alloc] initWithCapacity:self.colors.count];
90
- for (UIColor *color in self.colors) {
91
- [colors addObject:(id)color.CGColor];
92
- }
93
-
94
- CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, locations);
95
-
96
- free(locations);
97
-
98
- CGPoint start = self.startPoint, end = self.endPoint;
99
-
100
- CGContextDrawLinearGradient(ctx, gradient,
101
- CGPointMake(start.x * size.width, start.y * size.height),
102
- CGPointMake(end.x * size.width, end.y * size.height),
103
- kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
104
- CGGradientRelease(gradient);
105
- CGColorSpaceRelease(colorSpace);
106
-
107
- CGContextRestoreGState(ctx);
108
- }
109
-
110
- @end
@@ -1,8 +0,0 @@
1
- // Copyright 2015-present 650 Industries. All rights reserved.
2
-
3
- #import <ExpoModulesCore/EXViewManager.h>
4
- #import <ExpoModulesCore/EXExportedModule.h>
5
-
6
- @interface EXLinearGradientManager : EXViewManager
7
-
8
- @end
@@ -1,45 +0,0 @@
1
- // Copyright 2015-present 650 Industries. All rights reserved.
2
-
3
- #import <EXLinearGradient/EXLinearGradientManager.h>
4
- #import <EXLinearGradient/EXLinearGradient.h>
5
- #import <ExpoModulesCore/EXUIManager.h>
6
-
7
- @interface EXLinearGradientManager ()
8
-
9
- @end
10
-
11
- @implementation EXLinearGradientManager
12
-
13
- EX_EXPORT_MODULE(ExpoLinearGradientManager);
14
-
15
- - (NSString *)viewName
16
- {
17
- return @"ExpoLinearGradient";
18
- }
19
-
20
- - (UIView *)view
21
- {
22
- return [[EXLinearGradient alloc] init];
23
- }
24
-
25
- EX_VIEW_PROPERTY(colors, NSArray *, EXLinearGradient) {
26
- [view setColors:value];
27
- }
28
-
29
- // NOTE: startPoint and endPoint assume that the value is an array with exactly two floats
30
-
31
- EX_VIEW_PROPERTY(startPoint, NSArray *, EXLinearGradient) {
32
- CGPoint point = CGPointMake([[value objectAtIndex:0] floatValue], [[value objectAtIndex:1] floatValue]);
33
- [view setStartPoint:point];
34
- }
35
-
36
- EX_VIEW_PROPERTY(endPoint, NSArray *, EXLinearGradient) {
37
- CGPoint point = CGPointMake([[value objectAtIndex:0] floatValue], [[value objectAtIndex:1] floatValue]);
38
- [view setEndPoint:point];
39
- }
40
-
41
- EX_VIEW_PROPERTY(locations, NSArray *, EXLinearGradient) {
42
- [view setLocations:value];
43
- }
44
-
45
- @end
@@ -1,29 +0,0 @@
1
- import ExpoModulesCore
2
-
3
- public class LinearGradientModule: Module {
4
- public func definition() -> ModuleDefinition {
5
- name("ExpoLinearGradient")
6
-
7
- viewManager {
8
- view {
9
- EXLinearGradient()
10
- }
11
-
12
- prop("colors") { (view: EXLinearGradient, colors: [Int]) in
13
- view.setColors(colors)
14
- }
15
-
16
- prop("startPoint") { (view: EXLinearGradient, startPoint: [Double]) in
17
- view.setStart(CGPoint(x: startPoint[0], y: startPoint[1]))
18
- }
19
-
20
- prop("endPoint") { (view: EXLinearGradient, endPoint: [Double]) in
21
- view.setEnd(CGPoint(x: endPoint[0], y: endPoint[1]))
22
- }
23
-
24
- prop("locations") { (view: EXLinearGradient, locations: [Double]) in
25
- view.setLocations(locations)
26
- }
27
- }
28
- }
29
- }
package/unimodule.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "name": "expo-linear-gradient",
3
- "platforms": ["ios", "android"]
4
- }