diff --git a/src/@types/react-navigation.d.ts b/src/@types/react-navigation.d.ts index 9006d853..1b65c3eb 100644 --- a/src/@types/react-navigation.d.ts +++ b/src/@types/react-navigation.d.ts @@ -50,14 +50,14 @@ declare namespace Nav { | undefined 'Screen-ImagesViewer': { imageUrls: { + id: Mastodon.Attachment['id'] url: Mastodon.AttachmentImage['url'] width?: number height?: number preview_url: Mastodon.AttachmentImage['preview_url'] remote_url?: Mastodon.AttachmentImage['remote_url'] - imageIndex: number }[] - imageIndex: number + id: Mastodon.Attachment['id'] } } diff --git a/src/components/Timeline/Shared/Attachment.tsx b/src/components/Timeline/Shared/Attachment.tsx index d76025a8..7afdeff8 100644 --- a/src/components/Timeline/Shared/Attachment.tsx +++ b/src/components/Timeline/Shared/Attachment.tsx @@ -35,10 +35,10 @@ const TimelineAttachment = React.memo( let imageUrls: Nav.RootStackParamList['Screen-ImagesViewer']['imageUrls'] = [] const navigation = useNavigation() - const navigateToImagesViewer = (imageIndex: number) => + const navigateToImagesViewer = (id: string) => navigation.navigate('Screen-ImagesViewer', { imageUrls, - imageIndex + id }) const attachments = useMemo( () => @@ -46,12 +46,12 @@ const TimelineAttachment = React.memo( switch (attachment.type) { case 'image': imageUrls.push({ + id: attachment.id, url: attachment.url, preview_url: attachment.preview_url, remote_url: attachment.remote_url, width: attachment.meta?.original?.width, - height: attachment.meta?.original?.height, - imageIndex: index + height: attachment.meta?.original?.height }) return ( void + navigateToImagesViewer: (imageIndex: string) => void } const AttachmentImage = React.memo( ({ total, index, sensitiveShown, image, navigateToImagesViewer }: Props) => { const onPress = useCallback(() => { analytics('timeline_shared_attachment_image_press', { id: image.id }) - navigateToImagesViewer(index) + navigateToImagesViewer(image.id) }, []) return ( diff --git a/src/modules/react-native-image-viewing b/src/modules/react-native-image-viewing index 60ea23a6..2ef53462 160000 --- a/src/modules/react-native-image-viewing +++ b/src/modules/react-native-image-viewing @@ -1 +1 @@ -Subproject commit 60ea23a67512e97d8cb429d9825c75294603e262 +Subproject commit 2ef534628190a98dc2ce74b9d5adb4253cb1a4ab diff --git a/src/screens/ImagesViewer.tsx b/src/screens/ImagesViewer.tsx index 078db81a..5b06f0d3 100644 --- a/src/screens/ImagesViewer.tsx +++ b/src/screens/ImagesViewer.tsx @@ -34,7 +34,6 @@ const HeaderComponent = React.memo( height?: number | undefined preview_url: string remote_url?: string | undefined - imageIndex: number }[] }) => { const insets = useSafeAreaInsets() @@ -134,7 +133,7 @@ export type ScreenImagesViewerProp = StackScreenProps< const ScreenImagesViewer = ({ route: { - params: { imageUrls, imageIndex } + params: { imageUrls, id } }, navigation }: ScreenImagesViewerProp) => { @@ -142,16 +141,15 @@ const ScreenImagesViewer = ({ return null } - const [currentIndex, setCurrentIndex] = useState( - findIndex(imageUrls, ['imageIndex', imageIndex]) - ) + const initialIndex = findIndex(imageUrls, ['id', id]) + const [currentIndex, setCurrentIndex] = useState(initialIndex) return ( setCurrentIndex(index)} onRequestClose={() => navigation.goBack()} HeaderComponent={() => (