Skip to content

Commit 7a6f0e4

Browse files
gabrieldonadelfacebook-github-bot
authored andcommitted
feat: Add tintColor prop to Image component (facebook#34534)
Summary: This adds the `tintColor` prop to the Image component to replace the non-standard `style.tintColor` as requested on facebook#34424, so that React Native for Web does not have to deopt styles for Image rendering. I didn't have to change anything on Android as `tintColor` was already being passed down to the native component as a prop. This PR also updates RNTester ImageExample in order to facilitate the manual QA. ## Changelog [General] [Added] - Add tintColor prop to Image component Pull Request resolved: facebook#34534 Test Plan: 1. Open the RNTester app and navigate to the Image page 2. Test the `tintColor` prop through the `Tint Color` section https://user-images.githubusercontent.com/11707729/187444761-ce5fd949-89f3-4d73-9717-31d035c6ee6b.mov Reviewed By: necolas Differential Revision: D39133292 Pulled By: jacdebug fbshipit-source-id: 314e0ed47ab65366153e730667a31554bc2b6aa7
1 parent 3d82f7e commit 7a6f0e4

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

Libraries/Image/Image.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const BaseImage = (props: ImagePropsType, forwardedRef) => {
129129
// $FlowFixMe[prop-missing]
130130
const resizeMode = props.resizeMode || style.resizeMode || 'cover';
131131
// $FlowFixMe[prop-missing]
132-
const tintColor = style.tintColor;
132+
const tintColor = props.tintColor || style.tintColor;
133133

134134
if (props.src != null) {
135135
console.warn(

Libraries/Image/ImageProps.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
import type {SyntheticEvent, LayoutEvent} from '../Types/CoreEventTypes';
1414
import type {EdgeInsetsProp} from '../StyleSheet/EdgeInsetsPropType';
1515
import type {ImageSource} from './ImageSource';
16-
import type {ViewStyleProp, ImageStyleProp} from '../StyleSheet/StyleSheet';
16+
import type {
17+
ColorValue,
18+
ViewStyleProp,
19+
ImageStyleProp,
20+
} from '../StyleSheet/StyleSheet';
1721
import type {ViewProps} from '../Components/View/ViewPropTypes';
1822
import type {Node, Ref} from 'react';
1923
import typeof Image from './Image';
@@ -170,6 +174,13 @@ export type ImageProps = {|
170174
*/
171175
testID?: ?string,
172176

177+
/**
178+
* Changes the color of all the non-transparent pixels to the tintColor.
179+
*
180+
* See https://reactnative.dev/docs/image#tintcolor
181+
*/
182+
tintColor?: ColorValue,
183+
173184
src?: empty,
174185
children?: empty,
175186
|};

packages/rn-tester/js/examples/Image/ImageExample.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,27 +937,77 @@ exports.examples = [
937937
},
938938
{
939939
title: 'Tint Color',
940-
description: ('The `tintColor` style prop changes all the non-alpha ' +
940+
description: ('The `tintColor` prop changes all the non-alpha ' +
941941
'pixels to the tint color.': string),
942942
render: function (): React.Node {
943943
return (
944944
<View>
945+
<View style={styles.horizontal}>
946+
<Image
947+
source={require('../../assets/uie_thumb_normal.png')}
948+
style={[styles.icon, {borderRadius: 5, tintColor: '#ff2d55'}]}
949+
tintColor={'#5ac8fa'}
950+
/>
951+
<Image
952+
source={require('../../assets/uie_thumb_normal.png')}
953+
style={[styles.icon, {borderRadius: 5}]}
954+
tintColor={'#4cd964'}
955+
/>
956+
<Image
957+
source={require('../../assets/uie_thumb_normal.png')}
958+
style={[styles.icon, {borderRadius: 5}]}
959+
tintColor={'#ff2d55'}
960+
/>
961+
<Image
962+
source={require('../../assets/uie_thumb_normal.png')}
963+
style={[styles.icon, {borderRadius: 5}]}
964+
tintColor={'#8e8e93'}
965+
/>
966+
</View>
967+
<Text style={styles.sectionText}>
968+
It also works using the `tintColor` style prop
969+
</Text>
970+
<View style={styles.horizontal}>
971+
<Image
972+
source={require('../../assets/uie_thumb_normal.png')}
973+
style={[styles.icon, {borderRadius: 5, tintColor: '#5ac8fa'}]}
974+
/>
975+
<Image
976+
source={require('../../assets/uie_thumb_normal.png')}
977+
style={[styles.icon, {borderRadius: 5, tintColor: '#4cd964'}]}
978+
/>
979+
<Image
980+
source={require('../../assets/uie_thumb_normal.png')}
981+
style={[styles.icon, {borderRadius: 5, tintColor: '#ff2d55'}]}
982+
/>
983+
<Image
984+
source={require('../../assets/uie_thumb_normal.png')}
985+
style={[styles.icon, {borderRadius: 5, tintColor: '#8e8e93'}]}
986+
/>
987+
</View>
988+
<Text style={styles.sectionText}>
989+
The `tintColor` prop has precedence over the `tintColor` style prop
990+
</Text>
945991
<View style={styles.horizontal}>
946992
<Image
947993
source={require('../../assets/uie_thumb_normal.png')}
948994
style={[styles.icon, {borderRadius: 5, tintColor: '#5ac8fa'}]}
995+
tintColor={'#5ac8fa'}
949996
/>
950997
<Image
951998
source={require('../../assets/uie_thumb_normal.png')}
952999
style={[styles.icon, {borderRadius: 5, tintColor: '#4cd964'}]}
1000+
tintColor={'#5ac8fa'}
9531001
/>
9541002
<Image
9551003
source={require('../../assets/uie_thumb_normal.png')}
9561004
style={[styles.icon, {borderRadius: 5, tintColor: '#ff2d55'}]}
1005+
tintColor={'#5ac8fa'}
9571006
/>
9581007
<Image
9591008
source={require('../../assets/uie_thumb_normal.png')}
9601009
style={[styles.icon, {borderRadius: 5, tintColor: '#8e8e93'}]}
1010+
tintColor={'#5ac8fa'}
9611011
/>
9621012
</View>
9631013
<Text style={styles.sectionText}>

0 commit comments

Comments
 (0)