Commit Graph

320 Commits

Author SHA1 Message Date
Bartosz Stefańczyk
a089cc2efc feat: e2e snapshot tests (#2338)
<!-- 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

This PR adds E2E tests based on view screenshots done via
`react-native-view-shot`. It only works with devices that have their
[pixel ratio](https://reactnative.dev/docs/pixelratio) equal `3`. If you
want to use device with different pixel ratio, you need to adjust it in
`e2e/generateReferences.ts` viewport and regenerate reference images
(see below).

Steps to run tests:
- Run Metro server for example app via `yarn start` in example app's
directory
- Run `example` app on platform of your choice (currently only Android &
iOS are supported) via `yarn android` or `yarn ios` in example app's
directory
- Run `yarn e2e` in project's root directory to start Jest server
- Select `E2E` tab in example app
- Wait for tests to finish
- You can see test results, as well as diffs (actual rendered svg vs
reference image) in `e2e/diffs` directory

Steps to add new test cases:
- Put SVG of your choice to `e2e/cases` directory
- Run `yarn generateE2eRefrences`, this will open headless chrome
browser via `puppeteer` and snapshot all rendered SVGs to .png files and
later use them as reference in tests
- You should see new .png files in `e2e/references`
- When you run E2E tests again, it will use new test case(s) you've
added

## Test Plan


https://github.com/software-mansion/react-native-svg/assets/41289688/24ee5447-ce9a-43b6-9dde-76229d25a30a


https://github.com/software-mansion/react-native-svg/assets/41289688/71d1873f-8155-4494-80bd-e4c1fa72a065


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

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

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |    	     |
| Android |         |
| Web | 			 |
## 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

---------

Co-authored-by: bohdanprog <bohdan.artiukhov@swmansion.com>
Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
2024-08-23 13:29:38 +02:00
Jakub Grzywacz
ea99e5c875 Release 15.6.0 2024-08-21 15:16:16 +02:00
Jakub Grzywacz
4100c0897c chore: fix prettier (#2416)
# Summary

Fix pre-commit `format-js` prettier error caused by
https://github.com/software-mansion/react-native-svg/pull/2408
2024-08-20 12:07:36 +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
f12ec19b6c Release 15.5.0 2024-08-06 15:25:49 +02:00
Jakub Grzywacz
52466a2564 feat: introduce CSS filter API on FilterImage (#2359)
# Summary

Provide a **CSS**-like filter API in the `FilterImage` component. 
Unlike the SVG filter API, which can be complex and challenging even for
simple tasks, the CSS API is straightforward and allows users to quickly
achieve satisfactory results.

The full API can be viewed here
https://developer.mozilla.org/en-US/docs/Web/CSS/filter
_We support all `<filter-function>` listed in the docs while we do not
support functions from `<url>` (`url()` and `src()`)._

All shorthands are implemented according to the W3 standard described
here
https://www.w3.org/TR/filter-effects-1/#ShorthandEquivalents

This PR also changes the `filters` prop behavior as it adds `fe` in
front of `name` attribute to not introduce any abstract above that
specified in the docs.
```tsx
<FilterImage
  source={myImage}
  filters={[{ name: 'colorMatrix', type: 'saturate', values: 0.2 }])
/>
```
is now 
```tsx
<FilterImage
  source={myImage}
  filters={[{ name: 'feColorMatrix', type: 'saturate', values: 0.2 }])
/>
```

## Examples
Below are the simple examples of the usage

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

export default () => {
  return (
    <FilterImage
      style={styles.image}
      source={{
        uri: 'https://cdn.pixabay.com/photo/2024/05/26/00/40/lizard-8787888_1280.jpg',
      }}
    />
  );
};
const styles = StyleSheet.create({
  image: {
    width: 200,
    height: 200,
    filter: 'saturate(100) grayscale(100%)',
  },
});
```

or directly in the `style` prop

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

export default () => {
  return (
    <FilterImage
      style={{
        width: 200,
        height: 200,
        filter: 'saturate(100) grayscale(100%)',
      }}
      source={{
        uri: 'https://cdn.pixabay.com/photo/2024/05/26/00/40/lizard-8787888_1280.jpg',
      }}
    />
  );
};
```

## 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 10:19:47 +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
Jakub Grzywacz
5d7f21265a Release 15.4.0 2024-07-11 15:01:30 +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
Bartosz Stefańczyk
dd57e9e83b fix: fix format-js task to reflect changes made to folder structure (#2342)
<!-- 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
Fixes following error while commiting:
```
✖ yarn format-js:
[error] No files matching the pattern were found: "./Example/src/**/*.tsx".
error Command failed with exit code 2.
```


## Test Plan

Run `yarn format-js` or do a commit so hook will get ran.

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

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

## 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`
- [] I updated the typed files (typescript)
- [ ] I added a test for the API in the `__tests__` folder
2024-07-10 14:45:36 +02:00
Jakub Grzywacz
d6027ace60 Release 15.3.0 2024-05-16 15:09:14 +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
Wojciech Lewicki
a256f25de8 Release 15.2.0 2024-04-23 13:42:15 +02:00
Wojciech Lewicki
15f5b11f31 chore: bump package.json to 15.2.0-rc.0 2024-03-05 14:59:24 +01:00
Wojciech Lewicki
31772c0c0f Release 15.1.0 2024-03-05 11:38:43 +01:00
Wojciech Lewicki
e332c4ada9 Release 15.0.0 2024-02-26 15:32:58 +01:00
Wojciech Lewicki
2806bb2bee Release 14.1.0 2023-12-04 15:18:30 +01:00
Wojciech Lewicki
03ca039497 feat: add support for RN 73 (#2181)
PR bumping the library code to compile on new arch on RN 0.73.x and restoring the proper configuration of Image component on new arch on Android.

Also bumping the FabricExample to check if the code works correctly.
2023-12-01 11:58:49 +01:00
Wojciech Lewicki
1868f00f20 Release 14.0.0 2023-11-14 12:41:33 +01:00
Wojciech Lewicki
2b030dda12 feat: move css to different package for size reduction (#2168)
PR based on https://github.com/software-mansion/react-native-svg/pull/1452 extracting `css` related components to different package to reduce the size of the package.

***THIS IS A BREAKING CHANGE***. From now on, you should import 
```
  SvgCss,
  SvgCssUri,
  SvgWithCss,
  SvgWithCssUri,
  inlineStyles,
  LocalSvg,
  WithLocalSvg,
  loadLocalRawResource,
  ```
 from `react-native-svg/css` package instead.
2023-11-14 11:50:03 +01:00
Wojciech Lewicki
f9c7d8a807 Release 13.14.0 2023-09-20 17:29:47 +02:00
Wojciech Lewicki
849513946e Release 13.13.0 2023-08-24 15:34:12 +02:00
Wojciech Lewicki
fb28d7809c Release 13.12.0 2023-08-21 16:00:42 +02:00
Wojciech Lewicki
9176c4c95a Release 13.11.0 2023-08-07 18:49:17 +02:00
Wojciech Lewicki
416ccc8a86 fix: bump packages, eslint, tsconfig, prettier and resolve all conflicts (#2114)
PR bumping packages, eslint, tsconfig, prettier and resolving all conflicts connected to it.
2023-08-07 17:44:58 +02:00
Wojciech Lewicki
0e931577ac Release 13.10.0 2023-07-07 12:53:47 +02:00
Wojciech Lewicki
d31ffdb762 Release 13.9.0 2023-03-30 17:35:20 +02:00
Risto Keravuori
eaf79ea3ee Upgrade rn-builder-bob to enable tree-shaking in rn-web (#1993)
Upgrade rn-builder-bob to enable tree-shaking in rn-web
2023-03-21 14:49:28 +01:00
Wojciech Lewicki
2c59100e24 Release 13.8.0 2023-02-01 11:42:40 +01:00
Wojciech Lewicki
cb87e7510f feat: update FabricExample to 0.71.0-rc.6 (#1962)
PR bumping examples to RN 0.71. For now web Example seems not to load code properly.
2023-01-13 14:19:17 +01:00
Wojciech Lewicki
678940c506 Release 13.7.0 2023-01-09 16:58:43 +01:00
Marlene Cota
a118c879c7 feat(windows): add example app (#1937)
Added example app for Windows
2023-01-09 12:48:20 +01:00
Wojciech Lewicki
6182ca3501 Release 13.6.0 2022-11-15 16:11:20 +01:00
Wojciech Lewicki
1126079425 feat: use codegenNativeComponent to import native views (#1847)
Changed `requireNativeComponent` to `codegenNativeComponent` so that upcoming changes (Static View Configs, Bridgeless Mode and idk what more) in `react-native` are available in the library. Also, types and native components are now taken directly from `fabric` folder to make sure the values passed to the native components are the ones defined in props. It should work on all supported versions since `codegenNativeComponent` function exists from RN v. 0.61.0. Suggested by @RSNara and @cipolleschi

Reason for [`5394bbb` (#1847)](5394bbbced): 
- on `Paper`, `Animated` uses `setNativeProps` method when we set `useNativeDriver`  to `false`, and does not rerender the component. Therefore, new transform lands only in `SvgView` and is parsed in `RCTViewManager.m` .
- on `Fabric`, the same code makes the components rerender. Due to this, information about new transform is passed to the `SvgView` child: `G` , making it apply translations from the transform in its `updateProps` method.
- other than `Animated` use-case, on both archs, if we just passed `transform` prop to `Svg` component, it would end up in double transformations now as well. All of those changes are due to https://github.com/software-mansion/react-native-svg/pull/1895, which added proper parsing of RN style `transform` prop (array of transformations objects) therefore making `G` properly handle `transform` prop passed from `Svg`.

Reason for [`19bcb24` (#1847)](19bcb2464b): Same as https://github.com/software-mansion/react-native-screens/pull/1624
2022-11-03 15:47:29 +01:00
Wojciech Lewicki
b8d408f82f Release 13.5.0 2022-11-02 15:55:14 +01:00
Wojciech Lewicki
795bff5f37 Release 13.4.0 2022-10-10 15:37:52 +02:00
Wojciech Lewicki
f49728d783 Release 13.3.0 2022-10-05 19:28:56 +02:00
Wojciech Lewicki
7b7ca40262 Release 13.2.0 2022-09-15 14:34:42 +02:00
Wojciech Lewicki
ee6e5da195 feat: transfer specs to ts and remove unnecessary props (#1865)
PR transfering Fabric specs to TS, removing unnecessary @ReactProp adnotations, unifying inheritance hierarchy across platforms, adding custom types for color and image source props so they are parsed by react-native.
2022-09-14 12:01:35 +02:00
Wojciech Lewicki
67755288c0 Release 13.1.0 2022-08-29 17:39:47 +02:00
Wojciech Lewicki
0313f0cc07 Release 13.0.0 2022-08-17 16:42:35 +02:00
Wojciech Lewicki
0a26639532 chore: bump library and examples to rn 0.70-rc3 (#1837)
PR bumping library to RN 0.70-rc3, which might make it not compatible with earlier versions of RN on Fabric. It should come with the same change in other libraries.

In this PR, I had to remove macos code from Example since it breaks @react-native-community/cli resolution. Hopefully we can bring it back soon.
2022-08-17 14:24:50 +02:00
Wojciech Lewicki
98c14b4f45 chore: add CI for JS, iOS and Android formatting (#1782)
Added CI workflow and local pre-commit hook for formatting and linting the newly added JS, iOS and Android code.
2022-08-16 12:00:32 +02:00
Wojciech Lewicki
8f1bda4856 feat: add Fabric on iOS without ComponentViews (#1821)
Version of #1754 without usage of ComponentViews. It seems like a more proper way, but introduces the necessity of clearing whole state of each component on recycling for it not to be used when view is recycled.

Still known problems:

We stringify props of type NumberProp since codegen only accepts props of a single type. It is the fastest way of dealing with it, but maybe there could be a better way to handle it.
Image resolving should be probably handled the same as in RN core
SvgView needs to set opaque = NO so it is does not have black background (it comes from the fact that RCTViewComponentView overrides backgroundColor setter which in turn somehow messes with the view being opaque). All other svg components do it already so maybe it is not such an issue.
transform prop won't work when set natively since it is not parsed in Fabric
2022-08-11 14:08:11 +02:00
Wojciech Lewicki
f1fa606664 Release 12.4.4 2022-08-10 12:52:22 +02:00
Wojciech Lewicki
34ece786b3 Release 12.4.3 2022-07-26 17:56:13 +02:00
Wojciech Lewicki
0722eedf2f Release 12.4.2 2022-07-26 12:05:45 +02:00
Wojciech Lewicki
556690e9f1 fix: types from lib folder (#1813)
Added missing component props and made Svg* component props extend SvgProps. Also removed custom Color type which is now just ColorValue from react-native.
2022-07-26 12:02:48 +02:00
Wojciech Lewicki
de84df64ba Release 12.4.1 2022-07-25 17:29:29 +02:00
Wojciech Lewicki
286c02fac4 Refactor typescript code (#1806)
Co-authored-by: Eric Butler <eric@codebutler.com>
2022-07-22 17:41:30 +02:00