mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-31 13:52:58 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user