-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix: avatar defaultProps warning #2507
Merged
FaridSafi
merged 1 commit into
FaridSafi:master
from
gor3a:fix-avatar-defaultprops-warning
Aug 19, 2024
Merged
fix: avatar defaultProps warning #2507
FaridSafi
merged 1 commit into
FaridSafi:master
from
gor3a:fix-avatar-defaultprops-warning
Aug 19, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gor3a
force-pushed
the
fix-avatar-defaultprops-warning
branch
from
July 10, 2024 15:07
3176a30
to
e674c53
Compare
Warning: Avatar: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead closes FaridSafi#2498
gor3a
force-pushed
the
fix-avatar-defaultprops-warning
branch
from
July 10, 2024 15:08
e674c53
to
4d1ca25
Compare
Hope it will be merged as soon as possible. |
I would be great if this could be merged 👍 |
Until @FaridSafi merge this PR Create diff --git a/node_modules/react-native-gifted-chat/lib/Avatar.d.ts b/node_modules/react-native-gifted-chat/lib/Avatar.d.ts
index b23f94a..d7b4b8b 100644
--- a/node_modules/react-native-gifted-chat/lib/Avatar.d.ts
+++ b/node_modules/react-native-gifted-chat/lib/Avatar.d.ts
@@ -1,12 +1,12 @@
import PropTypes from 'prop-types';
-import { ReactNode } from 'react';
+import React, { ReactNode } from 'react';
import { ImageStyle, TextStyle, ViewStyle } from 'react-native';
-import { Omit, IMessage, User, LeftRightStyle } from './Models';
+import { IMessage, LeftRightStyle, User } from './Models';
export interface AvatarProps<TMessage extends IMessage> {
currentMessage?: TMessage;
previousMessage?: TMessage;
nextMessage?: TMessage;
- position: 'left' | 'right';
+ position: 'left' | 'right' | string;
renderAvatarOnTop?: boolean;
showAvatarForEveryMessage?: boolean;
imageStyle?: LeftRightStyle<ImageStyle>;
@@ -16,22 +16,24 @@ export interface AvatarProps<TMessage extends IMessage> {
onPressAvatar?(user: User): void;
onLongPressAvatar?(user: User): void;
}
-export declare function Avatar<TMessage extends IMessage = IMessage>(props: AvatarProps<TMessage>): JSX.Element | null;
+export declare function Avatar({ renderAvatarOnTop, showAvatarForEveryMessage, containerStyle, position, currentMessage, previousMessage, nextMessage, renderAvatar, imageStyle, onPressAvatar, onLongPressAvatar, }: {
+ renderAvatarOnTop?: boolean | undefined;
+ showAvatarForEveryMessage?: boolean | undefined;
+ containerStyle?: {
+ [key: string]: any;
+ } | undefined;
+ position?: string | undefined;
+ currentMessage?: IMessage | undefined;
+ previousMessage?: IMessage | undefined;
+ nextMessage?: IMessage | undefined;
+ renderAvatar?: ((props: Omit<AvatarProps<IMessage>, "renderAvatar">) => React.ReactNode) | undefined;
+ imageStyle?: {
+ [key: string]: any;
+ } | undefined;
+ onPressAvatar?: (({}: {}) => void) | undefined;
+ onLongPressAvatar?: (({}: {}) => void) | undefined;
+}): JSX.Element | null;
export declare namespace Avatar {
- var defaultProps: {
- renderAvatarOnTop: boolean;
- showAvatarForEveryMessage: boolean;
- position: string;
- currentMessage: {
- user: null;
- };
- previousMessage: {};
- nextMessage: {};
- containerStyle: {};
- imageStyle: {};
- onPressAvatar: () => void;
- onLongPressAvatar: () => void;
- };
var propTypes: {
renderAvatarOnTop: PropTypes.Requireable<boolean>;
showAvatarForEveryMessage: PropTypes.Requireable<boolean>;
diff --git a/node_modules/react-native-gifted-chat/lib/Avatar.js b/node_modules/react-native-gifted-chat/lib/Avatar.js
index 70ce1d7..974f232 100644
--- a/node_modules/react-native-gifted-chat/lib/Avatar.js
+++ b/node_modules/react-native-gifted-chat/lib/Avatar.js
@@ -33,63 +33,58 @@ const styles = {
},
}),
};
-export function Avatar(props) {
- const { renderAvatarOnTop, showAvatarForEveryMessage, containerStyle, position, currentMessage, renderAvatar, previousMessage, nextMessage, imageStyle, } = props;
+export function Avatar({ renderAvatarOnTop = false, showAvatarForEveryMessage = false, containerStyle = {}, position = 'left', currentMessage = {}, previousMessage = {}, nextMessage = {}, renderAvatar = (({}) => null), imageStyle = {}, onPressAvatar = ({}) => { }, onLongPressAvatar = ({}) => { }, }) {
const messageToCompare = renderAvatarOnTop ? previousMessage : nextMessage;
const computedStyle = renderAvatarOnTop ? 'onTop' : 'onBottom';
if (renderAvatar === null) {
return null;
}
if (!showAvatarForEveryMessage &&
- currentMessage &&
- messageToCompare &&
- isSameUser(currentMessage, messageToCompare) &&
- isSameDay(currentMessage, messageToCompare)) {
+ currentMessage &&
+ messageToCompare &&
+ isSameUser(currentMessage, messageToCompare) &&
+ isSameDay(currentMessage, messageToCompare)) {
return (<View style={[
- styles[position].container,
- containerStyle && containerStyle[position],
- ]}>
- <GiftedAvatar avatarStyle={[
+ styles[position].container,
+ containerStyle && containerStyle[position],
+ ]}>
+ <GiftedAvatar avatarStyle={[
styles[position].image,
imageStyle && imageStyle[position],
]}/>
- </View>);
+ </View>);
}
const renderAvatarComponent = () => {
- if (props.renderAvatar) {
- const { renderAvatar, ...avatarProps } = props;
- return props.renderAvatar(avatarProps);
+ if (renderAvatar) {
+ return renderAvatar({
+ renderAvatarOnTop,
+ showAvatarForEveryMessage,
+ containerStyle,
+ position,
+ currentMessage,
+ previousMessage,
+ nextMessage,
+ imageStyle,
+ onPressAvatar,
+ onLongPressAvatar,
+ });
}
- if (props.currentMessage) {
+ if (currentMessage) {
return (<GiftedAvatar avatarStyle={[
- styles[props.position].image,
- props.imageStyle && props.imageStyle[props.position],
- ]} user={props.currentMessage.user} onPress={() => { var _a; return (_a = props.onPressAvatar) === null || _a === void 0 ? void 0 : _a.call(props, props.currentMessage.user); }} onLongPress={() => { var _a; return (_a = props.onLongPressAvatar) === null || _a === void 0 ? void 0 : _a.call(props, props.currentMessage.user); }}/>);
+ styles[position].image,
+ imageStyle && imageStyle[position],
+ ]} user={currentMessage.user} onPress={() => onPressAvatar(currentMessage.user)} onLongPress={() => onLongPressAvatar(currentMessage.user)}/>);
}
return null;
};
return (<View style={[
- styles[position].container,
- styles[position][computedStyle],
- containerStyle && containerStyle[position],
- ]}>
- {renderAvatarComponent()}
+ styles[position].container,
+ styles[position][computedStyle],
+ containerStyle && containerStyle[position],
+ ]}>
+ {renderAvatarComponent()}
</View>);
}
-Avatar.defaultProps = {
- renderAvatarOnTop: false,
- showAvatarForEveryMessage: false,
- position: 'left',
- currentMessage: {
- user: null,
- },
- previousMessage: {},
- nextMessage: {},
- containerStyle: {},
- imageStyle: {},
- onPressAvatar: () => { },
- onLongPressAvatar: () => { },
-};
Avatar.propTypes = {
renderAvatarOnTop: PropTypes.bool,
showAvatarForEveryMessage: PropTypes.bool, |
@FaridSafi Could we get this PR in? |
@FaridSafi bump |
Hi everyone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Warning: Avatar: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead
closes #2498