From 2b030dda125439742cef84dcb7cbc5464deb6ba6 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Tue, 14 Nov 2023 11:50:03 +0100 Subject: [PATCH] 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. --- .eslintrc.js | 4 ++ Example/metro.config.js | 1 - FabricExample/metro.config.js | 1 - TestsExample/metro.config.js | 1 - TestsExample/src/Test1813.tsx | 69 ++++++++++++++--------------------- USAGE.md | 4 +- __tests__/css.test.tsx | 3 +- css/package.json | 6 +++ package.json | 1 + src/ReactNativeSVG.ts | 61 ++++++++++++++++++++++--------- src/{ => css}/LocalSvg.tsx | 7 ++-- src/{ => css}/css.tsx | 4 +- src/css/index.tsx | 20 ++++++++++ src/deprecated.tsx | 37 +++++++++++++++++++ tsconfig.json | 4 ++ 15 files changed, 152 insertions(+), 71 deletions(-) create mode 100644 css/package.json rename src/{ => css}/LocalSvg.tsx (93%) rename src/{ => css}/css.tsx (99%) create mode 100644 src/css/index.tsx create mode 100644 src/deprecated.tsx diff --git a/.eslintrc.js b/.eslintrc.js index 8886877a..c7c32195 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,6 +12,10 @@ module.exports = { 'react-native/react-native': true, }, settings: { + 'import/core-modules': [ + 'react-native-svg', + 'react-native-svg/css', + ], 'import/resolver': { 'babel-module': { extensions: ['.js', '.jsx', '.ts', '.tsx'], diff --git a/Example/metro.config.js b/Example/metro.config.js index 7efd0fe1..9b8b551b 100644 --- a/Example/metro.config.js +++ b/Example/metro.config.js @@ -57,7 +57,6 @@ const config = { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, - inlineRequires: true, }, }), }, diff --git a/FabricExample/metro.config.js b/FabricExample/metro.config.js index 6bb48e13..74235f11 100644 --- a/FabricExample/metro.config.js +++ b/FabricExample/metro.config.js @@ -44,7 +44,6 @@ const config = { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, - inlineRequires: true, }, }), }, diff --git a/TestsExample/metro.config.js b/TestsExample/metro.config.js index 2b936d1c..8891b995 100644 --- a/TestsExample/metro.config.js +++ b/TestsExample/metro.config.js @@ -40,7 +40,6 @@ const config = { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, - inlineRequires: true, }, }), }, diff --git a/TestsExample/src/Test1813.tsx b/TestsExample/src/Test1813.tsx index 0b7907d9..b70e4474 100644 --- a/TestsExample/src/Test1813.tsx +++ b/TestsExample/src/Test1813.tsx @@ -1,9 +1,18 @@ import React from 'react'; -import { SvgFromUri, SvgFromXml, SvgUri, SvgXml, SvgCss, SvgCssUri, SvgWithCss, SvgWithCssUri, WithLocalSvg, LocalSvg } from 'react-native-svg'; +import {SvgFromUri, SvgFromXml, SvgUri, SvgXml} from 'react-native-svg'; +import { + SvgCss, + SvgCssUri, + SvgWithCss, + SvgWithCssUri, + WithLocalSvg, + LocalSvg, +} from 'react-native-svg/css'; const asset = require('../assets/ruby.svg'); -const normalUri = "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ruby.svg"; -const uriWithCss = "http://thenewcode.com/assets/svg/accessibility.svg"; +const normalUri = + 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ruby.svg'; +const uriWithCss = 'http://thenewcode.com/assets/svg/accessibility.svg'; const xml = ` { - const [uri, setUri] = React.useState('https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/not_existing.svg') + const [uri, setUri] = React.useState( + 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/not_existing.svg', + ); return ( <> @@ -49,54 +60,30 @@ export default () => { height="100" uri={uri} /> - console.log(error)} + console.log(error)} width="100" height="100" uri={normalUri} /> - - - - console.log(error)} + + + + console.log(error)} width="100" height="100" uri={uriWithCss} /> - - console.log(error)} + + console.log(error)} width="100" height="100" uri={uriWithCss} /> - - + + ); -} +}; diff --git a/USAGE.md b/USAGE.md index 074b18d6..fe244a27 100644 --- a/USAGE.md +++ b/USAGE.md @@ -91,7 +91,7 @@ If remote SVG file contains CSS in `