Repository: kiwicom/mobile
Pull request #669 (2018-05-29 08:37:25)

NetworkImage: make the props exact


Patch:
diff --git a/packages/shared/src/image/MissingImage.js b/packages/shared/src/image/MissingImage.js
index 1049abbf..3c7ae544 100644
--- a/packages/shared/src/image/MissingImage.js
+++ b/packages/shared/src/image/MissingImage.js
@@ -3,7 +3,7 @@
 import * as React from 'react';
 import { Image } from 'react-native';
 
-export default function missingImage(imageProps: Object) {
+export default function MissingImage(imageProps: Object) {
   return (
     <Image {...imageProps} source={require('./assets/placeholders/100.png')} />
   );
diff --git a/packages/shared/src/image/NetworkImage.js b/packages/shared/src/image/NetworkImage.js
index a197eb96..8ace34a6 100644
--- a/packages/shared/src/image/NetworkImage.js
+++ b/packages/shared/src/image/NetworkImage.js
@@ -8,14 +8,16 @@ import { ConfigContext } from '@kiwicom/mobile-config';
 import MissingImage from './MissingImage';
 import IconLoading from '../loaders/IconLoading';
 
-type Props = {
-  // not exact - accepts all additional props from 'Image' component
-  source: {
-    uri: ?string,
-  },
-  style?: StylePropType,
-  dataSaverEnabled?: boolean,
-};
+type Props = {|
+  +source: {|
+    +uri: ?string,
+  |},
+  +style?: StylePropType,
+  +dataSaverEnabled?: boolean,
+  +resizeMode?:
+    | 'cover' // scales the image uniformly - image will be equal or larger
+    | 'contain', // scales the image uniformly - image will be equal or smaller
+|};
 
 /**
  * This is wrapper around original React Native image. It adds loading
diff --git a/packages/shared/src/image/StretchedImage.js b/packages/shared/src/image/StretchedImage.js
index 2137c5df..4e6399ec 100644
--- a/packages/shared/src/image/StretchedImage.js
+++ b/packages/shared/src/image/StretchedImage.js
@@ -7,8 +7,8 @@ import type { StylePropType } from '../../types/Styles';
 import StyleSheet from '../PlatformStyleSheet';
 
 type Props = {|
-  source: string,
-  style?: StylePropType,
+  +source: string,
+  +style?: StylePropType,
 |};
 
 export default function StretchedImage(props: Props) {


Test patch:
diff --git a/packages/shared/src/image/__tests__/__snapshots__/NetworkImage.test.js.snap b/packages/shared/src/image/__tests__/__snapshots__/NetworkImage.test.js.snap
index 95589c6e..99206c41 100644
--- a/packages/shared/src/image/__tests__/__snapshots__/NetworkImage.test.js.snap
+++ b/packages/shared/src/image/__tests__/__snapshots__/NetworkImage.test.js.snap
@@ -48,7 +48,7 @@ exports[`passes props to the original Image component 1`] = `
 `;
 
 exports[`returns MissingImage component for invalid URI 1`] = `
-<missingImage
+<MissingImage
   source={
     Object {
       "uri": null,
@@ -58,7 +58,7 @@ exports[`returns MissingImage component for invalid URI 1`] = `
 `;
 
 exports[`returns MissingImage component for invalid URI 2`] = `
-<missingImage
+<MissingImage
   source={
     Object {
       "uri": undefined,
@@ -68,7 +68,7 @@ exports[`returns MissingImage component for invalid URI 2`] = `
 `;
 
 exports[`returns MissingImage component when data saver enabled 1`] = `
-<missingImage
+<MissingImage
   dataSaverEnabled={true}
   source={
     Object {