expo-linear-gradient 10.0.2 → 11.0.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.
package/CHANGELOG.md CHANGED
@@ -10,9 +10,24 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 10.0.2 — 2021-10-15
13
+ ## 11.0.2 — 2022-02-01
14
14
 
15
- _This version does not introduce any user-facing changes._
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
18
+
19
+ ## 11.0.1 — 2022-01-27
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - 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))
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
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
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
 
@@ -1,9 +1,9 @@
1
1
  apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-android'
3
- apply plugin: 'maven'
3
+ apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '10.0.2'
6
+ version = '11.0.2'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -20,27 +20,25 @@ buildscript {
20
20
  }
21
21
  }
22
22
 
23
- // Upload android library to maven with javadoc and android sources
24
- configurations {
25
- deployerJars
26
- }
27
-
28
23
  // Creating sources with comments
29
24
  task androidSourcesJar(type: Jar) {
30
25
  classifier = 'sources'
31
26
  from android.sourceSets.main.java.srcDirs
32
27
  }
33
28
 
34
- // Put the androidSources and javadoc to the artifacts
35
- artifacts {
36
- archives androidSourcesJar
37
- }
38
-
39
- uploadArchives {
40
- repositories {
41
- mavenDeployer {
42
- configuration = configurations.deployerJars
43
- repository(url: mavenLocal().url)
29
+ afterEvaluate {
30
+ publishing {
31
+ publications {
32
+ release(MavenPublication) {
33
+ from components.release
34
+ // Add additional sourcesJar to artifacts
35
+ artifact(androidSourcesJar)
36
+ }
37
+ }
38
+ repositories {
39
+ maven {
40
+ url = mavenLocal().url
41
+ }
44
42
  }
45
43
  }
46
44
  }
@@ -53,11 +51,15 @@ android {
53
51
  targetCompatibility JavaVersion.VERSION_1_8
54
52
  }
55
53
 
54
+ kotlinOptions {
55
+ jvmTarget = JavaVersion.VERSION_1_8
56
+ }
57
+
56
58
  defaultConfig {
57
59
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
60
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
61
  versionCode 17
60
- versionName "10.0.2"
62
+ versionName "11.0.2"
61
63
  }
62
64
  lintOptions {
63
65
  abortOnError false
@@ -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
  };
@@ -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"]}
@@ -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,101 @@
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
+ required init?(coder: NSCoder) {
23
+ fatalError("init(coder:) has not been implemented")
24
+ }
25
+
26
+ func setColors(_ colors: [CGColor]) {
27
+ self.colors = colors
28
+ setNeedsDisplay()
29
+ }
30
+
31
+ func setStartPoint(_ startPoint: CGPoint?) {
32
+ self.startPoint = startPoint ?? defaultStartPoint
33
+ setNeedsDisplay()
34
+ }
35
+
36
+ func setEndPoint(_ endPoint: CGPoint?) {
37
+ self.endPoint = endPoint ?? defaultEndPoint
38
+ setNeedsDisplay()
39
+ }
40
+
41
+ func setLocations(_ locations: [CGFloat]?) {
42
+ self.locations = locations ?? defaultLocations
43
+ setNeedsDisplay()
44
+ }
45
+
46
+ override func display() {
47
+ super.display()
48
+
49
+ if colors.isEmpty || bounds.size.width.isZero || bounds.size.height.isZero {
50
+ return
51
+ }
52
+ let hasAlpha = colors.reduce(false) { result, color in
53
+ return result || color.alpha < 1.0
54
+ }
55
+
56
+ UIGraphicsBeginImageContextWithOptions(bounds.size, !hasAlpha, 0.0)
57
+
58
+ guard let contextRef = UIGraphicsGetCurrentContext() else {
59
+ return
60
+ }
61
+
62
+ draw(in: contextRef)
63
+
64
+ guard let image = UIGraphicsGetImageFromCurrentImageContext() else {
65
+ return
66
+ }
67
+
68
+ self.contents = image.cgImage
69
+ self.contentsScale = image.scale
70
+
71
+ UIGraphicsEndImageContext()
72
+ }
73
+
74
+ override func draw(in ctx: CGContext) {
75
+ super.draw(in: ctx)
76
+
77
+ ctx.saveGState()
78
+
79
+ let colorSpace = CGColorSpaceCreateDeviceRGB()
80
+ let locations = colors.enumerated().map { (offset: Int, element: CGColor) -> CGFloat in
81
+ if self.locations.count > offset {
82
+ return self.locations[offset]
83
+ } else {
84
+ return CGFloat(offset) / CGFloat(colors.count - 1)
85
+ }
86
+ }
87
+
88
+ if let gradient = CGGradient(colorsSpace: colorSpace, colors: colors as CFArray, locations: locations) {
89
+ let size = bounds.size
90
+
91
+ ctx.drawLinearGradient(
92
+ gradient,
93
+ start: CGPoint(x: startPoint.x * size.width, y: startPoint.y * size.height),
94
+ end: CGPoint(x: endPoint.x * size.width, y: endPoint.y * size.height),
95
+ options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]
96
+ )
97
+ }
98
+
99
+ ctx.restoreGState()
100
+ }
101
+ }
@@ -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.0.2",
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": "ba24eba18bf4f4d4b0d54828992d81a2bb18246a"
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
- }