react-native-vector-image 0.5.1 → 0.5.3
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/README.md +14 -0
- package/package.json +9 -1
- package/src/index.d.ts +5 -1
- package/src/index.js +14 -7
package/README.md
CHANGED
|
@@ -86,6 +86,20 @@ yarn react-native run-ios
|
|
|
86
86
|
yarn react-native run-android
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
### Optional: using source/drawable
|
|
90
|
+
|
|
91
|
+
If you need to use the underlying image source/drawable you can use the `VectorImage.resolveAssetSource` method, for example with Expo's native tabs:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
const iconSource = VectorImage.resolveAssetSource(require('./icon.svg'));
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<NativeTabs.Trigger name="index">
|
|
98
|
+
<Icon src={iconSource} drawable={iconSource.uri} />
|
|
99
|
+
</NativeTabs.Trigger>
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
89
103
|
## Troubleshooting
|
|
90
104
|
|
|
91
105
|
### `generate` command outputs "Error while parsing image.svg"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-vector-image",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Native vector images generated from SVG",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -42,6 +42,14 @@
|
|
|
42
42
|
"tempy": "^1.0.1",
|
|
43
43
|
"yargs": "^16.2.0"
|
|
44
44
|
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"expo": ">=47.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"expo": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
45
53
|
"devDependencies": {
|
|
46
54
|
"jest": "^26.6.3",
|
|
47
55
|
"metro": ">=0.83.3",
|
package/src/index.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface VectorImageProps extends ImageProps {
|
|
|
8
8
|
source: ImageRequireSource;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export function resolveVectorAssetSource(source: ImageRequireSource): { uri: string; width: number; height: number } | null;
|
|
12
|
+
|
|
13
|
+
declare const VectorImage: React.FunctionComponent<VectorImageProps> & {
|
|
14
|
+
resolveAssetSource: typeof resolveVectorAssetSource;
|
|
15
|
+
};
|
|
12
16
|
|
|
13
17
|
export default VectorImage;
|
package/src/index.js
CHANGED
|
@@ -3,20 +3,27 @@ import { Image } from 'react-native';
|
|
|
3
3
|
import { getAssetByID } from '@react-native/assets-registry/registry';
|
|
4
4
|
import getResourceName from './getResourceName';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export function resolveVectorAssetSource(source) {
|
|
7
7
|
const asset = getAssetByID(source);
|
|
8
|
+
if (!asset) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const resourceName = getResourceName(asset);
|
|
12
|
+
return { uri: resourceName,width: asset.width, height: asset.height }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function VectorImage({ source, ...props }) {
|
|
16
|
+
const asset = resolveVectorAssetSource(source);
|
|
8
17
|
if (!asset) {
|
|
9
18
|
console.warn(
|
|
10
19
|
`No asset registered for source "${source}", you may have to generate assets and recompile`
|
|
11
20
|
);
|
|
12
21
|
return null;
|
|
13
22
|
}
|
|
14
|
-
|
|
23
|
+
|
|
15
24
|
return (
|
|
16
|
-
<Image
|
|
17
|
-
source={{ uri: resourceName }}
|
|
18
|
-
style={[{ width: asset.width, height: asset.height }, style]}
|
|
19
|
-
{...props}
|
|
20
|
-
/>
|
|
25
|
+
<Image source={asset} {...props} />
|
|
21
26
|
);
|
|
22
27
|
}
|
|
28
|
+
|
|
29
|
+
VectorImage.resolveAssetSource = resolveVectorAssetSource;
|