Skip to content

Commit

Permalink
feat!: deprecated item removal in ChannelMessageList
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Jun 13, 2023
1 parent 48fabfe commit 3a68a33
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 61 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG_DRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@
- `GROUP_CHANNEL_MEMBERS.USER_BAR_ME_POSTFIX` is replaced to `LABELS.USER_BAR_ME_POSTFIX`
- `GROUP_CHANNEL_MEMBERS.USER_BAR_OPERATOR` is replaced to `LABELS.USER_BAR_OPERATOR`

### @sendbird/uikit-react-native

- `ChannelMessageList` (`GroupChannelProps`, `OpenChannelProps`)
- `onPressImageMessage` prop is replaced to `onPressMediaMessage`
- `onLeaveScrollBottom` prop is replaced to `onScrolledAwayFromBottom`
- `onPressAvatar` prop is replaced to `onShowUserProfile`

### @sendbird/uikit-chat-hooks

- `useGroupChannelMessages`, `useOpenChannelMessages`
- `nextMessages` and `newMessagesFromMembers` is replaced to `newMessages`
- `nextMessages` and `newMessagesFromMembers` property is replaced to `newMessages`

## Migrations
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
useFreshCallback,
} from '@sendbird/uikit-utils';

import { DEPRECATION_WARNING } from '../../constants';
import type { UserProfileContextType } from '../../contexts/UserProfileCtx';
import { useLocalization, usePlatformService, useSendbirdChat, useUserProfile } from '../../hooks/useContext';
import SBUUtils from '../../libs/SBUUtils';
Expand Down Expand Up @@ -71,8 +70,6 @@ export type ChannelMessageListProps<T extends SendbirdGroupChannel | SendbirdOpe
channel: T;
currentUserId?: ChannelMessageListProps<T>['currentUserId'];
enableMessageGrouping: ChannelMessageListProps<T>['enableMessageGrouping'];
/** @deprecated Please use `onShowUserProfile` **/
onPressAvatar?: UserProfileContextType['show'];
}) => React.ReactElement | null;
renderNewMessagesButton: null | CommonComponent<{
visible: boolean;
Expand All @@ -84,9 +81,6 @@ export type ChannelMessageListProps<T extends SendbirdGroupChannel | SendbirdOpe
onPress: () => void;
}>;
flatListProps?: Omit<FlatListProps<SendbirdMessage>, 'data' | 'renderItem'>;

/** @deprecated Please use `onPressMediaMessage` instead **/
onPressImageMessage?: (message: SendbirdFileMessage, uri: string) => void;
} & {
ref?: Ref<FlatList<SendbirdMessage>> | undefined;
};
Expand Down Expand Up @@ -114,7 +108,6 @@ const ChannelMessageList = <T extends SendbirdGroupChannel | SendbirdOpenChannel
flatListProps,
onPressNewMessagesButton,
onPressScrollToBottomButton,
onPressImageMessage,
}: ChannelMessageListProps<T>,
ref: React.ForwardedRef<FlatList<SendbirdMessage>>,
) => {
Expand All @@ -128,7 +121,6 @@ const ChannelMessageList = <T extends SendbirdGroupChannel | SendbirdOpenChannel
onEditMessage,
onDeleteMessage,
onResendFailedMessage,
onPressImageMessage,
onPressMediaMessage,
});

