Skip to content

Image - pass width and height to image style #2384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 9, 2023
58 changes: 40 additions & 18 deletions demo/src/screens/__tests__/__snapshots__/AvatarScreen.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 50,
}
}
height={50}
onError={[Function]}
source={
Object {
Expand All @@ -830,6 +829,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 50,
"width": 50,
},
undefined,
undefined,
undefined,
Expand All @@ -856,7 +859,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={50}
/>
<View
accessibilityLabel="badge"
Expand Down Expand Up @@ -1049,7 +1051,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 40,
}
}
height={40}
onError={[Function]}
source={
Object {
Expand All @@ -1060,6 +1061,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 40,
"width": 40,
},
undefined,
undefined,
undefined,
Expand All @@ -1086,7 +1091,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={40}
/>
<View
accessibilityLabel="badge"
Expand Down Expand Up @@ -1290,7 +1294,6 @@ exports[`AvatarScreen renders screen 1`] = `
accessibilityRole="image"
accessible={false}
assetGroup="icons"
height={60}
onError={[Function]}
onLoad={[Function]}
source={
Expand All @@ -1302,6 +1305,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 60,
"width": 60,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -1333,7 +1340,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={60}
/>
</View>
</View>
Expand Down Expand Up @@ -1460,7 +1466,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 70,
}
}
height={70}
onError={[Function]}
source={
Object {
Expand All @@ -1471,6 +1476,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 70,
"width": 70,
},
undefined,
undefined,
undefined,
Expand All @@ -1497,7 +1506,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={70}
/>
<View
accessibilityLabel="badge"
Expand Down Expand Up @@ -1690,7 +1698,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 60,
}
}
height={60}
onError={[Function]}
source={
Object {
Expand All @@ -1701,6 +1708,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 60,
"width": 60,
},
undefined,
undefined,
undefined,
Expand All @@ -1727,7 +1738,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={60}
/>
<View
accessibilityLabel="badge"
Expand Down Expand Up @@ -1823,6 +1833,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
null,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -1962,7 +1976,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 48,
}
}
height={48}
onError={[Function]}
source={
Object {
Expand All @@ -1973,6 +1986,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 48,
"width": 48,
},
undefined,
undefined,
undefined,
Expand All @@ -1999,7 +2016,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={48}
/>
</View>
</View>
Expand Down Expand Up @@ -2162,7 +2178,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 50,
}
}
height={50}
onError={[Function]}
onLoadEnd={[Function]}
onLoadStart={[Function]}
Expand All @@ -2175,6 +2190,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 50,
"width": 50,
},
undefined,
undefined,
undefined,
Expand All @@ -2201,7 +2220,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={50}
/>
</View>
</View>
Expand Down Expand Up @@ -2364,7 +2382,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 50,
}
}
height={50}
onError={[Function]}
onLoadEnd={[Function]}
onLoadStart={[Function]}
Expand All @@ -2377,6 +2394,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 50,
"width": 50,
},
undefined,
undefined,
undefined,
Expand All @@ -2403,7 +2424,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={50}
/>
</View>
</View>
Expand Down Expand Up @@ -2529,7 +2549,6 @@ exports[`AvatarScreen renders screen 1`] = `
"width": 50,
}
}
height={50}
onError={[Function]}
source={
Object {
Expand All @@ -2540,6 +2559,10 @@ exports[`AvatarScreen renders screen 1`] = `
Array [
undefined,
undefined,
Object {
"height": 50,
"width": 50,
},
undefined,
undefined,
undefined,
Expand All @@ -2566,7 +2589,6 @@ exports[`AvatarScreen renders screen 1`] = `
]
}
testID="undefined.image"
width={50}
/>
</View>
</View>
Expand Down
4 changes: 3 additions & 1 deletion demo/src/screens/componentScreens/ImageScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class ImageScreen extends Component<{}, State> {
cover={cover}
overlayType={overlayType !== 'none' ? overlayType : undefined}
overlayIntensity={overlayIntensity}
style={!cover && {width: DEFAULT_SIZE, height: DEFAULT_SIZE}}
// style={!cover && {width: DEFAULT_SIZE, height: DEFAULT_SIZE}}
width={!cover ? DEFAULT_SIZE : undefined}
height={!cover ? DEFAULT_SIZE : undefined}
Comment on lines +124 to +126
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I remove the 'style' prop

customOverlayContent={this.renderOverlayContent()}
{...{[`margin-${margin}`]: true}}
/>
Expand Down
32 changes: 32 additions & 0 deletions src/components/button/__tests__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@ exports[`Button container size should have no padding of button is an icon butto
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -1814,6 +1818,10 @@ exports[`Button icon should apply color on icon 1`] = `
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -1871,6 +1879,10 @@ exports[`Button icon should apply color on icon 2`] = `
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -1928,6 +1940,10 @@ exports[`Button icon should include custom iconStyle provided as a prop 1`] = `
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -1990,6 +2006,10 @@ exports[`Button icon should return icon style according to different variations
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -2047,6 +2067,10 @@ exports[`Button icon should return icon style according to different variations
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -2109,6 +2133,10 @@ exports[`Button icon should return icon style according to different variations
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -3111,6 +3139,10 @@ exports[`Button labelColor should return undefined color if this is an icon butt
Array [
undefined,
undefined,
Object {
"height": undefined,
"width": undefined,
},
undefined,
undefined,
undefined,
Expand Down
3 changes: 3 additions & 0 deletions src/components/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class Image extends PureComponent<Props, State> {
const {
tintColor,
style,
width,
height,
supportRTL,
cover,
aspectRatio,
Expand All @@ -228,6 +230,7 @@ class Image extends PureComponent<Props, State> {
style={[
tintColor && {tintColor},
shouldFlipRTL && styles.rtlFlipped,
{width, height},
cover && styles.coverImage,
this.isGif() && styles.gifImage,
aspectRatio && {aspectRatio},
Expand Down