Key lightbox by id
This commit is contained in:
+10
-3
@@ -1,10 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type {MeasuredDimensions} from 'react-native-reanimated'
|
import type {MeasuredDimensions} from 'react-native-reanimated'
|
||||||
|
import {nanoid} from 'nanoid/non-secure'
|
||||||
|
|
||||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||||
import {ImageSource} from '#/view/com/lightbox/ImageViewing/@types'
|
import {ImageSource} from '#/view/com/lightbox/ImageViewing/@types'
|
||||||
|
|
||||||
export type Lightbox = {
|
export type Lightbox = {
|
||||||
|
id: string
|
||||||
images: ImageSource[]
|
images: ImageSource[]
|
||||||
thumbDims: MeasuredDimensions | null
|
thumbDims: MeasuredDimensions | null
|
||||||
index: number
|
index: number
|
||||||
@@ -29,9 +31,14 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
null,
|
null,
|
||||||
)
|
)
|
||||||
|
|
||||||
const openLightbox = useNonReactiveCallback((lightbox: Lightbox) => {
|
const openLightbox = useNonReactiveCallback(
|
||||||
setActiveLightbox(lightbox)
|
(lightbox: Omit<Lightbox, 'id'>) => {
|
||||||
})
|
setActiveLightbox({
|
||||||
|
...lightbox,
|
||||||
|
id: nanoid(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const closeLightbox = useNonReactiveCallback(() => {
|
const closeLightbox = useNonReactiveCallback(() => {
|
||||||
let wasActive = !!activeLightbox
|
let wasActive = !!activeLightbox
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ function ImageViewingRoot({
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<ImageViewing
|
<ImageViewing
|
||||||
key={lightbox.index}
|
key={lightbox.id}
|
||||||
lightbox={lightbox}
|
lightbox={lightbox}
|
||||||
onRequestClose={onRequestClose}
|
onRequestClose={onRequestClose}
|
||||||
onPressSave={onPressSave}
|
onPressSave={onPressSave}
|
||||||
|
|||||||
Reference in New Issue
Block a user