From dbd5c3d8e5e35685be89156194a96cead553a330 Mon Sep 17 00:00:00 2001 From: Jesse Katsumata Date: Wed, 22 Sep 2021 20:19:24 -0700 Subject: [PATCH] chore: add ImageBackgroundPropType (#32099) Summary: Added FlowType definition for ImageBackground component Props ## Changelog [General] [Changed] - Add ImageBackground component type definition [General] [Fixed] - ImageBackground now respects `imageStyle` width and height Pull Request resolved: https://github.com/facebook/react-native/pull/32099 Test Plan: - [ ] flow check passes - [ ] rn-tester app runs Reviewed By: charlesbdudley Differential Revision: D30597737 Pulled By: yungsters fbshipit-source-id: 9699ee2bb727a1a8f30d6ffe3a2845c8a134e89d --- Libraries/Image/ImageBackground.js | 18 ++++++++++-------- Libraries/Image/ImageProps.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Libraries/Image/ImageBackground.js b/Libraries/Image/ImageBackground.js index 84bb98551f07a0..5d0de1ca1ac28c 100644 --- a/Libraries/Image/ImageBackground.js +++ b/Libraries/Image/ImageBackground.js @@ -10,10 +10,12 @@ 'use strict'; -const Image = require('./Image'); -const React = require('react'); -const StyleSheet = require('../StyleSheet/StyleSheet'); -const View = require('../Components/View/View'); +import Image from './Image'; +import * as React from 'react'; +import StyleSheet from '../StyleSheet/StyleSheet'; +import flattenStyle from '../StyleSheet/flattenStyle'; +import View from '../Components/View/View'; +import type {ImageBackgroundProps} from './ImageProps'; /** * Very simple drop-in replacement for which supports nesting views. @@ -39,7 +41,7 @@ const View = require('../Components/View/View'); * AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground); * ``` */ -class ImageBackground extends React.Component<$FlowFixMeProps> { +class ImageBackground extends React.Component { setNativeProps(props: Object) { // Work-around flow const viewRef = this._viewRef; @@ -56,7 +58,7 @@ class ImageBackground extends React.Component<$FlowFixMeProps> { render(): React.Node { const {children, style, imageStyle, imageRef, ...props} = this.props; - + const flattenedStyle = flattenStyle(style); return ( { // So, we have to proxy/reapply these styles explicitly for actual component. // This workaround should be removed after implementing proper support of // intrinsic content size of the . - width: style?.width, - height: style?.height, + width: flattenedStyle?.width, + height: flattenedStyle?.height, }, imageStyle, ]} diff --git a/Libraries/Image/ImageProps.js b/Libraries/Image/ImageProps.js index c7bf077c1f3190..ed3349c2b247b5 100644 --- a/Libraries/Image/ImageProps.js +++ b/Libraries/Image/ImageProps.js @@ -15,6 +15,8 @@ import type {EdgeInsetsProp} from '../StyleSheet/EdgeInsetsPropType'; import type {ImageSource} from './ImageSource'; import type {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<{| @@ -171,3 +173,29 @@ export type ImageProps = {| 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, +|}>;