Skip to content

Commit dbd5c3d

Browse files
Naturalclarfacebook-github-bot
authored andcommitted
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: #32099 Test Plan: - [ ] flow check passes - [ ] rn-tester app runs Reviewed By: charlesbdudley Differential Revision: D30597737 Pulled By: yungsters fbshipit-source-id: 9699ee2bb727a1a8f30d6ffe3a2845c8a134e89d
1 parent 67b62ad commit dbd5c3d

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

Libraries/Image/ImageBackground.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
'use strict';
1212

13-
const Image = require('./Image');
14-
const React = require('react');
15-
const StyleSheet = require('../StyleSheet/StyleSheet');
16-
const View = require('../Components/View/View');
13+
import Image from './Image';
14+
import * as React from 'react';
15+
import StyleSheet from '../StyleSheet/StyleSheet';
16+
import flattenStyle from '../StyleSheet/flattenStyle';
17+
import View from '../Components/View/View';
18+
import type {ImageBackgroundProps} from './ImageProps';
1719

1820
/**
1921
* Very simple drop-in replacement for <Image> which supports nesting views.
@@ -39,7 +41,7 @@ const View = require('../Components/View/View');
3941
* AppRegistry.registerComponent('DisplayAnImageBackground', () => DisplayAnImageBackground);
4042
* ```
4143
*/
42-
class ImageBackground extends React.Component<$FlowFixMeProps> {
44+
class ImageBackground extends React.Component<ImageBackgroundProps> {
4345
setNativeProps(props: Object) {
4446
// Work-around flow
4547
const viewRef = this._viewRef;
@@ -56,7 +58,7 @@ class ImageBackground extends React.Component<$FlowFixMeProps> {
5658

5759
render(): React.Node {
5860
const {children, style, imageStyle, imageRef, ...props} = this.props;
59-
61+
const flattenedStyle = flattenStyle(style);
6062
return (
6163
<View
6264
accessibilityIgnoresInvertColors={true}
@@ -74,8 +76,8 @@ class ImageBackground extends React.Component<$FlowFixMeProps> {
7476
// So, we have to proxy/reapply these styles explicitly for actual <Image> component.
7577
// This workaround should be removed after implementing proper support of
7678
// intrinsic content size of the <Image>.
77-
width: style?.width,
78-
height: style?.height,
79+
width: flattenedStyle?.width,
80+
height: flattenedStyle?.height,
7981
},
8082
imageStyle,
8183
]}

Libraries/Image/ImageProps.js

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type {EdgeInsetsProp} from '../StyleSheet/EdgeInsetsPropType';
1515
import type {ImageSource} from './ImageSource';
1616
import type {ViewStyleProp, ImageStyleProp} from '../StyleSheet/StyleSheet';
1717
import type {ViewProps} from '../Components/View/ViewPropTypes';
18+
import type {Node, Ref} from 'react';
19+
import typeof Image from './Image';
1820

1921
export type ImageLoadEvent = SyntheticEvent<
2022
$ReadOnly<{|
@@ -171,3 +173,29 @@ export type ImageProps = {|
171173
src?: empty,
172174
children?: empty,
173175
|};
176+
177+
export type ImageBackgroundProps = $ReadOnly<{|
178+
...ImageProps,
179+
children?: Node,
180+
181+
/**
182+
* Style applied to the outer View component
183+
*
184+
* See https://reactnative.dev/docs/imagebackground#style
185+
*/
186+
style?: ?ViewStyleProp,
187+
188+
/**
189+
* Style applied to the inner Image component
190+
*
191+
* See https://reactnative.dev/docs/imagebackground#imagestyle
192+
*/
193+
imageStyle?: ?ImageStyleProp,
194+
195+
/**
196+
* Allows to set a reference to the inner Image component
197+
*
198+
* See https://reactnative.dev/docs/imagebackground#imageref
199+
*/
200+
imageRef?: Ref<Image>,
201+
|}>;

0 commit comments

Comments
 (0)