refactor(plugins): update JPush config and improve SmartImage loading
- Update `withJPush` plugin to support Expo SDK 56+ by using `JPUSHService.setup` instead of `JCoreModule.setup` and adding `UNUserNotificationCenterDelegate` conformance. - Improve `SmartImage` component by adding a ref to prevent loading state flickering when transitioning from preview to original image. - Upgrade `@shopify/flash-list` dependency. - Add transition prop to `SmartImage` for smoother image loading.
This commit is contained in:
@@ -125,6 +125,7 @@ export const SmartImage: React.FC<SmartImageProps> = ({
|
||||
const [loadState, setLoadState] = useState<ImageLoadState>('loading');
|
||||
const [isVisible, setIsVisible] = useState(() => !lazyLoad || Platform.OS !== 'web');
|
||||
const [shouldLoadOriginal, setShouldLoadOriginal] = useState(false);
|
||||
const isUpgradingFromPreview = useRef(false);
|
||||
const lazyTargetRef = useRef<View>(null);
|
||||
|
||||
// 解析图片源 - 支持 uri 或 url 字段
|
||||
@@ -137,6 +138,7 @@ export const SmartImage: React.FC<SmartImageProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
setShouldLoadOriginal(false);
|
||||
isUpgradingFromPreview.current = false;
|
||||
setLoadState('loading');
|
||||
}, [imageUri]);
|
||||
|
||||
@@ -180,16 +182,24 @@ export const SmartImage: React.FC<SmartImageProps> = ({
|
||||
|
||||
// 处理加载开始
|
||||
const handleLoadStart = useCallback(() => {
|
||||
// 从预览图切换到原图时,不重置为loading状态,避免闪烁
|
||||
if (isUpgradingFromPreview.current) {
|
||||
return;
|
||||
}
|
||||
setLoadState('loading');
|
||||
}, []);
|
||||
|
||||
// 处理加载完成
|
||||
const handleLoad = useCallback(() => {
|
||||
setLoadState('success');
|
||||
// 如果正在加载预览图,切换到原图
|
||||
// 如果正在加载预览图,切换到原图(不重置loading状态,避免闪烁)
|
||||
if (usePreview && !shouldLoadOriginal && previewUri && getImageUrl() === previewUri) {
|
||||
isUpgradingFromPreview.current = true;
|
||||
setShouldLoadOriginal(true);
|
||||
return;
|
||||
}
|
||||
// 原图加载完成(包括从预览图升级的情况)
|
||||
isUpgradingFromPreview.current = false;
|
||||
setLoadState('success');
|
||||
onLoad?.();
|
||||
}, [onLoad, usePreview, shouldLoadOriginal, previewUri, getImageUrl]);
|
||||
|
||||
@@ -198,9 +208,11 @@ export const SmartImage: React.FC<SmartImageProps> = ({
|
||||
(error: any) => {
|
||||
// 如果预览图加载失败,尝试加载原图
|
||||
if (usePreview && !shouldLoadOriginal && getImageUrl() === previewUri && imageUri) {
|
||||
isUpgradingFromPreview.current = true;
|
||||
setShouldLoadOriginal(true);
|
||||
return;
|
||||
}
|
||||
isUpgradingFromPreview.current = false;
|
||||
setLoadState('error');
|
||||
onError?.(error);
|
||||
},
|
||||
@@ -298,6 +310,7 @@ export const SmartImage: React.FC<SmartImageProps> = ({
|
||||
resizeMode === 'center' ? 'scale-down' :
|
||||
resizeMode
|
||||
}
|
||||
transition={200}
|
||||
cachePolicy={cachePolicy}
|
||||
onLoadStart={handleLoadStart}
|
||||
onLoad={handleLoad}
|
||||
|
||||
Reference in New Issue
Block a user