refactor(PostCard, PostCard.legacy): remove legacy PostCard component and update exports
- Deleted the legacy PostCard component to streamline the codebase and improve maintainability. - Updated exports in PostCard and index files to remove references to the legacy component. - Adjusted PostCardProps to eliminate legacy properties, ensuring only the new API is supported. - Enhanced the PostCard component to focus on modern implementation and features.
This commit is contained in:
@@ -78,6 +78,8 @@ export const ChatScreen: React.FC = () => {
|
||||
// 输入框区域高度(用于定位浮动 mention 面板)
|
||||
const [inputWrapperHeight, setInputWrapperHeight] = useState(60);
|
||||
const [showEdgeLoadingIndicator, setShowEdgeLoadingIndicator] = useState(false);
|
||||
const replyTargetMessageIdRef = useRef<string | null>(null);
|
||||
const replyHighlightTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const isPreloadingRef = useRef(false);
|
||||
const lastScrollYRef = useRef(0);
|
||||
const isUserDraggingRef = useRef(false);
|
||||
@@ -151,6 +153,7 @@ export const ChatScreen: React.FC = () => {
|
||||
longPressMenuVisible,
|
||||
selectedMessage,
|
||||
selectedMessageId,
|
||||
setSelectedMessageId,
|
||||
menuPosition,
|
||||
isGroupChat,
|
||||
groupInfo,
|
||||
@@ -206,6 +209,7 @@ export const ChatScreen: React.FC = () => {
|
||||
handleReachLatestEdge,
|
||||
setBrowsingHistory,
|
||||
} = useChatScreen();
|
||||
const displayMessages = useMemo(() => [...messages].reverse(), [messages]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loadingMore && showEdgeLoadingIndicator) {
|
||||
@@ -218,14 +222,46 @@ export const ChatScreen: React.FC = () => {
|
||||
if (preloadCooldownTimerRef.current) {
|
||||
clearTimeout(preloadCooldownTimerRef.current);
|
||||
}
|
||||
if (replyHighlightTimerRef.current) {
|
||||
clearTimeout(replyHighlightTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const highlightMessageTemporarily = useCallback((messageId: string, duration = 1500) => {
|
||||
if (replyHighlightTimerRef.current) {
|
||||
clearTimeout(replyHighlightTimerRef.current);
|
||||
}
|
||||
setSelectedMessageId(messageId);
|
||||
replyHighlightTimerRef.current = setTimeout(() => {
|
||||
setSelectedMessageId(prev => (prev === messageId ? null : prev));
|
||||
}, duration);
|
||||
}, [setSelectedMessageId]);
|
||||
|
||||
const handleReplyPreviewPress = useCallback((messageId: string) => {
|
||||
const targetId = String(messageId);
|
||||
const targetIndex = displayMessages.findIndex(msg => String(msg.id) === targetId);
|
||||
if (targetIndex < 0) return;
|
||||
|
||||
replyTargetMessageIdRef.current = targetId;
|
||||
setBrowsingHistory(true);
|
||||
highlightMessageTemporarily(targetId);
|
||||
|
||||
flatListRef.current?.scrollToIndex({
|
||||
index: targetIndex,
|
||||
animated: true,
|
||||
viewPosition: 0.5,
|
||||
});
|
||||
}, [displayMessages, flatListRef, highlightMessageTemporarily, setBrowsingHistory]);
|
||||
|
||||
// 监听返回事件,刷新会话列表
|
||||
useEffect(() => {
|
||||
const unsubscribe = navigation.addListener('beforeRemove', () => {
|
||||
// 刷新会话列表,确保已读状态正确显示
|
||||
messageManager.fetchConversations(true);
|
||||
messageManager.requestConversationListRefresh('chat-before-remove', {
|
||||
force: true,
|
||||
allowDefer: false,
|
||||
});
|
||||
});
|
||||
return unsubscribe;
|
||||
}, [navigation]);
|
||||
@@ -261,6 +297,7 @@ export const ChatScreen: React.FC = () => {
|
||||
shouldShowTime={shouldShowTime}
|
||||
onImagePress={handleImagePress}
|
||||
onReply={handleReplyMessage}
|
||||
onReplyPress={handleReplyPreviewPress}
|
||||
/>
|
||||
);
|
||||
}, [
|
||||
@@ -280,14 +317,13 @@ export const ChatScreen: React.FC = () => {
|
||||
shouldShowTime,
|
||||
handleImagePress,
|
||||
handleReplyMessage,
|
||||
handleReplyPreviewPress,
|
||||
]);
|
||||
|
||||
const keyExtractor = useCallback((item: any) => String(item.id), []);
|
||||
|
||||
// 获取正在输入提示
|
||||
const typingHint = getTypingHint();
|
||||
const displayMessages = useMemo(() => [...messages].reverse(), [messages]);
|
||||
|
||||
const handleMessageListScroll = useCallback((event: any) => {
|
||||
const { contentSize, contentOffset, layoutMeasurement } = event.nativeEvent;
|
||||
scrollPositionRef.current = {
|
||||
@@ -410,6 +446,26 @@ export const ChatScreen: React.FC = () => {
|
||||
}}
|
||||
scrollEventThrottle={16}
|
||||
onContentSizeChange={handleContentSizeChange}
|
||||
onScrollToIndexFailed={(info) => {
|
||||
const targetId = replyTargetMessageIdRef.current;
|
||||
if (!targetId || !flatListRef.current) return;
|
||||
|
||||
flatListRef.current.scrollToOffset({
|
||||
offset: Math.max(0, info.averageItemLength * info.index),
|
||||
animated: true,
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
const retryIndex = displayMessages.findIndex(msg => String(msg.id) === targetId);
|
||||
if (retryIndex >= 0) {
|
||||
flatListRef.current?.scrollToIndex({
|
||||
index: retryIndex,
|
||||
animated: true,
|
||||
viewPosition: 0.5,
|
||||
});
|
||||
}
|
||||
}, 120);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{showEdgeLoadingIndicator && (
|
||||
|
||||
Reference in New Issue
Block a user