fix: allow to array style prop (#2189)

# 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`.** 
```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

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

- [x] I have tested this on a device and a simulator

---------

Co-authored-by: bohdanprog <bohdan.artiukhov@swmansion.com>
This commit is contained in:
HeeCheolKim
2024-07-18 18:25:08 +09:00
committed by GitHub
parent b8ff336fc5
commit 74445cc0fd
+1 -1
View File
@@ -177,7 +177,7 @@ export default class Svg extends Shape<SvgProps> {
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.