From 74445cc0fd1dfde70bef4abe98bcdf6272fae5de Mon Sep 17 00:00:00 2001 From: HeeCheolKim <35059687+heecheolman@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:25:08 +0900 Subject: [PATCH] fix: allow to array style prop (#2189) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Summary - Previously, styles in "Array" format were not being applied correctly. - Therefore, now ensure that styles in "Array" format are correctly applied using `StyleSheet.flatten.` **Before: The `opacity` attribute is not correctly applied in `gStyle`.** :x: ```tsx const gStyle = Object.assign({}, [{ opacity: 0.5 }]); /* { 0: {opacity: 0.5 }} */ ``` **After: Now, the `opacity` attribute is correctly applied in `gStyle`.** ✅ ```tsx const gStyle = StyleSheet.flatten([{ opacity: 0.5 }]); /* { opacity: 0.5 } */ ``` ```tsx const gStyle = StyleSheet.flatten([{ opacity: 0.5 }, { backgroundColor: 'red' }]); /* { opacity: 0.5, backgroundColor: 'red' } */ ``` ## Test Plan `0` key is not allow to `ViewStyle` ### What's required for testing (prerequisites)? ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ | ## Checklist - [x] I have tested this on a device and a simulator --------- Co-authored-by: bohdanprog --- src/elements/Svg.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elements/Svg.tsx b/src/elements/Svg.tsx index 2a468cbe..9283226b 100644 --- a/src/elements/Svg.tsx +++ b/src/elements/Svg.tsx @@ -177,7 +177,7 @@ export default class Svg extends Shape { props.onLayout = onLayout; } - const gStyle = Object.assign({}, style) as ViewStyle; + const gStyle = StyleSheet.flatten(style); // if transform prop is of RN style's kind, we want `SvgView` to handle it // since it can be done here. Otherwise, if transform is of `svg` kind, e.g. string, // we want G element to parse it since `Svg` does not include parsing of those custom transforms.