From 1b01381f28603d9dd3a65615d294bd7ccdf1df23 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Tue, 12 Apr 2022 13:47:21 +0200 Subject: [PATCH] feat: remove extractColor in favor of RN impl (#1726) PR removing extractColor.ts in favor of using the processColor implementation straight from react-native. It should handle all the cases from the previous implementation and the cases with PlatformColor and DynamicColorIOS. Normally we would just send the returned value to the native side, but in react-native-svg, e.g. fill prop can have more values than just color, e.g. currentColor. Because of it, we cannot use UIColor on iOS, NSColor on macOS and customType="Color" on Android as a prop type there and therefore we need to prepare the custom values on the JS side. It is done by passing the prop as an array with specific first element. In case of colors, it is 0. (hopefully I understood the code right). --- Example/ios/Podfile.lock | 6 +- TestsExample/App.js | 5 +- TestsExample/ios/Podfile.lock | 6 +- .../src/{SampleTest.tsx => ColorTest.tsx} | 21 +- TestsExample/src/Test1718.tsx | 18 + src/elements/Svg.tsx | 8 +- src/index.d.ts | 12 +- src/index.js.flow | 6 +- src/lib/extract/extractBrush.ts | 33 +- src/lib/extract/extractColor.ts | 446 ------------------ src/lib/extract/extractFill.ts | 4 +- src/lib/extract/extractGradient.ts | 4 +- src/lib/extract/types.ts | 12 +- 13 files changed, 63 insertions(+), 518 deletions(-) rename TestsExample/src/{SampleTest.tsx => ColorTest.tsx} (70%) create mode 100644 TestsExample/src/Test1718.tsx delete mode 100644 src/lib/extract/extractColor.ts diff --git a/Example/ios/Podfile.lock b/Example/ios/Podfile.lock index 7454e709..f18bf7b8 100644 --- a/Example/ios/Podfile.lock +++ b/Example/ios/Podfile.lock @@ -347,7 +347,7 @@ PODS: - React-jsi (= 0.68.0-rc.1) - React-logger (= 0.68.0-rc.1) - React-perflogger (= 0.68.0-rc.1) - - RNSVG (12.2.0): + - RNSVG (12.3.0): - React-Core - SocketRocket (0.6.0) - Yoga (1.14.0) @@ -501,7 +501,7 @@ SPEC CHECKSUMS: CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662 FBLazyVector: bcdeff523be9f87a135b7c6fde8736db94904716 - FBReactNativeSpec: 0c3f104f594b34d7b3a923cd12e03b0d4e12eaf5 + FBReactNativeSpec: c01fba40ea819e68030d0d9b9094a173b2a3d127 Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0 Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c @@ -540,7 +540,7 @@ SPEC CHECKSUMS: React-RCTVibration: 5cab6419b68d5750482b0fc34dbb27af550469cc React-runtimeexecutor: 10cda3a396b14a764a5f86088e7e3810b9c66cec ReactCommon: 73a01eb83f22c84a6b09dfb60f3463888ebd4975 - RNSVG: 4ecc2e8f38b6ebe7889909570c26f3abe8059767 + RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 Yoga: d29dba374c1a582b40cfb736647b5e1b5ed35dba YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/TestsExample/App.js b/TestsExample/App.js index c04945c0..a9b77ac2 100644 --- a/TestsExample/App.js +++ b/TestsExample/App.js @@ -1,7 +1,8 @@ /* eslint-disable no-unused-vars */ import React from 'react'; -import SampleTest from './src/SampleTest'; +import ColorTest from './src/ColorTest'; +import Test1718 from './src/Test1718'; export default function App() { - return ; + return ; } diff --git a/TestsExample/ios/Podfile.lock b/TestsExample/ios/Podfile.lock index 4f282bdf..94cc3bac 100644 --- a/TestsExample/ios/Podfile.lock +++ b/TestsExample/ios/Podfile.lock @@ -347,7 +347,7 @@ PODS: - React-jsi (= 0.68.0-rc.1) - React-logger (= 0.68.0-rc.1) - React-perflogger (= 0.68.0-rc.1) - - RNSVG (12.2.0): + - RNSVG (12.3.0): - React-Core - SocketRocket (0.6.0) - Yoga (1.14.0) @@ -501,7 +501,7 @@ SPEC CHECKSUMS: CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662 FBLazyVector: bcdeff523be9f87a135b7c6fde8736db94904716 - FBReactNativeSpec: 96fb2991e5748dcf1c627822cbf41253f1fffe31 + FBReactNativeSpec: 137186498f03934daf999cec565fbc3d291f294c Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0 Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c @@ -540,7 +540,7 @@ SPEC CHECKSUMS: React-RCTVibration: 5cab6419b68d5750482b0fc34dbb27af550469cc React-runtimeexecutor: 10cda3a396b14a764a5f86088e7e3810b9c66cec ReactCommon: 73a01eb83f22c84a6b09dfb60f3463888ebd4975 - RNSVG: 4ecc2e8f38b6ebe7889909570c26f3abe8059767 + RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 Yoga: d29dba374c1a582b40cfb736647b5e1b5ed35dba YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/TestsExample/src/SampleTest.tsx b/TestsExample/src/ColorTest.tsx similarity index 70% rename from TestsExample/src/SampleTest.tsx rename to TestsExample/src/ColorTest.tsx index 95db448c..d28792a0 100644 --- a/TestsExample/src/SampleTest.tsx +++ b/TestsExample/src/ColorTest.tsx @@ -1,23 +1,28 @@ import React from 'react'; -import { PlatformColor, Platform, Button } from 'react-native'; +import { PlatformColor, Platform, Button, DynamicColorIOS } from 'react-native'; import { Svg, Circle, Rect, Text, TSpan, - SvgUri } from 'react-native-svg'; const color = PlatformColor(Platform.select({ - ios: 'label', - android: '@android:color/primary_text_light', + ios: 'systemTealColor', + android: '@android:color/holo_blue_bright', default: 'black', })) +// const customContrastDynamicTextColor = DynamicColorIOS({ +// dark: 'hsla(360, 40%, 30%, 1.0)', +// light: '#ff00ff55', +// highContrastDark: 'black', +// highContrastLight: 'white', +// }); + export default () => { const [test, setTest] = React.useState(50); - const [uri, setUri] = React.useState('https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/not_existing.svg') return ( <> @@ -46,12 +51,6 @@ export default () => {