chore(mobile): fix type error (#3021)
This commit is contained in:
@@ -3,8 +3,8 @@ import type { FC } from "react"
|
||||
import { useRef } from "react"
|
||||
import { Pressable, View } from "react-native"
|
||||
|
||||
import { usePreviewImage } from "./PreviewPageProvider"
|
||||
import { ProxiedImage } from "./ProxiedImage"
|
||||
import { usePreviewImage } from "./usePreviewImage"
|
||||
|
||||
export interface PreviewImageProps {
|
||||
imageUrl: string
|
||||
@@ -46,7 +46,16 @@ export const PreviewImage = ({
|
||||
onPreview?.()
|
||||
openPreview({
|
||||
imageRef,
|
||||
images: [{ imageUrl, aspectRatio, blurhash, recyclingKey: imageUrl }],
|
||||
images: [
|
||||
{
|
||||
source: {
|
||||
uri: imageUrl,
|
||||
},
|
||||
aspectRatio,
|
||||
blurhash,
|
||||
recyclingKey: imageUrl,
|
||||
},
|
||||
],
|
||||
accessoriesElement: Accessory ? <Accessory {...AccessoryProps} /> : undefined,
|
||||
})
|
||||
}}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { createContext } from "react"
|
||||
|
||||
import type { OpenPreviewParams } from "./PreviewPageProvider"
|
||||
|
||||
interface PreviewImageContextType {
|
||||
openPreview: (params: OpenPreviewParams) => void
|
||||
}
|
||||
export const PreviewImageContext = createContext<PreviewImageContextType | null>(null)
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Image } from "expo-image"
|
||||
import type { RefObject } from "react"
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react"
|
||||
import { Dimensions, Modal, Pressable, useWindowDimensions, View } from "react-native"
|
||||
@@ -16,18 +15,13 @@ import { gentleSpringPreset } from "@/src/constants/spring"
|
||||
import { CloseCuteReIcon } from "@/src/icons/close_cute_re"
|
||||
|
||||
import { PortalHost } from "../portal"
|
||||
import type { ImageProps } from "./Image"
|
||||
import { Image } from "./Image"
|
||||
import { ImageContextMenu } from "./ImageContextMenu"
|
||||
|
||||
interface PreviewImageProps {
|
||||
imageUrl: string
|
||||
blurhash?: string | undefined
|
||||
aspectRatio: number
|
||||
recyclingKey?: string
|
||||
}
|
||||
|
||||
interface OpenPreviewParams {
|
||||
imageRef: RefObject<View>
|
||||
images: PreviewImageProps[]
|
||||
images: ImageProps[]
|
||||
initialIndex?: number
|
||||
accessoriesElement?: React.ReactNode
|
||||
}
|
||||
@@ -49,7 +43,7 @@ export const PreviewImageProvider = ({ children }: { children: React.ReactNode }
|
||||
const { width, height } = useWindowDimensions()
|
||||
const [previewModalOpen, setPreviewModalOpen] = useState(false)
|
||||
|
||||
const [currentState, setCurrentState] = useState<PreviewImageProps[] | null>(null)
|
||||
const [currentState, setCurrentState] = useState<ImageProps[] | null>(null)
|
||||
const [imageRef, setImageRef] = useState<View | null>(null)
|
||||
const [currentIndex, setCurrentIndex] = useState(0)
|
||||
const [accessoriesElement, setAccessoriesElement] = useState<React.ReactNode | null>(null)
|
||||
@@ -391,7 +385,7 @@ export const PreviewImageProvider = ({ children }: { children: React.ReactNode }
|
||||
return (
|
||||
<PreviewImageContext.Provider value={ctxValue}>
|
||||
{children}
|
||||
{currentState && (
|
||||
{currentState?.[currentIndex] && (
|
||||
<Modal transparent visible={previewModalOpen}>
|
||||
<PortalHost>
|
||||
<Animated.View style={overlayStyle} className="absolute inset-0" />
|
||||
@@ -421,18 +415,8 @@ export const PreviewImageProvider = ({ children }: { children: React.ReactNode }
|
||||
],
|
||||
}}
|
||||
>
|
||||
<ImageContextMenu imageUrl={currentState[currentIndex]?.imageUrl}>
|
||||
<Image
|
||||
recyclingKey={currentState[currentIndex]?.recyclingKey}
|
||||
source={{ uri: currentState[currentIndex]?.imageUrl }}
|
||||
className="w-full"
|
||||
style={{
|
||||
aspectRatio: currentState[currentIndex]?.aspectRatio,
|
||||
}}
|
||||
placeholder={{
|
||||
blurhash: currentState[currentIndex]?.blurhash,
|
||||
}}
|
||||
/>
|
||||
<ImageContextMenu imageUrl={currentState[currentIndex].source?.uri}>
|
||||
<Image {...currentState[currentIndex]} className="w-full" />
|
||||
</ImageContextMenu>
|
||||
</Animated.View>
|
||||
</Animated.View>
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { useContext } from "react"
|
||||
|
||||
import { PreviewImageContext } from "./PreviewImageContext"
|
||||
|
||||
export const usePreviewImage = () => {
|
||||
const context = useContext(PreviewImageContext)
|
||||
if (!context) {
|
||||
throw new Error("usePreviewImage must be used within PreviewImageProvider")
|
||||
}
|
||||
return context
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export function EntryVideoItem({ id }: { id: string }) {
|
||||
entryId={id}
|
||||
media={firstMedia}
|
||||
aspectRatio={16 / 9}
|
||||
AccessoryProps={{ id }}
|
||||
// AccessoryProps={{ id }}
|
||||
noPreview={true}
|
||||
/>
|
||||
</ItemPressable>
|
||||
|
||||
Reference in New Issue
Block a user