Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filters support FeColorMatrix and FilterImage #2316

Merged
merged 45 commits into from
Jul 11, 2024

Conversation

jakex7
Copy link
Member

@jakex7 jakex7 commented Jun 28, 2024

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.

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

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

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

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

Test Plan

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

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added documentation in README.md and USAGE.md
  • I updated the typed files (typescript)

@jakex7 jakex7 requested a review from WoLewicki June 28, 2024 09:08
@jakex7 jakex7 force-pushed the @jakex7/filtersFeColorMatrix branch from 1c2ca46 to e0941b8 Compare July 1, 2024 14:22
Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving some comments for now.

Example/src/examples/FilterImage/index.tsx Outdated Show resolved Hide resolved
Example/src/examples/Filters/index.tsx Outdated Show resolved Hide resolved
import {View} from 'react-native';
import {FilterImage} from 'react-native-svg/filter-image';

const testImage = require('../../assets/image.jpg');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the name of this image (and others too) to be more descriptive in some follow-up PR.

README.md Show resolved Hide resolved
android/src/main/java/com/horcrux/svg/SvgView.java Outdated Show resolved Hide resolved
apple/Filters/RNSVGFeColorMatrix.mm Outdated Show resolved Hide resolved
apple/Filters/RNSVGFilter.mm Show resolved Hide resolved
apple/RNSVGNode.mm Outdated Show resolved Hide resolved
apple/RNSVGRenderable.mm Show resolved Hide resolved
apple/Utils/RNSVGRenderUtils.h Outdated Show resolved Hide resolved
Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I finished the review! Great job 🚀 I left some more comments, please answer them.

src/lib/extract/extractFilter.ts Outdated Show resolved Hide resolved
src/lib/extract/extractFilter.ts Outdated Show resolved Hide resolved
src/elements/filters/FilterPrimitive.tsx Outdated Show resolved Hide resolved
src/lib/extract/extractFilter.ts Show resolved Hide resolved
src/lib/extract/extractOpacity.ts Outdated Show resolved Hide resolved
Comment on lines 2 to 9
import {
Svg,
FeColorMatrix,
Filter,
Image,
FeColorMatrixProps,
} from '../index';
import { FilterPrimitiveStandardAttributes } from '../elements/filters/FilterPrimitive';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we import those similar to as we import things from the main package in css:

import { camelCase, fetchText, parse, SvgAst } from 'react-native-svg';
?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When importing from react-native-svg types seems to be not recognized

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not good and we should fix it in both places. So if it works, let's leave it like this for now.

src/filter-image/FilterImage.tsx Show resolved Hide resolved
src/filter-image/FilterImage.tsx Outdated Show resolved Hide resolved
src/filter-image/FilterImage.tsx Show resolved Hide resolved
src/filter-image/FilterImage.tsx Outdated Show resolved Hide resolved
@jakex7 jakex7 requested a review from WoLewicki July 3, 2024 13:39
Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments. When you apply those, I think we are ready for merging!

src/elements/filters/Filter.tsx Outdated Show resolved Hide resolved
Comment on lines 2 to 9
import {
Svg,
FeColorMatrix,
Filter,
Image,
FeColorMatrixProps,
} from '../index';
import { FilterPrimitiveStandardAttributes } from '../elements/filters/FilterPrimitive';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not good and we should fix it in both places. So if it works, let's leave it like this for now.

Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jakex7 jakex7 merged commit 08e9207 into main Jul 11, 2024
7 checks passed
@jakex7 jakex7 deleted the @jakex7/filtersFeColorMatrix branch July 17, 2024 14:42
jakex7 added a commit that referenced this pull request Jul 25, 2024
# Summary

Continuation of #2316 
Introducing new filter `FeGaussianBlur`.

### Implementation notes

On Android there is no easy way to fully implement Gaussian blur, as
there is no native api for this. While a basic implementation is
possible with `RenderScript`, it does not allow for blur in one axis and
greater than `25`

## Test Plan

Example app -> Filters -> FeGaussianBlur

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |    ✅     |
| Android |    ✅     |
jakex7 added a commit that referenced this pull request Jul 25, 2024
# Summary

