mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7a6f0e44b2
Summary: This adds the `tintColor` prop to the Image component to replace the non-standard `style.tintColor` as requested on https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
213 lines
4.9 KiB
JavaScript
213 lines
4.9 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {SyntheticEvent, LayoutEvent} from '../Types/CoreEventTypes';
|
|
import type {EdgeInsetsProp} from '../StyleSheet/EdgeInsetsPropType';
|
|
import type {ImageSource} from './ImageSource';
|
|
import type {
|
|
ColorValue,
|
|
ViewStyleProp,
|
|
ImageStyleProp,
|
|
} from '../StyleSheet/StyleSheet';
|
|
import type {ViewProps} from '../Components/View/ViewPropTypes';
|
|
import type {Node, Ref} from 'react';
|
|
import typeof Image from './Image';
|
|
|
|
export type ImageLoadEvent = SyntheticEvent<
|
|
$ReadOnly<{|
|
|
source: $ReadOnly<{|
|
|
width: number,
|
|
height: number,
|
|
uri: string,
|
|
|}>,
|
|
|}>,
|
|
>;
|
|
|
|
type IOSImageProps = $ReadOnly<{|
|
|
/**
|
|
* A static image to display while loading the image source.
|
|
*
|
|
* See https://reactnative.dev/docs/image#defaultsource
|
|
*/
|
|
defaultSource?: ?ImageSource,
|
|
/**
|
|
* Invoked when a partial load of the image is complete.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onpartialload
|
|
*/
|
|
onPartialLoad?: ?() => void,
|
|
/**
|
|
* Invoked on download progress with `{nativeEvent: {loaded, total}}`.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onprogress
|
|
*/
|
|
onProgress?: ?(
|
|
event: SyntheticEvent<$ReadOnly<{|loaded: number, total: number|}>>,
|
|
) => void,
|
|
|}>;
|
|
|
|
type AndroidImageProps = $ReadOnly<{|
|
|
loadingIndicatorSource?: ?(number | $ReadOnly<{|uri: string|}>),
|
|
progressiveRenderingEnabled?: ?boolean,
|
|
fadeDuration?: ?number,
|
|
|}>;
|
|
|
|
export type ImageProps = {|
|
|
...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
|
|
...IOSImageProps,
|
|
...AndroidImageProps,
|
|
|
|
/**
|
|
* When true, indicates the image is an accessibility element.
|
|
*
|
|
* See https://reactnative.dev/docs/image#accessible
|
|
*/
|
|
accessible?: ?boolean,
|
|
|
|
/**
|
|
* Internal prop to set an "Analytics Tag" that can will be set on the Image
|
|
*/
|
|
internal_analyticTag?: ?string,
|
|
|
|
/**
|
|
* The text that's read by the screen reader when the user interacts with
|
|
* the image.
|
|
*
|
|
* See https://reactnative.dev/docs/image#accessibilitylabel
|
|
*/
|
|
accessibilityLabel?: ?Stringish,
|
|
|
|
/**
|
|
* blurRadius: the blur radius of the blur filter added to the image
|
|
*
|
|
* See https://reactnative.dev/docs/image#blurradius
|
|
*/
|
|
blurRadius?: ?number,
|
|
|
|
/**
|
|
* See https://reactnative.dev/docs/image#capinsets
|
|
*/
|
|
capInsets?: ?EdgeInsetsProp,
|
|
|
|
/**
|
|
* Invoked on load error with `{nativeEvent: {error}}`.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onerror
|
|
*/
|
|
onError?: ?(
|
|
event: SyntheticEvent<
|
|
$ReadOnly<{|
|
|
error: string,
|
|
|}>,
|
|
>,
|
|
) => void,
|
|
|
|
/**
|
|
* Invoked on mount and layout changes with
|
|
* `{nativeEvent: {layout: {x, y, width, height}}}`.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onlayout
|
|
*/
|
|
|
|
onLayout?: ?(event: LayoutEvent) => mixed,
|
|
|
|
/**
|
|
* Invoked when load completes successfully.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onload
|
|
*/
|
|
onLoad?: ?(event: ImageLoadEvent) => void,
|
|
|
|
/**
|
|
* Invoked when load either succeeds or fails.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onloadend
|
|
*/
|
|
onLoadEnd?: ?() => void,
|
|
|
|
/**
|
|
* Invoked on load start.
|
|
*
|
|
* See https://reactnative.dev/docs/image#onloadstart
|
|
*/
|
|
onLoadStart?: ?() => void,
|
|
|
|
/**
|
|
* See https://reactnative.dev/docs/image#resizemethod
|
|
*/
|
|
resizeMethod?: ?('auto' | 'resize' | 'scale'),
|
|
|
|
/**
|
|
* The image source (either a remote URL or a local file resource).
|
|
*
|
|
* See https://reactnative.dev/docs/image#source
|
|
*/
|
|
source?: ?ImageSource,
|
|
|
|
/**
|
|
* See https://reactnative.dev/docs/image#style
|
|
*/
|
|
style?: ?ImageStyleProp,
|
|
|
|
/**
|
|
* Determines how to resize the image when the frame doesn't match the raw
|
|
* image dimensions.
|
|
*
|
|
* See https://reactnative.dev/docs/image#resizemode
|
|
*/
|
|
resizeMode?: ?('cover' | 'contain' | 'stretch' | 'repeat' | 'center'),
|
|
|
|
/**
|
|
* A unique identifier for this element to be used in UI Automation
|
|
* testing scripts.
|
|
*
|
|
* See https://reactnative.dev/docs/image#testid
|
|
*/
|
|
testID?: ?string,
|
|
|
|
/**
|
|
* Changes the color of all the non-transparent pixels to the tintColor.
|
|
*
|
|
* See https://reactnative.dev/docs/image#tintcolor
|
|
*/
|
|
tintColor?: ColorValue,
|
|
|
|
src?: empty,
|
|
children?: empty,
|
|
|};
|
|
|
|
export type ImageBackgroundProps = $ReadOnly<{|
|
|
...ImageProps,
|
|
children?: Node,
|
|
|
|
/**
|
|
* Style applied to the outer View component
|
|
*
|
|
* See https://reactnative.dev/docs/imagebackground#style
|
|
*/
|
|
style?: ?ViewStyleProp,
|
|
|
|
/**
|
|
* Style applied to the inner Image component
|
|
*
|
|
* See https://reactnative.dev/docs/imagebackground#imagestyle
|
|
*/
|
|
imageStyle?: ?ImageStyleProp,
|
|
|
|
/**
|
|
* Allows to set a reference to the inner Image component
|
|
*
|
|
* See https://reactnative.dev/docs/imagebackground#imageref
|
|
*/
|
|
imageRef?: Ref<Image>,
|
|
|}>;
|