Commit Graph

630 Commits

Author SHA1 Message Date
Jakub Grzywacz
16baf27a50 fix: crop rect invalid bounds crash (#2494)
# Summary

Do not crash on `getCropRect` call when renderableBounds is null

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |          |
2024-10-17 11:34:37 +02:00
Jakub Grzywacz
93df20ca3f remove: deprecated sourceSets (#2493)
# Summary

Remove deprecated sourceSet and drop support for `react-native@0.72` to
simplify codebase.
2024-10-17 11:11:24 +02:00
Jakub Grzywacz
096fdc22a5 feat: FeBlend (#2489)
# Summary

Continuation of #2362 implementing `FeBlend` filter
https://www.w3.org/TR/SVG11/filters.html#feBlendElement

## Test Plan

Example app → Filters → `FeBlend`

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |          |
| macOS   |     _*_      |
| Android |          |
| Web     |          |
2024-10-16 11:45:44 +02:00
Jakub Grzywacz
cb30bd66d5 fix: filter subregion depend on primitive units not filter units (#2490)
# Summary

This fix addresses a minor bug/typo that was recently introduced, where
the filter subregion was incorrectly relying on filterUnits instead of
primitiveUnits.
2024-10-16 11:36:13 +02:00
Jakub Grzywacz
ba54b15799 feat: FeFlood (#2487)
# Summary

Continuation of #2362 implementing `FeFlood` filter
https://www.w3.org/TR/SVG11/filters.html#feFloodElement

## Test Plan

Example app → Filters → `FeFlood`

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |          |
| macOS   |     _*_      |
| Android |          |
| Web     |          |

_* `canvasWidth/canvasHeight` is incorrect on macOS, so there might be
some problems_
2024-10-15 09:35:13 +02:00
Jakub Grzywacz
8fed77476b feat: properly implement filter region unit USER_SPACE_ON_USE (#2486)
# Summary

After deep dive into the specification, I found out that the default
filter subregion is not equal to `0% 0% 100% 100%`, rather the size of
the parent filter region.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |          |
| MacOS   |          |
| Android |          |
2024-10-14 15:35:16 +02:00
Jakub Grzywacz
3aae632d1f feat: implement filter region lengths directly on RNSVGFilterRegion (#2485)
# Summary

[apple] Use filter region directly instead of creating new one on every
rerender.
[android] rename some variables and add temporary fix for null lengths
2024-10-14 14:47:44 +02:00
Jakub Grzywacz
690cddd2f7 feat: improve animating colors (#2471)
# Summary

Currently on Fabric, you cannot animate color properties like `fill` or
`stroke` using Animated with `useNativeDriver: true` or Reanimated.
That's because we have custom structure that needs to be parsed on `JS`
and looks like:

```ts
type ColorStruct = Readonly<{
  type?: WithDefault<Int32, -1>;
  payload?: ColorValue;
  brushRef?: string;
}>;
```

However, special values like `currentColor` / `context-fill` /
`context-stroke` / `/^url\(#(.+)\)$/` can not be animated anyway.
Instead, we should allow passing `ColorValue` directly and detect on the
native side if its ColorValue or ColorStruct.

## Test Plan

Example app -> TestX

## Compatibility

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

## Checklist

- [x] I have tested this on a device and a simulator
- [ ] I added documentation in `README.md`
2024-10-04 14:20:54 +02:00
Jakub Grzywacz
9d9958264b feat: properly implement currentColor (#2466)
# Summary

Motivated by issue #2455, I decided to implement the `currentColor`
property in line with the specs
(https://www.w3.org/TR/SVG11/color.html#ColorProperty). This involves
adding the `color` property to all renderable nodes.

## Test Plan

Example app -> `Test2455`

<img width="344" alt="image"
src="https://github.com/user-attachments/assets/ccaf5a79-4097-49f8-8948-0158d9d9274c">

```svg
<Svg color="red" width="60" height="60" viewBox="0 0 24 24" fill="none">
  <Path d="M22.7927 11.1242C21.359 18.5187 12.0003 22.7782 12.0003 22.7782C12.0003 22.7782 2.64153 18.5187 1.20661 11.1242C0.326598 6.58719 2.24925 2.02329 7.13701 2.00007C10.7781 1.98296 12.0003 5.65211 12.0003 5.65211C12.0003 5.65211 13.2226 1.98173 16.8624 2.00007C21.7612 2.02329 23.6727 6.58841 22.7927 11.1242Z" fill="currentColor"/>
  <G color="green" fill="purple">
    <G>
      <Rect x="16" y="16" width="8" height="8" fill="currentColor"/>
      <G color="pink">
        <Rect x="0" y="16" width="8" height="8" color="gold" fill="currentColor"/>
        <Circle cx="12" cy="20" r="4" fill="currentColor"/>
      </G>
    </G>
  </G>
</Svg>
```
## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |          |
| MacOS   |          |
| Android |          |
2024-09-30 15:50:37 +02:00
Jakub Grzywacz
cd47aece7e style: format and rename variables (#2469)
# Summary

Formatting and rename variable committed in #2415
2024-09-30 14:25:04 +02:00
Jakub Grzywacz
cc961774e7 fix: do not crash when borderRadius is set on Android (#2415)
# Summary

Fixes #2462
Currently, on Android, when `borderRadius` style is applied to a `Svg`
component an error occurs, stating `Cannot cast Double to Float`

This PR updates the codegen types, changing them from Double to Dynamic,
aligning with the implementation with the ViewProps.

## Test

### Tested on

- [x] react-native@0.76.0-rc.1
- [x] react-native@0.75.1
- [x] react-native@0.74.2
- [x] react-native@0.73.9

### Test case
```jsx
<Svg
  width="60"
  height="60"
  viewBox="0 0 24 24"
  style={{
    borderRadius: 16.2,
    borderTopLeftRadius: 16.2,
    borderBottomRightRadius: 16.2,
    borderStartStartRadius: 16.2,
    borderStartEndRadius: 16.2,
    borderTopRightRadius: 16.2,
    borderBottomLeftRadius: 16.2,
    borderTopStartRadius: 16.2,
    borderTopEndRadius: 16.2,
    borderBottomStartRadius: 16.2,
    borderBottomEndRadius: 16.2,
    borderEndEndRadius: 16.2,
    borderEndStartRadius: 16.2,
  }}>
  <Rect x="0" y="0" width="24" height="24" fill="red" />
</Svg>
```

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |          |
2024-09-30 13:02:40 +02:00
Jakub Grzywacz
712201a19e feat: implement maskUnits (#2457)
# Summary

Without the `maskUnits` attribute, masks may not render correctly, as
seen in issue #2449. This pull request adds support for `maskUnits` and
ensures proper cropping within the mask boundaries.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |          |
| MacOS   |          |
| Android |          |
2024-09-23 14:03:15 +02:00
Jakub Grzywacz
9df974194f refactor: use node resolver to locate React Native package (#2461)
# Summary

Twin pull request to
https://github.com/software-mansion/react-native-reanimated/pull/6482
2024-09-19 12:18:59 +02:00
Jakub Grzywacz
9049089954 fix: masked element layer opacity when previous item has stroke opacity (#2456)
# Summary

On Android when element before masked element has strokeOpacity
different from 1, the paint is reused to draw an offscreen layer
resulting in wrong opacity. Partially fixes (only on Android) #2449

## Test Plan

Add `stroke` and `strokeOpacity` to element directly before masked
element.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |          |
2024-09-18 13:13:59 +02:00
Jakub Grzywacz
b65b3c2679 feat: support react-native@0.76 (#2445)
# Summary

This PR adds support for React Native 0.76 (currently: 0.76.0-rc.0).
2024-09-17 11:02:48 +02:00
Jakub Grzywacz
2b081e5878 fix: transform scale on android (#2452)
# Summary

Undo these changes
https://github.com/software-mansion/react-native-svg/pull/2403/files#diff-7f8adeb6e7faded1a7ef711b4fa9d2b12d29ff386217e838c4551866afdd8bef
that introduced a bug described here
https://github.com/software-mansion/react-native-svg/issues/2442#issuecomment-2354170651
2024-09-17 09:56:27 +02:00
Jakub Grzywacz
51a4e0289a fix: render G offscreen only when it's needed (opacity != 1) (#2450)
# Summary

Improve #2417 by applying offscreen canvas only when opacity attribute
is set

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |          |
2024-09-16 15:21:02 +02:00
Jakub Grzywacz
d05f69e3d7 fix: Android group opacity prop (#2417)
# Summary

Currently, on Android, when the `opacity` prop is applied to `G` or
`Svg` elements, it is rendered incorrectly. Instead of rendering the
children "offscreen" and then applying the opacity to the entire result,
the child elements themselves are rendered with the specified opacity.

Fixes #2046

## Example

```tsx
import {View} from 'react-native';
import {G, Rect, Svg} from 'react-native-svg';

export default function App() {
  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      <Svg width="150" height="150" viewBox="0 0 150 150">
        <G opacity="0.5">
          <Rect width="100" height="100" fill="red" />
          <Rect x="50" y="50" width="100" height="100" fill="green" />
        </G>
      </Svg>

      <Svg width="150" height="150" viewBox="0 0 150 150" opacity="0.5">
        <Rect width="100" height="100" fill="red" />
        <Rect x="50" y="50" width="100" height="100" fill="green" />
      </Svg>
    </View>
  );
}
```

| Before | After | Web reference | 
| --- | --- | --- |
| <img width="200" alt="Zrzut ekranu 2024-08-20 o 15 44 13"
src="https://github.com/user-attachments/assets/68c57f7d-0375-4703-8c3c-a358fe124daa">
| <img width="200" alt="Zrzut ekranu 2024-08-20 o 15 44 26"
src="https://github.com/user-attachments/assets/ae7e24b9-edae-4b44-8785-3fc95a39fdd4">
| <img width="190" alt="image"
src="https://github.com/user-attachments/assets/1aa0491f-2936-4845-b18c-1fa669c34118">
|


## Test Plan

Example above is available in `test-examples` app as `Test2417`

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |         |
2024-09-12 13:42:55 +02:00
Jakub Grzywacz
85be1d0bac feat: implement filter region (#2441)
# Summary

Implement proper handling for filter region according to the specs:
*
[FilterEffectsRegion](https://www.w3.org/TR/SVG11/filters.html#FilterEffectsRegion)
*
[FilterPrimitiveSubRegion](https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion)

enabling user to specify 
* `filterUnits`
* `primitiveUnits`
* `x`
* `y`
* `width`
* `height`

on `Filter` element and the last four on filter primitives.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |          |
| MacOS   |         |
| Android |          |
| Web     |          |
2024-09-12 12:13:05 +02:00
Jakub Grzywacz
fbc66311a9 fix: add deprecated SvgViewManager to not break 0.72 (#2435)
# Summary

Fixes #2428
To not introduce the breaking change in minor version, it restores the
old `SvgViewManager.java` on RN <= 72 using sourceSets

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |          |
2024-09-02 15:28:54 +02:00
Jakub Grzywacz
8d3a03e6be fix: reset paint settings before drawing final bitmap (#2439)
# Summary

Fixes #2436.
#2403 introduced shared `Paint` between the node render method and the
final bitmap. However, Paint properties are not cleared after drawing,
so we need to call the `.clear()` method and re-enable antialiasing.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |         |
2024-09-02 13:27:10 +02:00
Jakub Grzywacz
53ba6f2413 fix: android svg scale 0 (#2424)
# Summary

Fixes #2421, bug introduced in
https://github.com/software-mansion/react-native-svg/pull/2403/files#diff-7f8adeb6e7faded1a7ef711b4fa9d2b12d29ff386217e838c4551866afdd8befR286
this line. When bitmap size is less or equal to 0 we want to stop
rendering the SVG to avoid Android crash.

## Test Plan

Set `transform="scale(0)"` to `Svg` element.

## Compatibility

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

## Checklist

- [x] I have tested this on a device and a simulator
2024-08-23 12:31:05 +02:00
Jakub Grzywacz
d11d892496 feat: rewrite Svg transform (#2403)
# Summary

Currently, when applying transforms depending on the type (RN style vs
SVG style) transforms behave differently giving wrong results.

Example component
```tsx
<Svg
  height="200"
  viewBox="0 0 200 200"
  width="200"
  // transform={[{scale: 2}]}
  // transform="scale(2)"
  // transform={[{rotate: '45deg'}]}
  // transform="rotate(45)"
  // transform={[{translateX: 100}, {translateY: 100}]}
  // transform="translate(100 100)"
>
  <Mask id="myMask">
    <Rect fill="white" height="100" width="100" x="0" y="0" />
    <Path d="M10,35 A20,20,0,0,1,50,35 A20,20,0,0,1,90,35 Q90,65,50,95 Q10,65,10,35 Z" />
  </Mask>
  <Rect fill="pink" height="200" width="300" x="0" y="0" />
  <Circle cx="50" cy="50" fill="purple" mask="url(#myMask)" r="50" />
  <Rect fill="green" x="50" y="100" width="100" height="100" />
</Svg>
```
| Attribute | Before | After |
| --- | --- | --- |
| `transform={[{scale: 2}]}` | <img width="250" alt="image"
src="https://github.com/user-attachments/assets/c04d7e11-e039-4d1a-b804-e993f3877b6a">
| <img width="250" alt="image"
src="https://github.com/user-attachments/assets/bb717ae4-7c8f-410a-942d-1bd6feab273c">
|
| `transform="scale(2)"` | <img width="250" alt="image"
src="https://github.com/user-attachments/assets/85717613-ede0-44a8-8524-c9af4b37c09d">
| <img width="250" alt="image"
src="https://github.com/user-attachments/assets/f4e23bc6-8cfb-4509-a2f5-45c4f642c197">
|
| `transform={[{rotate: '45deg'}]}` | <img width="250" alt="image"
src="https://github.com/user-attachments/assets/90131401-2c52-4e8a-81ab-6cd449625953">
| <img width="250" alt="image"
src="https://github.com/user-attachments/assets/bab46300-4794-4322-bd95-d6e7e7abd30e">
|
| `transform="rotate(45)"` | <img width="250" alt="image"
src="https://github.com/user-attachments/assets/6d308022-4844-451a-b767-1c3e94e7a295">
| <img width="250" alt="image"
src="https://github.com/user-attachments/assets/553bbad5-9e37-4a52-b4e0-fa0c7b6b558e">
|
| `transform={[{translateX: 100}, {translateY: 100}]}` | <img
width="250" alt="image"
src="https://github.com/user-attachments/assets/91508d75-2b0a-4be6-9280-2ace017d9271">
| <img width="250" alt="image"
src="https://github.com/user-attachments/assets/36fb5cad-1ccf-4c99-8ffd-70ea56ba589f">
|
| `transform="translate(100 100)"` | <img width="250" alt="image"
src="https://github.com/user-attachments/assets/28fa66f2-b2f2-4b86-bb41-47bd507d6018">
| <img width="250" alt="image"
src="https://github.com/user-attachments/assets/36fb5cad-1ccf-4c99-8ffd-70ea56ba589f">
|

## Test Plan

Test example app -> `Test2403`
2024-08-19 09:16:18 +02:00
Jakub Grzywacz
ca1c35caa9 feat: introduce hitSlop prop (#2407)
# Summary

Explain the **motivation** for making this change: here are some points
to help you:

* What issues does the pull request solve? Please tag them so that they
will get automatically closed once the PR is merged
* What is the feature? (if applicable)
* How did you implement the solution?
* What areas of the library does it impact?

## Test Plan

Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes UI.

### What's required for testing (prerequisites)?

### What are the steps to reproduce (after prerequisites)?

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| MacOS   |          |
| Android |          |
| Web     |          |
2024-08-19 09:11:07 +02:00
Jakub Grzywacz
7acbee41f3 fix: FeMerge on paper (#2384)
# Summary

Use empty string (`""`) instead of `undefined` for previous filter
result in `FeMergeNode`
2024-07-31 15:13:50 +02:00
Jakub Grzywacz
b8b022c31e feat: add FeMerge and FeMergeNode filters (#2369)
# Summary

As mentioned in #2362
Introduce new filters:
* `FeMerge`
* `FeMergeNode`

## Example usage

```tsx
<Svg width="200" height="200">
  <Filter id="mergeWithOffset" width="180" height="180">
    <FeOffset dx="50" dy="50" result="test" />
    <FeOffset dx="100" dy="100" in="SourceGraphic" />
    <FeMerge>
      <FeMergeNode in="SourceGraphic" />
      <FeMergeNode in="test" />
      <FeMergeNode />
    </FeMerge>
  </Filter>
  <Rect
    x="0"
    y="0"
    width="100"
    height="100"
    stroke="black"
    fill="red"
    filter="url(#mergeWithOffset)"
  />
</Svg>
```

<img width="207" alt="image"
src="https://github.com/user-attachments/assets/9cb3ded6-f939-4b2b-8ece-df54e64fe898">

## Test Plan

`Example` app -> `Filters` -> `FeMerge`

## 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)
2024-07-31 13:23:53 +02:00
Tomasz Żelawski
129e8ed8b5 feat: Make CMake less verbose (#2377)
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect -->

# Summary

Explain the **motivation** for making this change: here are some points
to help you:

* What issues does the pull request solve? Please tag them so that they
will get automatically closed once the PR is merged
* What is the feature? (if applicable)
* How did you implement the solution?
* What areas of the library does it impact?

## Test Plan

Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes UI.

### What's required for testing (prerequisites)?

### What are the steps to reproduce (after prerequisites)?

## Compatibility

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

## Checklist

<!-- Check completed item, when applicable, via: [X] -->

- [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)
- [x] I added a test for the API in the `__tests__` folder
2024-07-30 09:34:37 +02:00
Jakub Grzywacz
25099ff220 refactor: small changes to filters (#2368)
# Summary

This PR contains two small refactors of filters:
* extract common props on ViewManagers on Android
* remove unnecessary extract in `FeOffset` filter
2024-07-29 08:21:17 +02:00
Jakub Grzywacz
5807f2c1a6 feat: add FeOffset filter (#2361)
# 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)
2024-07-25 12:32:15 +02:00
Jakub Grzywacz
44254df9fb feat: add FeGaussianBlur filter (#2352)
# 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 |         |
2024-07-25 11:46:45 +02:00
Jakub Grzywacz
9a2cd3d855 fix: color shift in FeColorMatrix on android (#2365)
# Summary

While debugging #2364 I've noticed that color shift in `FeColorMatrix`
on Android is wrong.
On web, elements 5, 10, 15, 20 is a color shift represented by number
where 1 mean full color shift, while on Android it's 255 for full color
shift.

## Test

```tsx
<svg width="180" height="180" viewBox="0 0 180 180">
  <rect width="180" height="180" fill="red" filter="url(#filter)"/>
  <filter id="filter">
    <feColorMatrix type="matrix" values="0 0 0 0 1
                                         0 1 0 0 0
                                         0 0 1 0 0
                                         0 0 0 1 0"/>
  </filter>
</svg>
```
2024-07-24 16:27:06 +02:00
Maciej Stosio
567e90521a Feat: add scripts to sync archs (#2357)
Changes moved from:
https://github.com/software-mansion/react-native-screens/pull/2224

## Description

When changing native props on Fabric, codegen generates corresponding
interfaces and delegates. To make sure both implementations are
consistent, we implement those interfaces on Paper too. Currently, after
generating interfaces using codegen, developer needs to copy
corresponding files for paper manually. This task adds Gradle task, that
automates this.

## Changes
Current assumption: 
Two scripts: `check-archs-consistency` and `sync-archs`. The first one
generates codegen interfaces and compares them with what we have for
paper, the second generates and copies for paper to sync the archs.
- sync is run when staged on changes to `src/paper`
- check is run on CI when `src/paper` or
`android/src/paper/java/com/facebook/react/viewmanagers` changes

## Test code and steps to reproduce

Open `src/fabric/LineNativeComponent.ts` or/and
`src/fabric/NativeSvgRenderableModule.ts` and remove any proper form
interface. Now:
- when building paper, interface should be updated
- when committing, interface should be updated
- if committed and pushed, Test consistency between Paper & Fabric
should fail :)
Brining back the prop and repeating up should cause the interface back
and CI green.
Posting changes in other places should cause CI task to run. 

You can also run those commands yourself using `yarn
check-archs-consistency` and `yarn sync-archs`
2024-07-22 14:58:37 +02:00
Bohdan Artiukhov
2b6ced416b feat: format project and change in test example default component (#2350)
# Summary
Format the whole project.
2024-07-18 12:45:36 +02:00
Bohdan Artiukhov
b8ff336fc5 fix: remove using pattern matching in FilterView (#2354)
# Summary
Closes #2347
Fixed a problem with building an Android app, pattern matching threw an
error when we tried to build an Android app.

[Repository](https://github.com/bohdanprog/react-native-svg-error-pattern-matching)
to reproduce that error.
## Test Plan
We can easily check that build the app.

### What are the steps to reproduce (after prerequisites)?
build the app without that fix.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |         |
2024-07-18 10:52:02 +02:00
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
SergeyYurkevich
832522d1c1 feat: implement mask-type property (#2152)
# Summary

"mask-type: alpha" is not supported. 
resolve issue: #1790  

## Explanation

svg example:
```
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100" fill="none">
<g clip-path="url(#clip0_8_3)">
<rect width="100" height="100" fill="white"/>
<mask id="mask0_8_3" mask-type="alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="100" height="100">
<circle cx="50" cy="50" r="50" fill="#000000"/>
</mask>
<g mask="url(#mask0_8_3)">
<rect x="-26" y="-78" width="209" height="263" fill="#252E74"/>
</g>
</g>
<defs>
<clipPath id="clip0_8_3">
<rect width="100" height="100" fill="white"/>
</clipPath>
</defs>
</svg>
```

Current behavior: 

![image](https://github.com/software-mansion/react-native-svg/assets/17138397/2dca6f46-fe8f-48f3-80f9-799563911e8b)

Expected behavior:

![image](https://github.com/software-mansion/react-native-svg/assets/17138397/fb49cf0b-d677-491f-8215-9c9b1d69080f)

## Compatibility

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

## Checklist

<!-- Check completed item, when applicable, via: [X] -->

- [x] I have tested this on a device and a simulator
- [ ] I added documentation in `README.md`
- [x] I updated the typed files (typescript)
- [ ] I added a test for the API in the `__tests__` folder

---------

Co-authored-by: Sergey <s.yurkevich@logiclike.com>
Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
2024-07-05 15:11:48 +02:00
Bohdan Artiukhov
9faa387a98 Fix: image onLoad props (#2317)
# Summary
Change data structure returned from the Image onLoad event.
Add fix in new arch for returned sizes.

## Test Plan

Manually test in both architectures and platforms.

### What's required for testing (prerequisites)?

### What are the steps to reproduce (after prerequisites)?

## Compatibility

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

---------

Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
2024-07-02 09:33:25 +02:00
Bohdan Artiukhov
c0ee3e9ca0 add onLoad prop to Image component (#2293)
# Summary

Closes #1442

We want to add new props to the Image Component.

## Test Plan

Added the Test component. 
Manually test that in Android and IOS platforms on new and old
Architectures.

### What are the steps to reproduce (after prerequisites)?

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |         |
2024-06-27 16:10:28 +02:00
Jakub Grzywacz
7b5d4daaed fix: scaling when mask is set (#2299)
# Summary

This PR resolves an issue raised in #1451. 
Currently, when a mask is used, we render the element as a bitmap (or
platform equivalent), but the bitmap's size does not update accordingly
with transformations. With these changes, the problem is addressed as
follows:
* **Android**: We utilize the original canvas layers to render the mask
and element with the appropriate blending mode.
* **iOS**: We create an offscreen context with the size multiplied by
the screen scale and apply the original UIGraphics CTM (current
transformation matrix) to the offscreen context. This ensures that the
same transformations are applied as on the original context.

Additionally, there is a significant performance improvement on Android
as we are not creating three new Bitmaps and three new Canvases.

## Test Plan

There are many ways for testing these changes, but the required ones
are:
* `TestsExample` app -> `Test1451.tsx`
* `Example` app -> Mask section
* `FabricExample` app -> Mask section

## Compatibility

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

## Preview

<img width="337" alt="image"
src="https://github.com/software-mansion/react-native-svg/assets/39670088/93dbae85-edbd-452a-84b0-9a50107b1361">
<img width="337" alt="image"
src="https://github.com/software-mansion/react-native-svg/assets/39670088/07838dff-cb2d-4072-a2fc-5c16a76f6c33">
2024-06-26 09:25:54 +02:00
Bohdan Artiukhov
a36a676d43 fix: android PathParser crash app if pass some wrong d prop (#2308)
Closes #2086
# Summary

The application crashes if an error is thrown when something goes wrong
during path parse.

## Test Plan
You can easily check in that component `Test2086` how it works after the
fix.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |        |
2024-06-20 14:16:39 +02:00
Bohdan Artiukhov
474109ad71 fixed pars on Android platform prop strokeDasharray (#2294)
# Summary
Closes #2248.
Add the ability to parse `strokeDasharray` string value on the Android
platform

## Test Plan

Manually test both platforms.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |         |
2024-06-13 11:32:11 +02:00
Maciej Stosio
170339977d fix: error when building paper after fabric (#2281)
# Summary

We had similar config in react-native-screens. It caused problem when
building Paper arch app after Fabric. Those changes help, so I'm moving
them here as well.
2024-05-21 10:42:46 +02:00
Jakub Grzywacz
0db87030da fix: change android package name (#2275)
# Summary

Fixes android packageName by changing it in codegen configuration from
`com.horcrux.rnsvg` to `com.horcrux.svg`

## Tests

Tested with oldest supported `react-native@0.70.0` with an old
architecture and everything is working as expected.
2024-05-15 14:53:09 +02:00
Jakub Grzywacz
118a20c0fd fix: toDataUrl line breaks (#2272)
# Summary

This PR removes the flag to include custom line breaks on `toDataUrl`
method. Some software could not read base64 with additional line break
characters, so it could lead to corrupting the image (like in
react-native-share). Fixes #1986.

## Test Plan

`TestsExample` -> `Test1986`

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |         |
2024-05-15 12:01:33 +02:00
Jakub Grzywacz
38a8dbca39 fix: radialGradient r={0} (#2271)
# Summary

* Fixed crash on Android when `<RadialGradient r={0}>`.
* Fixed render issue on Android and iOS when radius is zero. According
to [MDN
Docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/r#radialgradient)
> A value of lower or equal to zero will cause the area to be painted as
a single color using the color and opacity of the last gradient
`<stop>`.

## Test Plan

Test is available in `TestsExample` as `Test2170`

## Compatibility

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


Fixes #2170
2024-05-15 12:00:52 +02:00
Fabrizio Cucci
19b2e42e1b fix: Fix static view config validation for RNSVGSvgViewAndroid (#2274)
# Summary

As per title, when running an app in bridgless mode the following redbox
appears:

> StaticViewConfigValidator: Invalid static view config for
'RNSVGSvgViewAndroid'.
> 
> 'validAttributes.borderBlockColor' is missing.
> 'validAttributes.borderBlockEndColor' is missing.
> 'validAttributes.borderBlockStartColor' is missing.
> 'validAttributes.borderEndEndRadius' is missing.
> 'validAttributes.borderEndStartRadius' is missing.
> 'validAttributes.borderStartEndRadius' is missing.
> 'validAttributes.borderStartStartRadius' is missing.

## Test Plan

Tested that the redbox is gone.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |    N/A     |
| Android |         |

## Checklist

<!-- Check completed item, when applicable, via: [X] -->

- [X] I have tested this on a device and a simulator
- [ ] I added documentation in `README.md`
- [ ] I updated the typed files (typescript)
- [ ] I added a test for the API in the `__tests__` folder

---------

Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
2024-05-15 11:13:01 +02:00
Jakub Grzywacz
ee634256ff fix: set default strokeWidth to 1 on android (#2269)
# Summary

According to [MDN
Docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width),
when `strokeWidth` is not provided, the default value should be set to
`1`.

On android, when we update the `strokeWidth` prop to `undefined` it was
mistakenly converted to `0` by `SVGLength`.

Fixes #2266 

## Test Plan

Test available in `TestsExample/Test2266` 

### What are the steps to reproduce (after prerequisites)?

* Run `TestsExample` app
* Replace `ColorTest` with `Test2266` in `App.js`
2024-05-09 15:27:24 +02:00
Tomasz Żelawski
4b51a41a22 Fix CMakeLists for Android (#2249)
Fix CMakeLists for Android typo
2024-03-26 14:54:35 +01:00
Wojciech Lewicki
138c23ba10 feat: add needed changes for RN 0.74 (#2231)
PR bringing support for RN 0.74 and bridgeless mode to the library.
2024-03-05 12:52:09 +01:00
Wojciech Lewicki
50c2289a2c feat: use dynamics instead of strings for props that can be either string or number (#2238)
# Summary

PR bringing proper support for react-native-reanimated in the library by using dynamics instead of strings for props that can be either string or number.
2024-03-05 11:36:17 +01:00