Continuation of #2316
Introducing new filter `FeOffset`.

## Test Plan

Example app -> Filters -> FeOffset

## Compatibility

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

## Checklist

- [x] I have tested this on a device and a simulator
- [x] I added documentation in `README.md`
- [x] I updated the typed files (typescript)
github-merge-queue bot referenced this pull request in valora-inc/wallet Aug 5, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[react-native-svg](https://github.com/react-native-community/react-native-svg)
| [`^15.3.0` ->
`^15.4.0`](https://renovatebot.com/diffs/npm/react-native-svg/15.3.0/15.4.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/react-native-svg/15.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/react-native-svg/15.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/react-native-svg/15.3.0/15.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-native-svg/15.3.0/15.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>react-native-community/react-native-svg
(react-native-svg)</summary>

###
[`v15.4.0`](https://github.com/software-mansion/react-native-svg/releases/tag/v15.4.0)

[Compare
Source](https://github.com/react-native-community/react-native-svg/compare/v15.3.0...v15.4.0)

Introducing the long-awaited filters in react-native-svg! 🎉
This minor release includes the first filter, FeColorMatrix, along with
numerous fixes and other improvements.

#### What's Changed

- fix: error when building paper after fabric by
[@&#8203;maciekstosio](https://github.com/maciekstosio) in
[https://github.com/software-mansion/react-native-svg/pull/2281](https://github.com/software-mansion/react-native-svg/pull/2281)
- Handle error when pass wrong uri to SvgFromUri component by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2289](https://github.com/software-mansion/react-native-svg/pull/2289)
- chore: TestsExample app fix reanimated and metro.config issues by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2291](https://github.com/software-mansion/react-native-svg/pull/2291)
- chore: remove macos-build-test.yml by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2292](https://github.com/software-mansion/react-native-svg/pull/2292)
- chore: add hire us section to readme by
[@&#8203;kacperkapusciak](https://github.com/kacperkapusciak) in
[https://github.com/software-mansion/react-native-svg/pull/2295](https://github.com/software-mansion/react-native-svg/pull/2295)
- feat: github action close-when-stale by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2296](https://github.com/software-mansion/react-native-svg/pull/2296)
- fixed pars on Android platform prop strokeDasharray by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2294](https://github.com/software-mansion/react-native-svg/pull/2294)
- feat: add new bug issue template, and github actions by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2300](https://github.com/software-mansion/react-native-svg/pull/2300)
- fix: issue template by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2301](https://github.com/software-mansion/react-native-svg/pull/2301)
- fix: example app package.json file and yarn.lock by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2303](https://github.com/software-mansion/react-native-svg/pull/2303)
- fix: handle onPress prop on web app by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2302](https://github.com/software-mansion/react-native-svg/pull/2302)
- fix: android PathParser crash app if pass some wrong d prop by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2308](https://github.com/software-mansion/react-native-svg/pull/2308)
- fix: scaling when mask is set by
[@&#8203;jakex7](https://github.com/jakex7) in
[https://github.com/software-mansion/react-native-svg/pull/2299](https://github.com/software-mansion/react-native-svg/pull/2299)
- add onLoad prop to Image component by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2293](https://github.com/software-mansion/react-native-svg/pull/2293)
- feat: update needs-more-info git workflow by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2314](https://github.com/software-mansion/react-native-svg/pull/2314)
- fix: new arch invalidate on mount/unmount by
[@&#8203;jakex7](https://github.com/jakex7) in
[https://github.com/software-mansion/react-native-svg/pull/2318](https://github.com/software-mansion/react-native-svg/pull/2318)
- Fix: image onLoad props by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2317](https://github.com/software-mansion/react-native-svg/pull/2317)
- feat(windows): add support for 74 and bump Example by
[@&#8203;marlenecota](https://github.com/marlenecota) in
[https://github.com/software-mansion/react-native-svg/pull/2315](https://github.com/software-mansion/react-native-svg/pull/2315)
- feat: add Example Windows build workflow by
[@&#8203;marlenecota](https://github.com/marlenecota) in
[https://github.com/software-mansion/react-native-svg/pull/2322](https://github.com/software-mansion/react-native-svg/pull/2322)
- fix: add check in RNSVGImage for macos platform by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2324](https://github.com/software-mansion/react-native-svg/pull/2324)
- Add correct invalidate calls to SvgView on ios with test by
[@&#8203;Kicu](https://github.com/Kicu) in
[https://github.com/software-mansion/react-native-svg/pull/2327](https://github.com/software-mansion/react-native-svg/pull/2327)
- fix: extract opacity use percentage values by
[@&#8203;jakex7](https://github.com/jakex7) in
[https://github.com/software-mansion/react-native-svg/pull/2325](https://github.com/software-mansion/react-native-svg/pull/2325)
- feat: change folders structure by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2319](https://github.com/software-mansion/react-native-svg/pull/2319)
- Implement mask-type property by
[@&#8203;SergeyYurkevich](https://github.com/SergeyYurkevich) in
[https://github.com/software-mansion/react-native-svg/pull/2152](https://github.com/software-mansion/react-native-svg/pull/2152)
- feat: extract web example by
[@&#8203;bohdanprog](https://github.com/bohdanprog) in
[https://github.com/software-mansion/react-native-svg/pull/2333](https://github.com/software-mansion/react-native-svg/pull/2333)
- fix: macos mask by [@&#8203;jakex7](https://github.com/jakex7) in
[https://github.com/software-mansion/react-native-svg/pull/2337](https://github.com/software-mansion/react-native-svg/pull/2337)
- fix: fix format-js task to reflect changes made to folder structure by
[@&#8203;CDFN](https://github.com/CDFN) in
[https://github.com/software-mansion/react-native-svg/pull/2342](https://github.com/software-mansion/react-native-svg/pull/2342)
- Add missing `#include <folly/dynamic.h>` on RN 0.75 by
[@&#8203;tomekzaw](https://github.com/tomekzaw) in
[https://github.com/software-mansion/react-native-svg/pull/2344](https://github.com/software-mansion/react-native-svg/pull/2344)
- feat: filters support FeColorMatrix and FilterImage by
[@&#8203;jakex7](https://github.com/jakex7) in
[https://github.com/software-mansion/react-native-svg/pull/2316](https://github.com/software-mansion/react-native-svg/pull/2316)
- fix: mask and filters rendering issues by
[@&#8203;jakex7](https://github.com/jakex7) in
[https://github.com/software-mansion/react-native-svg/pull/2345](https://github.com/software-mansion/react-native-svg/pull/2345)

#### New Contributors

- [@&#8203;maciekstosio](https://github.com/maciekstosio) made their
first contribution in
[https://github.com/software-mansion/react-native-svg/pull/2281](https://github.com/software-mansion/react-native-svg/pull/2281)
- [@&#8203;bohdanprog](https://github.com/bohdanprog) made their first
contribution in
[https://github.com/software-mansion/react-native-svg/pull/2289](https://github.com/software-mansion/react-native-svg/pull/2289)
- [@&#8203;Kicu](https://github.com/Kicu) made their first
contribution in
[https://github.com/software-mansion/react-native-svg/pull/2327](https://github.com/software-mansion/react-native-svg/pull/2327)
- [@&#8203;SergeyYurkevich](https://github.com/SergeyYurkevich) made
their first contribution in
[https://github.com/software-mansion/react-native-svg/pull/2152](https://github.com/software-mansion/react-native-svg/pull/2152)
- [@&#8203;CDFN](https://github.com/CDFN) made their first
contribution in
[https://github.com/software-mansion/react-native-svg/pull/2342](https://github.com/software-mansion/react-native-svg/pull/2342)

**Full Changelog**:
software-mansion/react-native-svg@v15.3.0...v15.4.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone
America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone
America/Los_Angeles.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/valora-inc/wallet).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzguMCIsInVwZGF0ZWRJblZlciI6IjM3LjQzOC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJucG0iLCJyZW5vdmF0ZSJdfQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: valora-bot <[email protected]>
Co-authored-by: Alex Bakoushin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants