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:
@@ -4,7 +4,7 @@
|
||||
* 使用 expo-image,原生支持 GIF/WebP 动图
|
||||
*/
|
||||
|
||||
import React, { useState, useCallback, useEffect, useMemo } from 'react';
|
||||
import React, { useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
View,
|
||||
@@ -84,6 +84,8 @@ export const ImageGallery: React.FC<ImageGalleryProps> = ({
|
||||
onSave,
|
||||
backgroundOpacity = 1,
|
||||
}) => {
|
||||
const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const isClosingRef = useRef(false);
|
||||
const [currentIndex, setCurrentIndex] = useState(initialIndex);
|
||||
const [showControls, setShowControls] = useState(true);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -136,6 +138,20 @@ export const ImageGallery: React.FC<ImageGalleryProps> = ({
|
||||
}
|
||||
}, [visible, initialIndex, resetZoom]);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
isClosingRef.current = false;
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (closeTimerRef.current) {
|
||||
clearTimeout(closeTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 图片变化时重置加载状态和缩放
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
@@ -156,6 +172,18 @@ export const ImageGallery: React.FC<ImageGalleryProps> = ({
|
||||
setShowControls(prev => !prev);
|
||||
}, []);
|
||||
|
||||
const requestClose = useCallback(() => {
|
||||
if (isClosingRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
isClosingRef.current = true;
|
||||
// 延迟一个短时间窗口,避免关闭同一触摸触发到底层组件
|
||||
closeTimerRef.current = setTimeout(() => {
|
||||
onClose();
|
||||
}, 120);
|
||||
}, [onClose]);
|
||||
|
||||
const goToPrev = useCallback(() => {
|
||||
if (currentIndex > 0) {
|
||||
updateIndex(currentIndex - 1);
|
||||
@@ -297,7 +325,7 @@ export const ImageGallery: React.FC<ImageGalleryProps> = ({
|
||||
.numberOfTaps(1)
|
||||
.maxDistance(10)
|
||||
.onEnd(() => {
|
||||
runOnJS(onClose)();
|
||||
runOnJS(requestClose)();
|
||||
});
|
||||
|
||||
// 组合手势:
|
||||
@@ -326,7 +354,7 @@ export const ImageGallery: React.FC<ImageGalleryProps> = ({
|
||||
visible={visible}
|
||||
transparent
|
||||
animationType="fade"
|
||||
onRequestClose={onClose}
|
||||
onRequestClose={requestClose}
|
||||
statusBarTranslucent
|
||||
>
|
||||
<GestureHandlerRootView style={styles.root}>
|
||||
@@ -334,7 +362,7 @@ export const ImageGallery: React.FC<ImageGalleryProps> = ({
|
||||
{/* 顶部控制栏 */}
|
||||
{showControls && (
|
||||
<View style={[styles.header, { paddingTop: insets.top + spacing.md }]}>
|
||||
<TouchableOpacity style={styles.closeButton} onPress={onClose}>
|
||||
<TouchableOpacity style={styles.closeButton} onPress={requestClose}>
|
||||
<MaterialCommunityIcons name="close" size={24} color="#FFF" />
|
||||
</TouchableOpacity>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user