expo-linear-gradient 9.1.0 → 10.0.1
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 +33 -0
- package/android/build.gradle +24 -14
- package/android/src/main/java/expo/modules/lineargradient/LinearGradientManager.java +2 -2
- package/android/src/main/java/expo/modules/lineargradient/LinearGradientPackage.java +2 -2
- package/build/LinearGradient.d.ts +16 -11
- package/build/LinearGradient.js +2 -2
- package/build/LinearGradient.js.map +1 -1
- package/build/NativeLinearGradient.android.js +2 -2
- package/build/NativeLinearGradient.android.js.map +1 -1
- package/build/NativeLinearGradient.ios.js +1 -1
- package/build/NativeLinearGradient.ios.js.map +1 -1
- package/build/NativeLinearGradient.js +1 -1
- package/build/NativeLinearGradient.js.map +1 -1
- package/build/NativeLinearGradient.types.d.ts +3 -3
- package/build/NativeLinearGradient.types.js.map +1 -1
- package/build/NativeLinearGradient.web.js +7 -10
- package/build/NativeLinearGradient.web.js.map +1 -1
- package/expo-module.config.json +7 -0
- package/ios/EXLinearGradient/EXLinearGradient.h +0 -2
- package/ios/EXLinearGradient/EXLinearGradient.m +4 -4
- package/ios/EXLinearGradient/EXLinearGradientManager.h +3 -3
- package/ios/EXLinearGradient/EXLinearGradientManager.m +6 -6
- package/ios/EXLinearGradient/LinearGradientModule.swift +29 -0
- package/ios/EXLinearGradient.podspec +10 -3
- package/package.json +6 -3
- package/src/LinearGradient.tsx +25 -13
- package/src/NativeLinearGradient.android.tsx +1 -1
- package/src/NativeLinearGradient.ios.tsx +4 -4
- package/src/NativeLinearGradient.types.ts +4 -4
- package/src/NativeLinearGradient.web.tsx +6 -9
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,39 @@
|
|
|
8
8
|
|
|
9
9
|
### 🐛 Bug fixes
|
|
10
10
|
|
|
11
|
+
### 💡 Others
|
|
12
|
+
|
|
13
|
+
## 10.0.1 — 2021-10-01
|
|
14
|
+
|
|
15
|
+
_This version does not introduce any user-facing changes._
|
|
16
|
+
|
|
17
|
+
## 10.0.0 — 2021-09-28
|
|
18
|
+
|
|
19
|
+
### 🛠 Breaking changes
|
|
20
|
+
|
|
21
|
+
- Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
|
|
22
|
+
|
|
23
|
+
### 🐛 Bug fixes
|
|
24
|
+
|
|
25
|
+
- Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
|
|
26
|
+
|
|
27
|
+
## 9.3.0-alpha.0 — 2021-08-17
|
|
28
|
+
|
|
29
|
+
### 💡 Others
|
|
30
|
+
|
|
31
|
+
- Migrated from `@unimodules/core` to `expo-modules-core`. (by [@tsapeta](https://github.com/tsapeta))
|
|
32
|
+
- Experimental Swift implementation using Sweet API. (by [@tsapeta](https://github.com/tsapeta))
|
|
33
|
+
|
|
34
|
+
## 9.2.0 — 2021-06-16
|
|
35
|
+
|
|
36
|
+
### 🐛 Bug fixes
|
|
37
|
+
|
|
38
|
+
- Enable kotlin in all modules. ([#12716](https://github.com/expo/expo/pull/12716) by [@wschurman](https://github.com/wschurman))
|
|
39
|
+
|
|
40
|
+
### 💡 Others
|
|
41
|
+
|
|
42
|
+
- Build Android code using Java 8 to fix Android instrumented test build error. ([#12939](https://github.com/expo/expo/pull/12939) by [@kudo](https://github.com/kudo))
|
|
43
|
+
|
|
11
44
|
## 9.1.0 — 2021-03-10
|
|
12
45
|
|
|
13
46
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
2
3
|
apply plugin: 'maven'
|
|
3
4
|
|
|
4
5
|
group = 'host.exp.exponent'
|
|
5
|
-
version = '
|
|
6
|
+
version = '10.0.1'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
buildscript {
|
|
9
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
10
|
+
ext.safeExtGet = { prop, fallback ->
|
|
11
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
repositories {
|
|
15
|
+
mavenCentral()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
dependencies {
|
|
19
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.4.21')}")
|
|
20
|
+
}
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
// Upload android library to maven with javadoc and android sources
|
|
@@ -37,25 +48,24 @@ uploadArchives {
|
|
|
37
48
|
android {
|
|
38
49
|
compileSdkVersion safeExtGet("compileSdkVersion", 30)
|
|
39
50
|
|
|
51
|
+
compileOptions {
|
|
52
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
53
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
}
|
|
55
|
+
|
|
40
56
|
defaultConfig {
|
|
41
57
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
42
58
|
targetSdkVersion safeExtGet("targetSdkVersion", 30)
|
|
43
59
|
versionCode 17
|
|
44
|
-
versionName "
|
|
60
|
+
versionName "10.0.1"
|
|
45
61
|
}
|
|
46
62
|
lintOptions {
|
|
47
63
|
abortOnError false
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
|
|
52
|
-
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
|
|
53
|
-
} else {
|
|
54
|
-
throw new GradleException(
|
|
55
|
-
"'unimodules-core.gradle' was not found in the usual React Native dependency location. " +
|
|
56
|
-
"This package can only be used in such projects. Are you sure you've installed the dependencies properly?")
|
|
57
|
-
}
|
|
58
|
-
|
|
59
67
|
dependencies {
|
|
60
|
-
|
|
68
|
+
implementation project(':expo-modules-core')
|
|
69
|
+
|
|
70
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.4.21')}"
|
|
61
71
|
}
|
|
@@ -2,8 +2,8 @@ package expo.modules.lineargradient;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import expo.modules.core.ViewManager;
|
|
6
|
+
import expo.modules.core.interfaces.ExpoProp;
|
|
7
7
|
|
|
8
8
|
import java.util.ArrayList;
|
|
9
9
|
|
|
@@ -5,8 +5,8 @@ import android.content.Context;
|
|
|
5
5
|
import java.util.Collections;
|
|
6
6
|
import java.util.List;
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import expo.modules.core.BasePackage;
|
|
9
|
+
import expo.modules.core.ViewManager;
|
|
10
10
|
|
|
11
11
|
public class LinearGradientPackage extends BasePackage {
|
|
12
12
|
@Override
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ViewProps } from 'react-native';
|
|
3
3
|
import { NativeLinearGradientPoint } from './NativeLinearGradient.types';
|
|
4
|
+
/**
|
|
5
|
+
* An object `{ x: number; y: number }` or array `[x, y]` that represents the point
|
|
6
|
+
* at which the gradient starts or ends, as a fraction of the overall size of the gradient ranging
|
|
7
|
+
* from `0` to `1`, inclusive.
|
|
8
|
+
*/
|
|
4
9
|
export declare type LinearGradientPoint = {
|
|
10
|
+
/**
|
|
11
|
+
* A number ranging from `0` to `1`, representing the position of gradient transformation.
|
|
12
|
+
*/
|
|
5
13
|
x: number;
|
|
14
|
+
/**
|
|
15
|
+
* A number ranging from `0` to `1`, representing the position of gradient transformation.
|
|
16
|
+
*/
|
|
6
17
|
y: number;
|
|
7
18
|
} | NativeLinearGradientPoint;
|
|
8
|
-
export declare type LinearGradientProps = {
|
|
19
|
+
export declare type LinearGradientProps = ViewProps & {
|
|
9
20
|
/**
|
|
10
21
|
* An array of colors that represent stops in the gradient. At least two colors are required
|
|
11
22
|
* (for a single-color background, use the `style.backgroundColor` prop on a `View` component).
|
|
12
23
|
*/
|
|
13
24
|
colors: string[];
|
|
14
25
|
/**
|
|
15
|
-
* An array that contains `number`s ranging from 0 to 1
|
|
26
|
+
* An array that contains `number`s ranging from `0` to `1`, inclusive, and is the same length as the `colors` property.
|
|
16
27
|
* Each number indicates a color-stop location where each respective color should be located.
|
|
17
28
|
*
|
|
18
29
|
* For example, `[0.5, 0.8]` would render:
|
|
@@ -20,28 +31,22 @@ export declare type LinearGradientProps = {
|
|
|
20
31
|
* - a gradient from the first color to the second from the 50% point to the 80% point; and
|
|
21
32
|
* - the second color, solid, from the 80% point to the end of the gradient view.
|
|
22
33
|
*
|
|
23
|
-
* The color-stop locations must be ascending from least to greatest.
|
|
34
|
+
* > The color-stop locations must be ascending from least to greatest.
|
|
24
35
|
*/
|
|
25
36
|
locations?: number[] | null;
|
|
26
37
|
/**
|
|
27
|
-
* An object `{ x: number; y: number }` or array `[x, y]` that represents the point
|
|
28
|
-
* at which the gradient starts, as a fraction of the overall size of the gradient ranging from 0 to 1, inclusive.
|
|
29
|
-
*
|
|
30
38
|
* For example, `{ x: 0.1, y: 0.2 }` means that the gradient will start `10%` from the left and `20%` from the top.
|
|
31
39
|
*
|
|
32
40
|
* **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the starting position.
|
|
33
41
|
*/
|
|
34
42
|
start?: LinearGradientPoint | null;
|
|
35
43
|
/**
|
|
36
|
-
* An object `{ x: number; y: number }` or array `[x, y]` that represents the point
|
|
37
|
-
* at which the gradient ends, as a fraction of the overall size of the gradient ranging from 0 to 1, inclusive.
|
|
38
|
-
*
|
|
39
44
|
* For example, `{ x: 0.1, y: 0.2 }` means that the gradient will end `10%` from the left and `20%` from the bottom.
|
|
40
45
|
*
|
|
41
46
|
* **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the end position.
|
|
42
47
|
*/
|
|
43
48
|
end?: LinearGradientPoint | null;
|
|
44
|
-
}
|
|
49
|
+
};
|
|
45
50
|
/**
|
|
46
51
|
* Renders a native view that transitions between multiple colors in a linear direction.
|
|
47
52
|
*/
|
package/build/LinearGradient.js
CHANGED
|
@@ -12,10 +12,10 @@ export class LinearGradient extends React.Component {
|
|
|
12
12
|
console.warn('LinearGradient colors and locations props should be arrays of the same length');
|
|
13
13
|
resolvedLocations = locations.slice(0, colors.length);
|
|
14
14
|
}
|
|
15
|
-
return (React.createElement(NativeLinearGradient,
|
|
15
|
+
return (React.createElement(NativeLinearGradient, { ...props, colors: Platform.select({
|
|
16
16
|
web: colors,
|
|
17
17
|
default: colors.map(processColor),
|
|
18
|
-
}), locations: resolvedLocations, startPoint: _normalizePoint(start), endPoint: _normalizePoint(end) }))
|
|
18
|
+
}), locations: resolvedLocations, startPoint: _normalizePoint(start), endPoint: _normalizePoint(end) }));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
function _normalizePoint(point) {
|
|
@@ -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,
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { requireNativeViewManager } from '
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { StyleSheet, View } from 'react-native';
|
|
4
4
|
export default function NativeLinearGradient({ colors, locations, startPoint, endPoint, children, style, ...props }) {
|
|
@@ -18,7 +18,7 @@ export default function NativeLinearGradient({ colors, locations, startPoint, en
|
|
|
18
18
|
flatStyle.borderBottomLeftRadius ?? borderRadius,
|
|
19
19
|
flatStyle.borderBottomLeftRadius ?? borderRadius,
|
|
20
20
|
];
|
|
21
|
-
return (React.createElement(View,
|
|
21
|
+
return (React.createElement(View, { ...props, style: style },
|
|
22
22
|
React.createElement(BaseNativeLinearGradient, { style: StyleSheet.absoluteFill, colors: colors, startPoint: startPoint, endPoint: endPoint, locations: locations, borderRadii: borderRadiiPerCorner }),
|
|
23
23
|
children));
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeLinearGradient.android.js","sourceRoot":"","sources":["../src/NativeLinearGradient.android.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"NativeLinearGradient.android.js","sourceRoot":"","sources":["../src/NativeLinearGradient.android.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,GAAG,KAAK,EACkB;IAC1B,6FAA6F;IAC7F,sEAAsE;IACtE,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAClD,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,IAAI,CAAC,CAAC;IAEjD,2BAA2B;IAC3B,wJAAwJ;IACxJ,MAAM,oBAAoB,GAAG;QAC3B,SAAS,CAAC,mBAAmB,IAAI,YAAY;QAC7C,SAAS,CAAC,mBAAmB,IAAI,YAAY;QAC7C,SAAS,CAAC,oBAAoB,IAAI,YAAY;QAC9C,SAAS,CAAC,oBAAoB,IAAI,YAAY;QAC9C,SAAS,CAAC,uBAAuB,IAAI,YAAY;QACjD,SAAS,CAAC,uBAAuB,IAAI,YAAY;QACjD,SAAS,CAAC,sBAAsB,IAAI,YAAY;QAChD,SAAS,CAAC,sBAAsB,IAAI,YAAY;KACjD,CAAC;IAEF,OAAO,CACL,oBAAC,IAAI,OAAK,KAAK,EAAE,KAAK,EAAE,KAAK;QAC3B,oBAAC,wBAAwB,IACvB,KAAK,EAAE,UAAU,CAAC,YAAY,EAC9B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,oBAAoB,GACjC;QACD,QAAQ,CACJ,CACR,CAAC;AACJ,CAAC;AAED,MAAM,wBAAwB,GAAG,wBAAwB,CAAC,oBAAoB,CAAC,CAAC","sourcesContent":["import { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport { StyleSheet, View } from 'react-native';\n\nimport { NativeLinearGradientProps } from './NativeLinearGradient.types';\n\nexport default function NativeLinearGradient({\n colors,\n locations,\n startPoint,\n endPoint,\n children,\n style,\n ...props\n}: NativeLinearGradientProps): React.ReactElement {\n // TODO: revisit whether we need to inherit the container's borderRadius since this issue has\n // been resolved: https://github.com/facebook/react-native/issues/3198\n const flatStyle = StyleSheet.flatten(style) ?? {};\n const borderRadius = flatStyle.borderRadius ?? 0;\n\n // This is the format from:\n // https://developer.android.com/reference/android/graphics/Path.html#addRoundRect(android.graphics.RectF,%20float[],%20android.graphics.Path.Direction)\n const borderRadiiPerCorner = [\n flatStyle.borderTopLeftRadius ?? borderRadius,\n flatStyle.borderTopLeftRadius ?? borderRadius,\n flatStyle.borderTopRightRadius ?? borderRadius,\n flatStyle.borderTopRightRadius ?? borderRadius,\n flatStyle.borderBottomRightRadius ?? borderRadius,\n flatStyle.borderBottomRightRadius ?? borderRadius,\n flatStyle.borderBottomLeftRadius ?? borderRadius,\n flatStyle.borderBottomLeftRadius ?? borderRadius,\n ];\n\n return (\n <View {...props} style={style}>\n <BaseNativeLinearGradient\n style={StyleSheet.absoluteFill}\n colors={colors}\n startPoint={startPoint}\n endPoint={endPoint}\n locations={locations}\n borderRadii={borderRadiiPerCorner}\n />\n {children}\n </View>\n );\n}\n\nconst BaseNativeLinearGradient = requireNativeViewManager('ExpoLinearGradient');\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { requireNativeViewManager } from '
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
2
|
const NativeLinearGradient = requireNativeViewManager('ExpoLinearGradient');
|
|
3
3
|
export default NativeLinearGradient;
|
|
4
4
|
//# sourceMappingURL=NativeLinearGradient.ios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeLinearGradient.ios.js","sourceRoot":"","sources":["../src/NativeLinearGradient.ios.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"NativeLinearGradient.ios.js","sourceRoot":"","sources":["../src/NativeLinearGradient.ios.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAK7D,MAAM,oBAAoB,GAAG,wBAAwB,CACnD,oBAAoB,CACkB,CAAC;AAEzC,eAAe,oBAAoB,CAAC","sourcesContent":["import { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\n\nimport { NativeLinearGradientProps } from './NativeLinearGradient.types';\n\nconst NativeLinearGradient = requireNativeViewManager(\n 'ExpoLinearGradient'\n) as React.FC<NativeLinearGradientProps>;\n\nexport default NativeLinearGradient;\n"]}
|
|
@@ -5,6 +5,6 @@ import { View } from 'react-native';
|
|
|
5
5
|
export default function NativeLinearGradient(props) {
|
|
6
6
|
const { colors, locations, startPoint, endPoint, ...viewProps } = props;
|
|
7
7
|
console.warn('LinearGradient is not available on this platform');
|
|
8
|
-
return React.createElement(View,
|
|
8
|
+
return React.createElement(View, { ...viewProps });
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=NativeLinearGradient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeLinearGradient.js","sourceRoot":"","sources":["../src/NativeLinearGradient.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIpC,mEAAmE;AACnE,kFAAkF;AAClF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAgC;IAC3E,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACxE,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACjE,OAAO,oBAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"NativeLinearGradient.js","sourceRoot":"","sources":["../src/NativeLinearGradient.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIpC,mEAAmE;AACnE,kFAAkF;AAClF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAgC;IAC3E,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACxE,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACjE,OAAO,oBAAC,IAAI,OAAM,SAAiB,GAAI,CAAC;AAC1C,CAAC","sourcesContent":["import * as React from 'react';\nimport { View } from 'react-native';\n\nimport { NativeLinearGradientProps } from './NativeLinearGradient.types';\n\n// This is a shim view for platforms that aren't supported by Expo.\n// The component and prop types should match all of the other platform variations.\nexport default function NativeLinearGradient(props: NativeLinearGradientProps): React.ReactElement {\n const { colors, locations, startPoint, endPoint, ...viewProps } = props;\n console.warn('LinearGradient is not available on this platform');\n return <View {...(viewProps as any)} />;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export declare type NativeLinearGradientProps =
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { ViewProps } from 'react-native';
|
|
3
|
+
export declare type NativeLinearGradientProps = ViewProps & PropsWithChildren<{
|
|
4
4
|
colors: number[];
|
|
5
5
|
locations?: number[] | null;
|
|
6
6
|
startPoint?: NativeLinearGradientPoint | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeLinearGradient.types.js","sourceRoot":"","sources":["../src/NativeLinearGradient.types.ts"],"names":[],"mappings":"","sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"NativeLinearGradient.types.js","sourceRoot":"","sources":["../src/NativeLinearGradient.types.ts"],"names":[],"mappings":"","sourcesContent":["import { PropsWithChildren } from 'react';\nimport { ViewProps } from 'react-native';\n\nexport type NativeLinearGradientProps = ViewProps &\n PropsWithChildren<{\n colors: number[];\n locations?: number[] | null;\n startPoint?: NativeLinearGradientPoint | null;\n endPoint?: NativeLinearGradientPoint | null;\n }>;\n\nexport type NativeLinearGradientPoint = [number, number];\n"]}
|
|
@@ -3,10 +3,8 @@ import { View } from 'react-native';
|
|
|
3
3
|
import normalizeColor from 'react-native-web/src/modules/normalizeColor';
|
|
4
4
|
export default function NativeLinearGradient({ colors, locations, startPoint, endPoint, ...props }) {
|
|
5
5
|
const [layout, setLayout] = React.useState(null);
|
|
6
|
-
const [gradientColors, setGradientColors] = React.useState([]);
|
|
7
|
-
const [pseudoAngle, setPseudoAngle] = React.useState(0);
|
|
8
6
|
const { width = 1, height = 1 } = layout ?? {};
|
|
9
|
-
React.
|
|
7
|
+
const pseudoAngle = React.useMemo(() => {
|
|
10
8
|
const getControlPoints = () => {
|
|
11
9
|
let correctedStartPoint = [0, 0];
|
|
12
10
|
if (Array.isArray(startPoint)) {
|
|
@@ -31,10 +29,10 @@ export default function NativeLinearGradient({ colors, locations, startPoint, en
|
|
|
31
29
|
end[1] *= height;
|
|
32
30
|
const py = end[1] - start[1];
|
|
33
31
|
const px = end[0] - start[0];
|
|
34
|
-
|
|
32
|
+
return 90 + (Math.atan2(py, px) * 180) / Math.PI;
|
|
35
33
|
}, [width, height, startPoint, endPoint]);
|
|
36
|
-
React.
|
|
37
|
-
|
|
34
|
+
const gradientColors = React.useMemo(() => {
|
|
35
|
+
return colors.map((color, index) => {
|
|
38
36
|
const hexColor = normalizeColor(color);
|
|
39
37
|
let output = hexColor;
|
|
40
38
|
if (locations && locations[index]) {
|
|
@@ -45,17 +43,16 @@ export default function NativeLinearGradient({ colors, locations, startPoint, en
|
|
|
45
43
|
}
|
|
46
44
|
return output;
|
|
47
45
|
});
|
|
48
|
-
setGradientColors(nextGradientColors);
|
|
49
46
|
}, [colors, locations]);
|
|
50
47
|
const colorStyle = gradientColors.join(',');
|
|
51
48
|
const backgroundImage = `linear-gradient(${pseudoAngle}deg, ${colorStyle})`;
|
|
52
49
|
// TODO(Bacon): In the future we could consider adding `backgroundRepeat: "no-repeat"`. For more
|
|
53
50
|
// browser support.
|
|
54
|
-
return (React.createElement(View,
|
|
51
|
+
return (React.createElement(View, { ...props, style: [
|
|
55
52
|
props.style,
|
|
56
53
|
// @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
|
|
57
54
|
{ backgroundImage },
|
|
58
|
-
], onLayout: event => {
|
|
55
|
+
], onLayout: (event) => {
|
|
59
56
|
const { x, y, width, height } = event.nativeEvent.layout;
|
|
60
57
|
const oldLayout = layout ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
61
58
|
// don't set new layout state unless the layout has actually changed
|
|
@@ -68,6 +65,6 @@ export default function NativeLinearGradient({ colors, locations, startPoint, en
|
|
|
68
65
|
if (props.onLayout) {
|
|
69
66
|
props.onLayout(event);
|
|
70
67
|
}
|
|
71
|
-
} }))
|
|
68
|
+
} }));
|
|
72
69
|
}
|
|
73
70
|
//# sourceMappingURL=NativeLinearGradient.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeLinearGradient.web.js","sourceRoot":"","sources":["../src/NativeLinearGradient.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,IAAI,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,cAAc,MAAM,6CAA6C,CAAC;AAIzE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,GAAG,KAAK,EACkB;IAC1B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAyB,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeLinearGradient.web.js","sourceRoot":"","sources":["../src/NativeLinearGradient.web.tsx"],"names":[],"mappings":"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","sourcesContent":["import * as React from 'react';\nimport { LayoutRectangle, View } from 'react-native';\nimport normalizeColor from 'react-native-web/src/modules/normalizeColor';\n\nimport { NativeLinearGradientPoint, NativeLinearGradientProps } from './NativeLinearGradient.types';\n\nexport default function NativeLinearGradient({\n colors,\n locations,\n startPoint,\n endPoint,\n ...props\n}: NativeLinearGradientProps): React.ReactElement {\n const [layout, setLayout] = React.useState<LayoutRectangle | null>(null);\n\n const { width = 1, height = 1 } = layout ?? {};\n\n const pseudoAngle = React.useMemo(() => {\n const getControlPoints = (): NativeLinearGradientPoint[] => {\n let correctedStartPoint: NativeLinearGradientPoint = [0, 0];\n if (Array.isArray(startPoint)) {\n correctedStartPoint = [\n startPoint[0] != null ? startPoint[0] : 0.0,\n startPoint[1] != null ? startPoint[1] : 0.0,\n ];\n }\n let correctedEndPoint: NativeLinearGradientPoint = [0.0, 1.0];\n if (Array.isArray(endPoint)) {\n correctedEndPoint = [\n endPoint[0] != null ? endPoint[0] : 0.0,\n endPoint[1] != null ? endPoint[1] : 1.0,\n ];\n }\n return [correctedStartPoint, correctedEndPoint];\n };\n\n const [start, end] = getControlPoints();\n start[0] *= width;\n end[0] *= width;\n start[1] *= height;\n end[1] *= height;\n const py = end[1] - start[1];\n const px = end[0] - start[0];\n\n return 90 + (Math.atan2(py, px) * 180) / Math.PI;\n }, [width, height, startPoint, endPoint]);\n\n const gradientColors = React.useMemo(() => {\n return colors.map((color: number, index: number): string => {\n const hexColor = normalizeColor(color);\n let output = hexColor;\n if (locations && locations[index]) {\n const location = Math.max(0, Math.min(1, locations[index]));\n // Convert 0...1 to 0...100\n const percentage = location * 100;\n output += ` ${percentage}%`;\n }\n return output;\n });\n }, [colors, locations]);\n\n const colorStyle = gradientColors.join(',');\n const backgroundImage = `linear-gradient(${pseudoAngle}deg, ${colorStyle})`;\n // TODO(Bacon): In the future we could consider adding `backgroundRepeat: \"no-repeat\"`. For more\n // browser support.\n return (\n <View\n {...props}\n style={[\n props.style,\n // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.\n { backgroundImage },\n ]}\n onLayout={(event) => {\n const { x, y, width, height } = event.nativeEvent.layout;\n const oldLayout = layout ?? { x: 0, y: 0, width: 1, height: 1 };\n // don't set new layout state unless the layout has actually changed\n if (\n x !== oldLayout.x ||\n y !== oldLayout.y ||\n width !== oldLayout.width ||\n height !== oldLayout.height\n ) {\n setLayout({ x, y, width, height });\n }\n\n if (props.onLayout) {\n props.onLayout(event);\n }\n }}\n />\n );\n}\n"]}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
#import <EXLinearGradient/EXLinearGradient.h>
|
|
4
4
|
#import <EXLinearGradient/EXLinearGradientLayer.h>
|
|
5
5
|
#import <UIKit/UIKit.h>
|
|
6
|
-
#import <
|
|
7
|
-
#import <
|
|
8
|
-
#import <
|
|
6
|
+
#import <ExpoModulesCore/EXModuleRegistry.h>
|
|
7
|
+
#import <ExpoModulesCore/EXAppLifecycleListener.h>
|
|
8
|
+
#import <ExpoModulesCore/EXUtilities.h>
|
|
9
9
|
|
|
10
10
|
@interface EXLinearGradient ()
|
|
11
11
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
{
|
|
28
28
|
NSMutableArray *colors = [NSMutableArray arrayWithCapacity:colorStrings.count];
|
|
29
29
|
for (NSString *colorString in colorStrings) {
|
|
30
|
-
UIColor *convertedColor = [
|
|
30
|
+
UIColor *convertedColor = [EXUtilities UIColor:colorString];
|
|
31
31
|
if (convertedColor) {
|
|
32
32
|
[colors addObject:convertedColor];
|
|
33
33
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
#import <
|
|
4
|
-
#import <
|
|
3
|
+
#import <ExpoModulesCore/EXViewManager.h>
|
|
4
|
+
#import <ExpoModulesCore/EXExportedModule.h>
|
|
5
5
|
|
|
6
|
-
@interface EXLinearGradientManager :
|
|
6
|
+
@interface EXLinearGradientManager : EXViewManager
|
|
7
7
|
|
|
8
8
|
@end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#import <EXLinearGradient/EXLinearGradientManager.h>
|
|
4
4
|
#import <EXLinearGradient/EXLinearGradient.h>
|
|
5
|
-
#import <
|
|
5
|
+
#import <ExpoModulesCore/EXUIManager.h>
|
|
6
6
|
|
|
7
7
|
@interface EXLinearGradientManager ()
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
@implementation EXLinearGradientManager
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
EX_EXPORT_MODULE(ExpoLinearGradientManager);
|
|
14
14
|
|
|
15
15
|
- (NSString *)viewName
|
|
16
16
|
{
|
|
@@ -22,23 +22,23 @@ UM_EXPORT_MODULE(ExpoLinearGradientManager);
|
|
|
22
22
|
return [[EXLinearGradient alloc] init];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
EX_VIEW_PROPERTY(colors, NSArray *, EXLinearGradient) {
|
|
26
26
|
[view setColors:value];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// NOTE: startPoint and endPoint assume that the value is an array with exactly two floats
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
EX_VIEW_PROPERTY(startPoint, NSArray *, EXLinearGradient) {
|
|
32
32
|
CGPoint point = CGPointMake([[value objectAtIndex:0] floatValue], [[value objectAtIndex:1] floatValue]);
|
|
33
33
|
[view setStartPoint:point];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
EX_VIEW_PROPERTY(endPoint, NSArray *, EXLinearGradient) {
|
|
37
37
|
CGPoint point = CGPointMake([[value objectAtIndex:0] floatValue], [[value objectAtIndex:1] floatValue]);
|
|
38
38
|
[view setEndPoint:point];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
EX_VIEW_PROPERTY(locations, NSArray *, EXLinearGradient) {
|
|
42
42
|
[view setLocations:value];
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -10,15 +10,22 @@ Pod::Spec.new do |s|
|
|
|
10
10
|
s.license = package['license']
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.homepage = package['homepage']
|
|
13
|
-
s.platform = :ios, '
|
|
13
|
+
s.platform = :ios, '12.0'
|
|
14
|
+
s.swift_version = '5.4'
|
|
14
15
|
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
16
|
+
s.static_framework = true
|
|
15
17
|
|
|
16
|
-
s.dependency '
|
|
18
|
+
s.dependency 'ExpoModulesCore'
|
|
19
|
+
|
|
20
|
+
# Swift/Objective-C compatibility
|
|
21
|
+
s.pod_target_xcconfig = {
|
|
22
|
+
'DEFINES_MODULE' => 'YES'
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
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')
|
|
19
26
|
s.source_files = "#{s.name}/**/*.h"
|
|
20
27
|
s.vendored_frameworks = "#{s.name}.xcframework"
|
|
21
28
|
else
|
|
22
|
-
s.source_files = "#{s.name}/**/*.{h,m}"
|
|
29
|
+
s.source_files = "#{s.name}/**/*.{h,m,swift}"
|
|
23
30
|
end
|
|
24
31
|
end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-linear-gradient",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.1",
|
|
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",
|
|
@@ -32,9 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"author": "650 Industries, Inc.",
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"homepage": "https://docs.expo.
|
|
35
|
+
"homepage": "https://docs.expo.dev/versions/latest/sdk/linear-gradient/",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"expo-modules-core": "~0.4.2"
|
|
38
|
+
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"expo-module-scripts": "^2.0.0"
|
|
38
41
|
},
|
|
39
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2718b696f4a6919905b0f47ebb24ff65b42d8ff9"
|
|
40
43
|
}
|
package/src/LinearGradient.tsx
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Platform, processColor,
|
|
2
|
+
import { Platform, processColor, ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import NativeLinearGradient from './NativeLinearGradient';
|
|
5
5
|
import { NativeLinearGradientPoint } from './NativeLinearGradient.types';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// @needsAudit
|
|
8
|
+
/**
|
|
9
|
+
* An object `{ x: number; y: number }` or array `[x, y]` that represents the point
|
|
10
|
+
* at which the gradient starts or ends, as a fraction of the overall size of the gradient ranging
|
|
11
|
+
* from `0` to `1`, inclusive.
|
|
12
|
+
*/
|
|
13
|
+
export type LinearGradientPoint =
|
|
14
|
+
| {
|
|
15
|
+
/**
|
|
16
|
+
* A number ranging from `0` to `1`, representing the position of gradient transformation.
|
|
17
|
+
*/
|
|
18
|
+
x: number;
|
|
19
|
+
/**
|
|
20
|
+
* A number ranging from `0` to `1`, representing the position of gradient transformation.
|
|
21
|
+
*/
|
|
22
|
+
y: number;
|
|
23
|
+
}
|
|
24
|
+
| NativeLinearGradientPoint;
|
|
8
25
|
|
|
9
|
-
|
|
26
|
+
// @needsAudit
|
|
27
|
+
export type LinearGradientProps = ViewProps & {
|
|
10
28
|
/**
|
|
11
29
|
* An array of colors that represent stops in the gradient. At least two colors are required
|
|
12
30
|
* (for a single-color background, use the `style.backgroundColor` prop on a `View` component).
|
|
13
31
|
*/
|
|
14
32
|
colors: string[];
|
|
15
33
|
/**
|
|
16
|
-
* An array that contains `number`s ranging from 0 to 1
|
|
34
|
+
* An array that contains `number`s ranging from `0` to `1`, inclusive, and is the same length as the `colors` property.
|
|
17
35
|
* Each number indicates a color-stop location where each respective color should be located.
|
|
18
36
|
*
|
|
19
37
|
* For example, `[0.5, 0.8]` would render:
|
|
@@ -21,28 +39,22 @@ export type LinearGradientProps = {
|
|
|
21
39
|
* - a gradient from the first color to the second from the 50% point to the 80% point; and
|
|
22
40
|
* - the second color, solid, from the 80% point to the end of the gradient view.
|
|
23
41
|
*
|
|
24
|
-
* The color-stop locations must be ascending from least to greatest.
|
|
42
|
+
* > The color-stop locations must be ascending from least to greatest.
|
|
25
43
|
*/
|
|
26
44
|
locations?: number[] | null;
|
|
27
45
|
/**
|
|
28
|
-
* An object `{ x: number; y: number }` or array `[x, y]` that represents the point
|
|
29
|
-
* at which the gradient starts, as a fraction of the overall size of the gradient ranging from 0 to 1, inclusive.
|
|
30
|
-
*
|
|
31
46
|
* For example, `{ x: 0.1, y: 0.2 }` means that the gradient will start `10%` from the left and `20%` from the top.
|
|
32
47
|
*
|
|
33
48
|
* **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the starting position.
|
|
34
49
|
*/
|
|
35
50
|
start?: LinearGradientPoint | null;
|
|
36
51
|
/**
|
|
37
|
-
* An object `{ x: number; y: number }` or array `[x, y]` that represents the point
|
|
38
|
-
* at which the gradient ends, as a fraction of the overall size of the gradient ranging from 0 to 1, inclusive.
|
|
39
|
-
*
|
|
40
52
|
* For example, `{ x: 0.1, y: 0.2 }` means that the gradient will end `10%` from the left and `20%` from the bottom.
|
|
41
53
|
*
|
|
42
54
|
* **On web**, this only changes the angle of the gradient because CSS gradients don't support changing the end position.
|
|
43
55
|
*/
|
|
44
56
|
end?: LinearGradientPoint | null;
|
|
45
|
-
}
|
|
57
|
+
};
|
|
46
58
|
|
|
47
59
|
/**
|
|
48
60
|
* Renders a native view that transitions between multiple colors in a linear direction.
|
|
@@ -73,7 +85,7 @@ export class LinearGradient extends React.Component<LinearGradientProps> {
|
|
|
73
85
|
|
|
74
86
|
function _normalizePoint(
|
|
75
87
|
point: LinearGradientPoint | null | undefined
|
|
76
|
-
):
|
|
88
|
+
): NativeLinearGradientPoint | undefined {
|
|
77
89
|
if (!point) {
|
|
78
90
|
return undefined;
|
|
79
91
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { requireNativeViewManager } from '
|
|
1
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
import { NativeLinearGradientProps } from './NativeLinearGradient.types';
|
|
5
5
|
|
|
6
|
-
const NativeLinearGradient = requireNativeViewManager(
|
|
7
|
-
|
|
8
|
-
>;
|
|
6
|
+
const NativeLinearGradient = requireNativeViewManager(
|
|
7
|
+
'ExpoLinearGradient'
|
|
8
|
+
) as React.FC<NativeLinearGradientProps>;
|
|
9
9
|
|
|
10
10
|
export default NativeLinearGradient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
|
-
export type NativeLinearGradientProps =
|
|
5
|
-
|
|
4
|
+
export type NativeLinearGradientProps = ViewProps &
|
|
5
|
+
PropsWithChildren<{
|
|
6
6
|
colors: number[];
|
|
7
7
|
locations?: number[] | null;
|
|
8
8
|
startPoint?: NativeLinearGradientPoint | null;
|
|
@@ -12,11 +12,10 @@ export default function NativeLinearGradient({
|
|
|
12
12
|
...props
|
|
13
13
|
}: NativeLinearGradientProps): React.ReactElement {
|
|
14
14
|
const [layout, setLayout] = React.useState<LayoutRectangle | null>(null);
|
|
15
|
-
const [gradientColors, setGradientColors] = React.useState<string[]>([]);
|
|
16
|
-
const [pseudoAngle, setPseudoAngle] = React.useState<number>(0);
|
|
17
15
|
|
|
18
16
|
const { width = 1, height = 1 } = layout ?? {};
|
|
19
|
-
|
|
17
|
+
|
|
18
|
+
const pseudoAngle = React.useMemo(() => {
|
|
20
19
|
const getControlPoints = (): NativeLinearGradientPoint[] => {
|
|
21
20
|
let correctedStartPoint: NativeLinearGradientPoint = [0, 0];
|
|
22
21
|
if (Array.isArray(startPoint)) {
|
|
@@ -43,11 +42,11 @@ export default function NativeLinearGradient({
|
|
|
43
42
|
const py = end[1] - start[1];
|
|
44
43
|
const px = end[0] - start[0];
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
return 90 + (Math.atan2(py, px) * 180) / Math.PI;
|
|
47
46
|
}, [width, height, startPoint, endPoint]);
|
|
48
47
|
|
|
49
|
-
React.
|
|
50
|
-
|
|
48
|
+
const gradientColors = React.useMemo(() => {
|
|
49
|
+
return colors.map((color: number, index: number): string => {
|
|
51
50
|
const hexColor = normalizeColor(color);
|
|
52
51
|
let output = hexColor;
|
|
53
52
|
if (locations && locations[index]) {
|
|
@@ -58,8 +57,6 @@ export default function NativeLinearGradient({
|
|
|
58
57
|
}
|
|
59
58
|
return output;
|
|
60
59
|
});
|
|
61
|
-
|
|
62
|
-
setGradientColors(nextGradientColors);
|
|
63
60
|
}, [colors, locations]);
|
|
64
61
|
|
|
65
62
|
const colorStyle = gradientColors.join(',');
|
|
@@ -74,7 +71,7 @@ export default function NativeLinearGradient({
|
|
|
74
71
|
// @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
|
|
75
72
|
{ backgroundImage },
|
|
76
73
|
]}
|
|
77
|
-
onLayout={event => {
|
|
74
|
+
onLayout={(event) => {
|
|
78
75
|
const { x, y, width, height } = event.nativeEvent.layout;
|
|
79
76
|
const oldLayout = layout ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
80
77
|
// don't set new layout state unless the layout has actually changed
|