expo-mesh-gradient 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +5 -0
- package/README.md +35 -0
- package/build/MeshGradient.types.d.ts +35 -0
- package/build/MeshGradient.types.d.ts.map +1 -0
- package/build/MeshGradientView.d.ts +4 -0
- package/build/MeshGradientView.d.ts.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -0
- package/expo-module.config.json +10 -0
- package/ios/Convertibles+SIMD.swift +35 -0
- package/ios/ExpoMeshGradient.podspec +29 -0
- package/ios/MeshGradientModule.swift +11 -0
- package/ios/MeshGradientProps.swift +13 -0
- package/ios/MeshGradientView.swift +23 -0
- package/package.json +40 -0
- package/src/MeshGradient.types.ts +41 -0
- package/src/MeshGradientView.tsx +7 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +9 -0
package/.eslintrc.js
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# expo-mesh-gradient
|
|
2
|
+
|
|
3
|
+
My new module
|
|
4
|
+
|
|
5
|
+
# API documentation
|
|
6
|
+
|
|
7
|
+
- [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/mesh-gradient/)
|
|
8
|
+
- [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/mesh-gradient/)
|
|
9
|
+
|
|
10
|
+
# Installation in managed Expo projects
|
|
11
|
+
|
|
12
|
+
For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
|
|
13
|
+
|
|
14
|
+
# Installation in bare React Native projects
|
|
15
|
+
|
|
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
|
+
|
|
18
|
+
### Add the package to your npm dependencies
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install expo-mesh-gradient
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Configure for Android
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Configure for iOS
|
|
30
|
+
|
|
31
|
+
Run `npx pod-install` after installing the npm package.
|
|
32
|
+
|
|
33
|
+
# Contributing
|
|
34
|
+
|
|
35
|
+
Contributions are very welcome! Please refer to guidelines described in the [contributing guide]( https://github.com/expo/expo#contributing).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
export type MeshGradientViewProps = {
|
|
3
|
+
style?: StyleProp<ViewStyle>;
|
|
4
|
+
/**
|
|
5
|
+
* Width of the mesh, i.e. the number of vertices per row.
|
|
6
|
+
* @default 0
|
|
7
|
+
*/
|
|
8
|
+
columns?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Height of the mesh, i.e. the number of vertices per column.
|
|
11
|
+
* @default 0
|
|
12
|
+
*/
|
|
13
|
+
rows?: number;
|
|
14
|
+
/**
|
|
15
|
+
* An array of two-dimensional points on the mesh. Must contain `columns * rows` elements.
|
|
16
|
+
*/
|
|
17
|
+
points?: number[][];
|
|
18
|
+
/**
|
|
19
|
+
* An array of colors. Must contain `columns * rows` elements.
|
|
20
|
+
* @default []
|
|
21
|
+
*/
|
|
22
|
+
colors?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Whether cubic (smooth) interpolation should be used for the colors in the mesh
|
|
25
|
+
* rather than only for the shape of the mesh.
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
smoothsColors?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to ignore safe areas when positioning the view.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
ignoresSafeArea?: boolean;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=MeshGradient.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeshGradient.types.d.ts","sourceRoot":"","sources":["../src/MeshGradient.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE7B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeshGradientView.d.ts","sourceRoot":"","sources":["../src/MeshGradientView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,QAAA,MAAM,UAAU,sDAA+D,CAAC;AAEhF,eAAe,UAAU,CAAC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2024-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import ExpoModulesCore
|
|
4
|
+
|
|
5
|
+
// Declares convertible conformance to `SIMD2<Float>` type which is commonly used in many SwiftUI APIs.
|
|
6
|
+
extension SIMD2: @retroactive Convertible, AnyArgument where Scalar == Float {
|
|
7
|
+
public static func convert(from value: Any?, appContext: AppContext) throws -> SIMD2<Float> {
|
|
8
|
+
guard let values = value as? [Any] else {
|
|
9
|
+
throw NotAnArrayException()
|
|
10
|
+
}
|
|
11
|
+
guard values.count == 2 else {
|
|
12
|
+
throw IncorrectArraySizeException((expected: 2, actual: values.count))
|
|
13
|
+
}
|
|
14
|
+
if let values = values as? [Double] {
|
|
15
|
+
// Numbers from JS always come as doubles.
|
|
16
|
+
return SIMD2(Float(values[0]), Float(values[1]))
|
|
17
|
+
}
|
|
18
|
+
if let values = values as? [Float] {
|
|
19
|
+
return SIMD2(values[0], values[1])
|
|
20
|
+
}
|
|
21
|
+
throw Conversions.ConvertingException<SIMD2<Float>>(value)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
internal final class NotAnArrayException: Exception {
|
|
26
|
+
override var reason: String {
|
|
27
|
+
"Given value is not an array"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
internal final class IncorrectArraySizeException: GenericException<(expected: Int, actual: Int)> {
|
|
32
|
+
override var reason: String {
|
|
33
|
+
"Given array has unexpected number of elements: \(param.actual), expected: \(param.expected)"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'ExpoMeshGradient'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = {
|
|
14
|
+
:ios => '15.1',
|
|
15
|
+
:tvos => '15.1'
|
|
16
|
+
}
|
|
17
|
+
s.swift_version = '5.4'
|
|
18
|
+
s.source = { git: 'https://github.com/expo/expo' }
|
|
19
|
+
s.static_framework = true
|
|
20
|
+
|
|
21
|
+
s.dependency 'ExpoModulesCore'
|
|
22
|
+
|
|
23
|
+
# Swift/Objective-C compatibility
|
|
24
|
+
s.pod_target_xcconfig = {
|
|
25
|
+
'DEFINES_MODULE' => 'YES',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
|
29
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2024-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import ExpoModulesCore
|
|
5
|
+
|
|
6
|
+
class MeshGradientProps: ExpoSwiftUI.ViewProps {
|
|
7
|
+
@Field var columns: Int = 0
|
|
8
|
+
@Field var rows: Int = 0
|
|
9
|
+
@Field var points: [SIMD2<Float>] = []
|
|
10
|
+
@Field var colors: [Color] = []
|
|
11
|
+
@Field var smoothsColors: Bool = true
|
|
12
|
+
@Field var ignoresSafeArea: Bool = true
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2024-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import ExpoModulesCore
|
|
5
|
+
|
|
6
|
+
struct MeshGradientView: ExpoSwiftUI.View {
|
|
7
|
+
@EnvironmentObject var props: MeshGradientProps
|
|
8
|
+
|
|
9
|
+
var body: some View {
|
|
10
|
+
if #available(iOS 18.0, *) {
|
|
11
|
+
MeshGradient(
|
|
12
|
+
width: props.columns,
|
|
13
|
+
height: props.rows,
|
|
14
|
+
points: props.points,
|
|
15
|
+
colors: props.colors,
|
|
16
|
+
smoothsColors: props.smoothsColors
|
|
17
|
+
)
|
|
18
|
+
.ignoresSafeArea(edges: props.ignoresSafeArea ? .all : [])
|
|
19
|
+
} else {
|
|
20
|
+
EmptyView()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "expo-mesh-gradient",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A module that exposes MeshGradient view from SwiftUI to React Native",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "expo-module build",
|
|
9
|
+
"clean": "expo-module clean",
|
|
10
|
+
"lint": "expo-module lint",
|
|
11
|
+
"test": "expo-module test",
|
|
12
|
+
"prepare": "expo-module prepare",
|
|
13
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
|
+
"expo-module": "expo-module",
|
|
15
|
+
"open:ios": "xed example/ios",
|
|
16
|
+
"open:android": "open -a \"Android Studio\" example/android"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"expo",
|
|
21
|
+
"expo-mesh-gradient",
|
|
22
|
+
"ExpoMeshGradient"
|
|
23
|
+
],
|
|
24
|
+
"repository": "https://github.com/tsapeta/expo-mesh-gradient",
|
|
25
|
+
"author": "Tomasz Sapeta (tsapeta)",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://github.com/expo/expo#readme",
|
|
28
|
+
"dependencies": {},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "~18.3.12",
|
|
31
|
+
"expo-module-scripts": "^4.0.2",
|
|
32
|
+
"expo": "~52.0.0",
|
|
33
|
+
"react-native": "0.76.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"expo": "*",
|
|
37
|
+
"react": "*",
|
|
38
|
+
"react-native": "*"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
|
|
3
|
+
export type MeshGradientViewProps = {
|
|
4
|
+
style?: StyleProp<ViewStyle>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Width of the mesh, i.e. the number of vertices per row.
|
|
8
|
+
* @default 0
|
|
9
|
+
*/
|
|
10
|
+
columns?: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Height of the mesh, i.e. the number of vertices per column.
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
rows?: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An array of two-dimensional points on the mesh. Must contain `columns * rows` elements.
|
|
20
|
+
*/
|
|
21
|
+
points?: number[][];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An array of colors. Must contain `columns * rows` elements.
|
|
25
|
+
* @default []
|
|
26
|
+
*/
|
|
27
|
+
colors?: string[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether cubic (smooth) interpolation should be used for the colors in the mesh
|
|
31
|
+
* rather than only for the shape of the mesh.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
smoothsColors?: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Whether to ignore safe areas when positioning the view.
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
ignoresSafeArea?: boolean;
|
|
41
|
+
};
|
package/src/index.ts
ADDED