Skip to content

V7/ deprecate imageSource of Avatar #2471

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

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Changes from all commits
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
28 changes: 6 additions & 22 deletions src/components/avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import React, {PropsWithChildren, useEffect, useMemo, forwardRef} from 'react';
import React, {PropsWithChildren, useMemo, forwardRef} from 'react';
import {
StyleSheet,
ImageSourcePropType,
Expand All @@ -11,7 +11,6 @@ import {
TextStyle,
AccessibilityProps
} from 'react-native';
import {LogService} from '../../services';
import {Colors, BorderRadiuses} from '../../style';
import {extractAccessibilityProps} from '../../commons/modifiers';
import Badge, {BadgeProps} from '../badge';
Expand Down Expand Up @@ -74,10 +73,6 @@ export type AvatarProps = Pick<AccessibilityProps, 'accessibilityLabel'> &
* The image source (external or assets)
*/
source?: ImageSourcePropType;
/**
* @deprecated use 'source' prop
*/
imageSource?: ImageSourcePropType;
/**
* Image props object
*/
Expand Down Expand Up @@ -168,7 +163,6 @@ interface Statics {
const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.ForwardedRef<any>) => {
const themeProps = useThemeProps(props, 'Avatar');
const {
imageSource,
source,
size = 50,
labelColor = Colors.$textDefault,
Expand Down Expand Up @@ -197,16 +191,6 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
const {size: _badgeSize, borderWidth: badgeBorderWidth = 0} = badgeProps;
const badgeSize = _badgeSize || DEFAULT_BADGE_SIZE;

useEffect(() => {
if (imageSource) {
LogService.warn('uilib: imageSource prop is deprecated, use source instead.');
}
}, [imageSource]);

const _source = useMemo(() => {
return source || imageSource;
}, [source, imageSource]);

const _baseContainerStyle: StyleProp<ImageStyle> = useMemo(() => {
return {
width: size,
Expand Down Expand Up @@ -284,13 +268,13 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
}, [size, initialsStyle, labelColor]);

const textContainerStyle = useMemo(() => {
const hasImage = !_.isUndefined(_source);
const hasImage = !_.isUndefined(source);
return [
styles.initialsContainer,
{backgroundColor: _backgroundColor},
hasImage && styles.initialsContainerWithInset
];
}, [_source, _backgroundColor]);
}, [source, _backgroundColor]);

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

const renderImage = () => {
if (_source !== undefined) {
if (source !== undefined) {
// Looks like reanimated does not support SVG
const ImageContainer = animate && !isSvg(_source) ? AnimatedImage : Image;
const ImageContainer = animate && !isSvg(source) ? AnimatedImage : Image;
return (
<ImageContainer
style={_imageStyle}
source={_source}
source={source}
onLoadStart={onImageLoadStart}
onLoadEnd={onImageLoadEnd}
onError={onImageLoadError}
Expand Down