Half-broken dismiss animation
This commit is contained in:
@@ -18,7 +18,11 @@ import {
|
|||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {Gesture} from 'react-native-gesture-handler'
|
import {Gesture} from 'react-native-gesture-handler'
|
||||||
import PagerView from 'react-native-pager-view'
|
import PagerView from 'react-native-pager-view'
|
||||||
import {interpolate} from 'react-native-reanimated'
|
import {
|
||||||
|
interpolate,
|
||||||
|
SharedValue,
|
||||||
|
useAnimatedReaction,
|
||||||
|
} from 'react-native-reanimated'
|
||||||
import Animated, {
|
import Animated, {
|
||||||
runOnJS,
|
runOnJS,
|
||||||
useAnimatedStyle,
|
useAnimatedStyle,
|
||||||
@@ -47,20 +51,17 @@ const SCREEN_HEIGHT = Dimensions.get('window').height
|
|||||||
|
|
||||||
function ImageViewing({
|
function ImageViewing({
|
||||||
lightbox,
|
lightbox,
|
||||||
|
openProgress,
|
||||||
onRequestClose,
|
onRequestClose,
|
||||||
onPressSave,
|
onPressSave,
|
||||||
onPressShare,
|
onPressShare,
|
||||||
}: {
|
}: {
|
||||||
lightbox: Lightbox
|
lightbox: Lightbox
|
||||||
|
openProgress: SharedValue<number>
|
||||||
onRequestClose: () => void
|
onRequestClose: () => void
|
||||||
onPressSave: (uri: string) => void
|
onPressSave: (uri: string) => void
|
||||||
onPressShare: (uri: string) => void
|
onPressShare: (uri: string) => void
|
||||||
}) {
|
}) {
|
||||||
const openProgress = useSharedValue(0)
|
|
||||||
React.useEffect(() => {
|
|
||||||
openProgress.value = withClampedSpring(1)
|
|
||||||
}, [openProgress])
|
|
||||||
|
|
||||||
const {images, index: initialImageIndex, thumbDims} = lightbox
|
const {images, index: initialImageIndex, thumbDims} = lightbox
|
||||||
const [isScaled, setIsScaled] = useState(false)
|
const [isScaled, setIsScaled] = useState(false)
|
||||||
const [isDragging, setIsDragging] = useState(false)
|
const [isDragging, setIsDragging] = useState(false)
|
||||||
@@ -383,7 +384,7 @@ const styles = StyleSheet.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function ImageViewingRoot({
|
function ImageViewingRoot({
|
||||||
lightbox,
|
lightbox: nextLightbox,
|
||||||
onRequestClose,
|
onRequestClose,
|
||||||
onPressSave,
|
onPressSave,
|
||||||
onPressShare,
|
onPressShare,
|
||||||
@@ -393,13 +394,39 @@ function ImageViewingRoot({
|
|||||||
onPressSave: (uri: string) => void
|
onPressSave: (uri: string) => void
|
||||||
onPressShare: (uri: string) => void
|
onPressShare: (uri: string) => void
|
||||||
}) {
|
}) {
|
||||||
if (!lightbox) {
|
const [activeLightbox, setActiveLightbox] = useState(nextLightbox)
|
||||||
|
const openProgress = useSharedValue(0)
|
||||||
|
|
||||||
|
if (!activeLightbox && nextLightbox) {
|
||||||
|
setActiveLightbox(nextLightbox)
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (nextLightbox) {
|
||||||
|
openProgress.value = withClampedSpring(1)
|
||||||
|
} else {
|
||||||
|
openProgress.value = withClampedSpring(0)
|
||||||
|
}
|
||||||
|
}, [nextLightbox, openProgress])
|
||||||
|
|
||||||
|
useAnimatedReaction(
|
||||||
|
() => openProgress.value === 0,
|
||||||
|
(isGone, wasGone) => {
|
||||||
|
if (isGone && !wasGone) {
|
||||||
|
runOnJS(setActiveLightbox)(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!activeLightbox) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ImageViewing
|
<ImageViewing
|
||||||
key={lightbox.id}
|
key={activeLightbox.id}
|
||||||
lightbox={lightbox}
|
lightbox={activeLightbox}
|
||||||
|
openProgress={openProgress}
|
||||||
onRequestClose={onRequestClose}
|
onRequestClose={onRequestClose}
|
||||||
onPressSave={onPressSave}
|
onPressSave={onPressSave}
|
||||||
onPressShare={onPressShare}
|
onPressShare={onPressShare}
|
||||||
|
|||||||
@@ -49,10 +49,6 @@ export function Lightbox() {
|
|||||||
[permissionResponse, requestPermission, _],
|
[permissionResponse, requestPermission, _],
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!activeLightbox) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ImageView
|
<ImageView
|
||||||
lightbox={activeLightbox}
|
lightbox={activeLightbox}
|
||||||
|
|||||||
Reference in New Issue
Block a user