Skip to content
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

feat: Add tintColor prop to Image component #34534

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const BaseImage = (props: ImagePropsType, forwardedRef) => {
// $FlowFixMe[prop-missing]
const resizeMode = props.resizeMode || style.resizeMode || 'cover';
// $FlowFixMe[prop-missing]
const tintColor = style.tintColor;
const tintColor = props.tintColor || style.tintColor;

if (props.src != null) {
console.warn(
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Image/ImageProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {SyntheticEvent, LayoutEvent} from '../Types/CoreEventTypes';
import type {EdgeInsetsProp} from '../StyleSheet/EdgeInsetsPropType';
import type {ImageSource} from './ImageSource';
import type {ViewStyleProp, ImageStyleProp} from '../StyleSheet/StyleSheet';
import type {____ColorValue_Internal} from '../StyleSheet/StyleSheetTypes';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'll want to import the type like this:

import type {ColorValue} from './StyleSheet';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I've just updated it.

import type {ViewProps} from '../Components/View/ViewPropTypes';
import type {Node, Ref} from 'react';
import typeof Image from './Image';
Expand Down Expand Up @@ -170,6 +171,13 @@ export type ImageProps = {|
*/
testID?: ?string,

/**
* Changes the color of all the non-transparent pixels to the tintColor.
*
* See https://reactnative.dev/docs/image#tintcolor
*/
tintColor?: ____ColorValue_Internal,

src?: empty,
children?: empty,
|};
Expand Down
52 changes: 51 additions & 1 deletion packages/rn-tester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,27 +937,77 @@ exports.examples = [
},
{
title: 'Tint Color',
description: ('The `tintColor` style prop changes all the non-alpha ' +
description: ('The `tintColor` prop changes all the non-alpha ' +
'pixels to the tint color.': string),
render: function (): React.Node {
return (
<View>
<View style={styles.horizontal}>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#ff2d55'}]}
tintColor={'#5ac8fa'}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5}]}
tintColor={'#4cd964'}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5}]}
tintColor={'#ff2d55'}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5}]}
tintColor={'#8e8e93'}
/>
</View>
<Text style={styles.sectionText}>
It also works using the `tintColor` style prop
</Text>
<View style={styles.horizontal}>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#5ac8fa'}]}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#4cd964'}]}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#ff2d55'}]}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#8e8e93'}]}
/>
</View>
<Text style={styles.sectionText}>
The `tintColor` prop has precedence over the `tintColor` style prop
</Text>
<View style={styles.horizontal}>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#5ac8fa'}]}
tintColor={'#5ac8fa'}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#4cd964'}]}
tintColor={'#5ac8fa'}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#ff2d55'}]}
tintColor={'#5ac8fa'}
/>
<Image
source={require('../../assets/uie_thumb_normal.png')}
style={[styles.icon, {borderRadius: 5, tintColor: '#8e8e93'}]}
tintColor={'#5ac8fa'}
/>
</View>
<Text style={styles.sectionText}>
Expand Down