Expand Down Expand Up @@ -197,17 +189,10 @@ const useGetMessagePressActions = <T extends SendbirdGroupChannel | SendbirdOpen
onResendFailedMessage,
onEditMessage,
onDeleteMessage,
onPressImageMessage,
onPressMediaMessage,
}: Pick<
ChannelMessageListProps<T>,
| 'channel'
| 'currentUserId'
| 'onEditMessage'
| 'onDeleteMessage'
| 'onResendFailedMessage'
| 'onPressImageMessage'
| 'onPressMediaMessage'
'channel' | 'currentUserId' | 'onEditMessage' | 'onDeleteMessage' | 'onResendFailedMessage' | 'onPressMediaMessage'
>) => {
const { colors } = useUIKitTheme();
const { STRINGS } = useLocalization();
Expand Down Expand Up @@ -329,10 +314,6 @@ const useGetMessagePressActions = <T extends SendbirdGroupChannel | SendbirdOpen
case 'video':
case 'audio': {
response.onPress = () => {
if (onPressImageMessage && fileType === 'image') {
Logger.warn(DEPRECATION_WARNING.CHANNEL.ON_PRESS_IMAGE_MESSAGE);
onPressImageMessage(msg, getAvailableUriFromFileMessage(msg));
}
onPressMediaMessage?.(msg, () => onDeleteMessage(msg), getAvailableUriFromFileMessage(msg));
};
break;
Expand Down
7 changes: 1 addition & 6 deletions packages/uikit-react-native/src/components/ChatFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ type Props = Omit<FlatListProps<SendbirdMessage>, 'onEndReached'> & {
onBottomReached: () => void;
onTopReached: () => void;
onScrolledAwayFromBottom: (value: boolean) => void;

/** @deprecated Please use `onScrolledAwayFromBottom` **/
onLeaveScrollBottom?: (value: boolean) => void;
};
// FIXME: Inverted FlatList performance issue on Android {@link https://github.com/facebook/react-native/issues/30034}
const ChatFlatList = forwardRef<RNFlatList<SendbirdMessage>, Props>(function CustomFlatList(
{ onTopReached, onBottomReached, onScrolledAwayFromBottom, onLeaveScrollBottom, onScroll, ...props },
{ onTopReached, onBottomReached, onScrolledAwayFromBottom, onScroll, ...props },
ref,
) {
const { select } = useUIKitTheme();
Expand All @@ -35,10 +32,8 @@ const ChatFlatList = forwardRef<RNFlatList<SendbirdMessage>, Props>(function Cus

if (BOTTOM_DETECT_THRESHOLD < prevOffsetY && currOffsetY <= BOTTOM_DETECT_THRESHOLD) {
onScrolledAwayFromBottom(false);
onLeaveScrollBottom?.(false);
} else if (BOTTOM_DETECT_THRESHOLD < currOffsetY && prevOffsetY <= BOTTOM_DETECT_THRESHOLD) {
onScrolledAwayFromBottom(true);
onLeaveScrollBottom?.(true);
}

contentOffsetY.current = contentOffset.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import type { GroupChannelMessageProps, RegexTextPattern } from '@sendbird/uikit-react-native-foundation';
import { Box, GroupChannelMessage, Text, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
import {
Logger,
SendbirdAdminMessage,
SendbirdFileMessage,
SendbirdMessage,
Expand All @@ -23,14 +22,12 @@ import GroupChannelMessageDateSeparator from './GroupChannelMessageDateSeparator
import GroupChannelMessageFocusAnimation from './GroupChannelMessageFocusAnimation';
import GroupChannelMessageOutgoingStatus from './GroupChannelMessageOutgoingStatus';

let WARN_onPressAvatar = false;
const GroupChannelMessageRenderer: GroupChannelProps['Fragment']['renderMessage'] = ({
channel,
message,
onPress,
onLongPress,
onShowUserProfile,
onPressAvatar,
enableMessageGrouping,
focused,
prevMessage,
Expand All @@ -47,11 +44,6 @@ const GroupChannelMessageRenderer: GroupChannelProps['Fragment']['renderMessage'
nextMessage,
);

if (__DEV__ && !WARN_onPressAvatar && onPressAvatar) {
WARN_onPressAvatar = true;
Logger.warn('`onPressAvatar` is deprecated, please use `onShowUserProfile`');
}

const reactionChildren = useIIFE(() => {
if (shouldRenderReaction(channel, features.reactionEnabled) && message.reactions && message.reactions.length > 0) {
return <ReactionAddons.Message channel={channel} message={message} />;
Expand All @@ -66,22 +58,10 @@ const GroupChannelMessageRenderer: GroupChannelProps['Fragment']['renderMessage'
onLongPress,
onPressURL: () => message.ogMetaData?.url && SBUUtils.openURL(message.ogMetaData?.url),
onPressAvatar: () => {
if ('sender' in message) {
if (onPressAvatar) {
onPressAvatar(message.sender);
} else if (onShowUserProfile) {
onShowUserProfile(message.sender);
}
}
if ('sender' in message) onShowUserProfile?.(message.sender);
},
onPressMentionedUser: () => {
if ('sender' in message) {
if (onPressAvatar) {
onPressAvatar(message.sender);
} else if (onShowUserProfile) {
onShowUserProfile(message.sender);
}
}
if ('sender' in message) onShowUserProfile?.(message.sender);
},
groupedWithPrev: groupWithPrev,
groupedWithNext: groupWithNext,
Expand Down
5 changes: 0 additions & 5 deletions packages/uikit-react-native/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
export const DEFAULT_LONG_PRESS_DELAY = 350;
export const MESSAGE_SEARCH_SAFE_SCROLL_DELAY = 500;
export const MESSAGE_FOCUS_ANIMATION_DELAY = 250;
export const DEPRECATION_WARNING = {
CHANNEL: {
ON_PRESS_IMAGE_MESSAGE: '`onPressImageMessage` is deprecated, please use `onPressMediaMessage` instead',
},
} as const;

export const UNKNOWN_USER_ID = '##__USER_ID_IS_NOT_PROVIDED__##';
4 changes: 0 additions & 4 deletions packages/uikit-react-native/src/domain/groupChannel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export interface GroupChannelProps {
queryCreator?: UseGroupChannelMessagesOptions['queryCreator'];

searchItem?: GroupChannelProps['MessageList']['searchItem'];

/** @deprecated Please use `onPressMediaMessage` instead **/
onPressImageMessage?: GroupChannelProps['MessageList']['onPressImageMessage'];
};
Header: {
shouldHideRight: () => boolean;
Expand All @@ -73,7 +70,6 @@ export interface GroupChannelProps {
| 'renderNewMessagesButton'
| 'renderScrollToBottomButton'
| 'flatListProps'
| 'onPressImageMessage'
| 'hasNext'
| 'searchItem'
> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export type OpenChannelProps = {
| 'renderNewMessagesButton'
| 'renderScrollToBottomButton'
| 'flatListProps'
| 'onPressImageMessage'
| 'hasNext'
>;
Input: Pick<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
collectionCreator,
sortComparator = messageComparator,
flatListProps,
onPressImageMessage,
}) => {
const { sdk, currentUser } = useSendbirdChat();

Expand Down Expand Up @@ -219,7 +218,6 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
onDeleteMessage={deleteMessage}
onPressMediaMessage={onPressMediaMessage}
flatListProps={memoizedFlatListProps}
onPressImageMessage={onPressImageMessage}
/>
<GroupChannelModule.Input
SuggestedMentionList={GroupChannelModule.SuggestedMentionList}
Expand Down

0 comments on commit 3a68a33

Please sign in to comment.