kfiroo / react-native-cached-image

CachedImage component for react-native
MIT License
938 stars 470 forks source link

styles applied twice #125

Open fcangialosi opened 5 years ago

fcangialosi commented 5 years ago

It seems that styles passed to the CachedImage component are applied to both the ImageBackground wrapper and the internal Image component.

For example, my styles included margins, so this threw off the positioning of all my image elements.

I'm not sure what the correct solution is (for positioning styles you probably want them applied to the ImgeBackground component, for other styles you may want them applied to the internal image), but it at least seems the current one breaks things.

Not applying any of the styles to the internal Image component solves the problem (for me), but I don't know if this will generalize to all cases. Here's the change I made in CachedImage.js:

index daf03c8..233bf05 100644
--- a/CachedImage.js
+++ b/CachedImage.js
@@ -52,7 +52,7 @@ class CachedImage extends React.Component {
     };

     static defaultProps = {
-            renderImage: props => (<ImageBackground imageStyle={props.style} ref={CACHED_IMAGE_REF} {...props} />),
+            renderImage: props => (<ImageBackground ref={CACHED_IMAGE_REF} {...props} />),
             activityIndicatorProps: {},
     };