react-native-vector-image 0.3.2 → 0.4.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/README.md CHANGED
@@ -74,6 +74,8 @@ yarn react-native-vector-image generate
74
74
  | `--no-ios-output` | Disable iOS output. | `false` |
75
75
  | `--android-output` | Path to an Android `res` folder. | `android/app/src/main/res` |
76
76
  | `--no-android-output` | Disable Android output. | `false` |
77
+ | `--current-color` | Replace any `current` color references in SVGs. | `#000000` |
78
+ | `--current-color-dark` | Replace any `current` color references in `.dark.svg` SVGs. | `#ffffff` |
77
79
 
78
80
  ### Step 3: recompile
79
81
 
@@ -93,6 +95,10 @@ Some optimizations applied by SVGO are not compatible with the SVG parser on And
93
95
 
94
96
  It means that the native vector asset does not exist or is out of sync with the SVG. Simply generate the files and recompile the app.
95
97
 
98
+ ### the `generate` command does not generate any new assets
99
+
100
+ Make sure your image component is used (imported) somewhere in your code, otherwise the asset generator won't find it.
101
+
96
102
  ## License
97
103
 
98
104
  [MIT License](http://opensource.org/licenses/mit-license.html). © Joel Arvidsson 2021
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vector-image",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Native vector images generated from SVG",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -5,6 +5,7 @@ const generateAndroidAsset = require('./generateAndroidAsset');
5
5
  const getAssets = require('./getAssets');
6
6
  const getResourceName = require('../getResourceName');
7
7
  const resolveAssetSources = require('./resolveAssetSources');
8
+ const readSvgAsset = require('./readSvgAsset');
8
9
  const { InputError, TransformationError } = require('./errors');
9
10
 
10
11
  async function removeGeneratedAssets(directory) {
@@ -28,6 +29,8 @@ async function generateAssets({
28
29
  config,
29
30
  entryFile,
30
31
  resetCache,
32
+ currentColor,
33
+ currentColorDark,
31
34
  }) {
32
35
  const assets = await getAssets({ config, entryFile, resetCache });
33
36
 
@@ -54,8 +57,8 @@ async function generateAssets({
54
57
 
55
58
  const resourceName = getResourceName(asset);
56
59
  const source = {
57
- light: fs.readFileSync(light).toString(),
58
- dark: dark && fs.readFileSync(dark).toString(),
60
+ light: readSvgAsset(light, currentColor),
61
+ dark: dark && readSvgAsset(dark, currentColorDark),
59
62
  width: asset.width,
60
63
  height: asset.height,
61
64
  };
@@ -9,11 +9,14 @@ async function getAssets(options) {
9
9
  dev: false,
10
10
  minify: false,
11
11
  platform: 'ios',
12
- resetCache: options.resetCache,
13
12
  };
14
13
 
15
14
  const config = await loadConfig(
16
- { cwd: process.cwd(), config: options.config },
15
+ {
16
+ cwd: process.cwd(),
17
+ config: options.config,
18
+ resetCache: options.resetCache,
19
+ },
17
20
  {
18
21
  resolver: {
19
22
  resolverMainFields: ['react-native', 'browser', 'main'],
package/src/cli/index.js CHANGED
@@ -44,6 +44,16 @@ function main(argv) {
44
44
  description: 'Path to an Android `res` folder',
45
45
  default: 'android/app/src/main/res',
46
46
  },
47
+ 'current-color': {
48
+ description: 'Replace any `current` color references in SVGs.',
49
+ default: '#000000',
50
+ type: 'string',
51
+ },
52
+ 'current-color-dark': {
53
+ description: 'Replace any `current` color references in `.dark.svg` SVGs.',
54
+ default: '#ffffff',
55
+ type: 'string',
56
+ },
47
57
  },
48
58
  async (options) => {
49
59
  try {
@@ -0,0 +1,12 @@
1
+ const fs = require('fs');
2
+
3
+ const readSvgAsset = (path, currentColor) =>
4
+ fs
5
+ .readFileSync(path)
6
+ .toString()
7
+ .replace(
8
+ /\s(fill|stroke|stop-color|flood-color|lighting-color)=["']current["']/g,
9
+ (_, attribute) => ` ${attribute}="${currentColor}"`
10
+ );
11
+
12
+ module.exports = readSvgAsset;
package/strip_svgs.gradle CHANGED
@@ -1,11 +1,10 @@
1
1
  // This script removes .svg files generated by metro.
2
2
 
3
3
  gradle.projectsEvaluated {
4
- def bundleTasks = tasks.findAll { task -> task.name.startsWith("bundle") && task.name.endsWith("JsAndAssets") && !task.name.contains("Debug") && task.enabled }
5
4
  android.applicationVariants.all { def variant ->
6
5
  def targetName = variant.name.capitalize()
7
6
  def targetPath = variant.dirName
8
- def bundleTask = tasks.findByName("bundle${targetName}JsAndAssets")
7
+ def bundleTask = tasks.findByName("createBundle${targetName}Resources") ?: tasks.findByName("bundle${targetName}Resources")
9
8
  def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
10
9
  def cleanUpTask = tasks.create(name: "${bundleTask.name}_VectorImageCleanUp", type: Delete) {
11
10
  description = "strip generated svg assets"