Skip to content

Commit b5ecc66

Browse files
authored
deprecate imageSource of Avatar (#2471)
1 parent f0960d6 commit b5ecc66

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

src/components/avatar/index.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash';
2-
import React, {PropsWithChildren, useEffect, useMemo, forwardRef} from 'react';
2+
import React, {PropsWithChildren, useMemo, forwardRef} from 'react';
33
import {
44
StyleSheet,
55
ImageSourcePropType,
@@ -11,7 +11,6 @@ import {
1111
TextStyle,
1212
AccessibilityProps
1313
} from 'react-native';
14-
import {LogService} from '../../services';
1514
import {Colors, BorderRadiuses} from '../../style';
1615
import {extractAccessibilityProps} from '../../commons/modifiers';
1716
import Badge, {BadgeProps} from '../badge';
@@ -74,10 +73,6 @@ export type AvatarProps = Pick<AccessibilityProps, 'accessibilityLabel'> &
7473
* The image source (external or assets)
7574
*/
7675
source?: ImageSourcePropType;
77-
/**
78-
* @deprecated use 'source' prop
79-
*/
80-
imageSource?: ImageSourcePropType;
8176
/**
8277
* Image props object
8378
*/
@@ -168,7 +163,6 @@ interface Statics {
168163
const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.ForwardedRef<any>) => {
169164
const themeProps = useThemeProps(props, 'Avatar');
170165
const {
171-
imageSource,
172166
source,
173167
size = 50,
174168
labelColor = Colors.$textDefault,
@@ -197,16 +191,6 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
197191
const {size: _badgeSize, borderWidth: badgeBorderWidth = 0} = badgeProps;
198192
const badgeSize = _badgeSize || DEFAULT_BADGE_SIZE;
199193

200-
useEffect(() => {
201-
if (imageSource) {
202-
LogService.warn('uilib: imageSource prop is deprecated, use source instead.');
203-
}
204-
}, [imageSource]);
205-
206-
const _source = useMemo(() => {
207-
return source || imageSource;
208-
}, [source, imageSource]);
209-
210194
const _baseContainerStyle: StyleProp<ImageStyle> = useMemo(() => {
211195
return {
212196
width: size,
@@ -284,13 +268,13 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
284268
}, [size, initialsStyle, labelColor]);
285269

286270
const textContainerStyle = useMemo(() => {
287-
const hasImage = !_.isUndefined(_source);
271+
const hasImage = !_.isUndefined(source);
288272
return [
289273
styles.initialsContainer,
290274
{backgroundColor: _backgroundColor},
291275
hasImage && styles.initialsContainerWithInset
292276
];
293-
}, [_source, _backgroundColor]);
277+
}, [source, _backgroundColor]);
294278

295279
const accessibilityProps = useMemo(() => {
296280
return extractAccessibilityProps(props);
@@ -301,13 +285,13 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
301285
}, [_baseContainerStyle, imageStyle]);
302286

303287
const renderImage = () => {
304-
if (_source !== undefined) {
288+
if (source !== undefined) {
305289
// Looks like reanimated does not support SVG
306-
const ImageContainer = animate && !isSvg(_source) ? AnimatedImage : Image;
290+
const ImageContainer = animate && !isSvg(source) ? AnimatedImage : Image;
307291
return (
308292
<ImageContainer
309293
style={_imageStyle}
310-
source={_source}
294+
source={source}
311295
onLoadStart={onImageLoadStart}
312296
onLoadEnd={onImageLoadEnd}
313297
onError={onImageLoadError}

0 commit comments

Comments
 (0)