Files
react-native-svg/package.json
Jakub Grzywacz 08e92074b4 feat: filters support FeColorMatrix and FilterImage (#2316)
# Summary

Introducing the long-awaited **Filters** in `react-native-svg` 🎉

### Motivation

This PR is the beginning of bringing support of SVG Filters into
`react-native-svg`.

* **related issues**: This PR series will address the following issues:
#150, #176, #635, #883, #994, #996, #1216
* **feature overview**: This PR is a boilerplate for Filters
   * introducing `Filter` component and `FeColorMatrix` as a start. 
* It also introduces a new subdirectory called
`react-native-svg/filter-image` with a `FilterImage` component.

# Usage

## Filter and Fe...

Filters are compatible with the web familiar standard, so most things
should be compatible out-of-the-box and changes will be limited to using
a capital letter as it's component.

### Example

```tsx
import React from 'react';
import { FeColorMatrix, Filter, Rect, Svg } from 'react-native-svg';

export default () => {
  return (
    <Svg height="300" width="300">
      <Filter id="myFilter">
        <FeColorMatrix type="saturate" values="0.2" />
      </Filter>
      <Rect
        x="0"
        y="0"
        width="300"
        height="300"
        fill="red"
        filter="url(#myFilter)"
      />
    </Svg>
  );
};
```

![image](https://github.com/software-mansion/react-native-svg/assets/39670088/c36fb238-95f4-455d-b0aa-2a7d4038b828)

## Filter Image

`FilterImage` is a new component that is not strictly related to SVG.
Its behavior should be the same as a regular `Image` component from
React Native with one exception - the additional prop `filters`, which
accepts an array of filters to apply to the image.

### Example

```tsx
import React from 'react';
import { StyleSheet } from 'react-native';
import { FilterImage } from 'react-native-svg/filter-image';

const myImage = require('./myImage.jpg');

export default () => {
  return (
    <FilterImage
      style={styles.image}
      source={myImage}
      filters={[
        { name: 'colorMatrix', type: 'saturate', values: 0.2 },
        {
          name: 'colorMatrix',
          type: 'matrix',
          values: [
            0.2, 0.2, 0.2, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0.2, 0.2, 0.2, 0, 0, 0, 0,
            0, 1, 0,
          ],
        },
      ]}
    />
  );
};
const styles = StyleSheet.create({
  image: {
    width: 200,
    height: 200,
  },
});
```


![image](https://github.com/software-mansion/react-native-svg/assets/39670088/666ed89f-68d8-491b-b97f-1eef112b7095)

## Test Plan

**Example App**: Updated the example app with various filter effects,
showcasing real-world usage.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |         |

## Checklist

- [x] I have tested this on a device and a simulator
- [x] I added documentation in `README.md` and `USAGE.md`
- [x] I updated the typed files (typescript)
2024-07-11 11:17:35 +02:00

125 lines
3.5 KiB
JSON

{
"version": "15.3.0",
"name": "react-native-svg",
"description": "SVG library for react-native",
"homepage": "https://github.com/react-native-community/react-native-svg",
"repository": {
"type": "git",
"url": "https://github.com/react-native-community/react-native-svg"
},
"license": "MIT",
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
"types": "lib/typescript/index.d.ts",
"react-native": "src/index.ts",
"files": [
"android",
"apple",
"common",
"lib",
"src",
"css",
"filter-image",
"RNSVG.podspec",
"!android/build",
"windows",
"react-native.config.js"
],
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
"commonjs",
"module",
"typescript"
]
},
"keywords": [
"react-component",
"react-native",
"ios",
"android",
"windows",
"SVG",
"ART",
"VML",
"gradient"
],
"scripts": {
"bob": "bob build",
"format": "yarn format-js && yarn format-ios && yarn format-java",
"format-ios": "find apple/ common/ -iname *.h -o -iname *.m -o -iname *.cpp -o -iname *.mm | xargs clang-format -i",
"format-java": "node ./scripts/format-java.js",
"format-js": "prettier --write README.md CONTRIBUTING.md CODE_OF_CONDUCT.md USAGE.md ./src/**/*.{ts,tsx} ./apps/**/*.tsx ./example/**/*.tsx ./*-example/**/*.tsx",
"jest": "jest",
"lint": "eslint --ext .ts,.tsx src",
"peg": "pegjs -o src/lib/extract/transform.js ./src/lib/extract/transform.peg",
"prepare": "npm run bob && husky install",
"release": "npm login && release-it",
"test": "npm run lint && npm run tsc",
"tsc": "tsc --noEmit"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"dependencies": {
"css-select": "^5.1.0",
"css-tree": "^1.1.3",
"warn-once": "0.1.1"
},
"devDependencies": {
"@react-native-community/eslint-config": "^3.0.2",
"@react-native-community/eslint-plugin": "^1.2.0",
"@react-native/babel-plugin-codegen": "^0.71.0",
"@react-native/eslint-config": "^0.72.2",
"@types/css-tree": "^1.0.3",
"@types/jest": "^27.5.2",
"@types/node": "*",
"@types/react": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^28.1.0",
"babel-plugin-module-resolver": "^5.0.0",
"clang-format": "^1.8.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-babel-module": "^5.3.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-standard": "^5.0.0",
"husky": "^8.0.1",
"jest": "^28.1.0",
"lint-staged": "^13.0.3",
"pegjs": "^0.10.0",
"prettier": "3.0.1",
"react": "^18.2.0",
"react-native": "^0.72.3",
"react-native-builder-bob": "^0.20.4",
"react-native-windows": "^0.72.4",
"react-test-renderer": "^18.2.0",
"release-it": "^14.12.5",
"ts-node": "^10.8.0",
"typescript": "^5.1.6"
},
"lint-staged": {
"{src,Example}/**/*.{js,ts,tsx}": "yarn format-js",
"src/**/*.{js,ts,tsx}": "yarn lint",
"apple/**/*.{h,m,mm,cpp}": "yarn format-ios",
"android/src/**/*.java": "yarn format-java"
},
"nativePackage": true,
"codegenConfig": {
"name": "rnsvg",
"type": "all",
"jsSrcsDir": "./src/fabric",
"android": {
"javaPackageName": "com.horcrux.svg"
}
}
}