Inline lightbox helpers
This commit is contained in:
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) JOB TODAY S.A. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Animated} from 'react-native'
|
|
||||||
|
|
||||||
const INITIAL_POSITION = {x: 0, y: 0}
|
|
||||||
const ANIMATION_CONFIG = {
|
|
||||||
duration: 200,
|
|
||||||
useNativeDriver: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
const useAnimatedComponents = () => {
|
|
||||||
const headerTranslate = new Animated.ValueXY(INITIAL_POSITION)
|
|
||||||
const footerTranslate = new Animated.ValueXY(INITIAL_POSITION)
|
|
||||||
|
|
||||||
const toggleVisible = (isVisible: boolean) => {
|
|
||||||
if (isVisible) {
|
|
||||||
Animated.parallel([
|
|
||||||
Animated.timing(headerTranslate.y, {...ANIMATION_CONFIG, toValue: 0}),
|
|
||||||
Animated.timing(footerTranslate.y, {...ANIMATION_CONFIG, toValue: 0}),
|
|
||||||
]).start()
|
|
||||||
} else {
|
|
||||||
Animated.parallel([
|
|
||||||
Animated.timing(headerTranslate.y, {
|
|
||||||
...ANIMATION_CONFIG,
|
|
||||||
toValue: -300,
|
|
||||||
}),
|
|
||||||
Animated.timing(footerTranslate.y, {
|
|
||||||
...ANIMATION_CONFIG,
|
|
||||||
toValue: 300,
|
|
||||||
}),
|
|
||||||
]).start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const headerTransform = headerTranslate.getTranslateTransform()
|
|
||||||
const footerTransform = footerTranslate.getTranslateTransform()
|
|
||||||
|
|
||||||
return [headerTransform, footerTransform, toggleVisible] as const
|
|
||||||
}
|
|
||||||
|
|
||||||
export default useAnimatedComponents
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) JOB TODAY S.A. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {useState} from 'react'
|
|
||||||
import {NativeSyntheticEvent, NativeScrollEvent} from 'react-native'
|
|
||||||
|
|
||||||
import {Dimensions} from '../@types'
|
|
||||||
|
|
||||||
const useImageIndexChange = (imageIndex: number, screen: Dimensions) => {
|
|
||||||
const [currentImageIndex, setImageIndex] = useState(imageIndex)
|
|
||||||
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
||||||
const {
|
|
||||||
nativeEvent: {
|
|
||||||
contentOffset: {x: scrollX},
|
|
||||||
},
|
|
||||||
} = event
|
|
||||||
|
|
||||||
if (screen.width) {
|
|
||||||
const nextIndex = Math.round(scrollX / screen.width)
|
|
||||||
setImageIndex(nextIndex < 0 ? 0 : nextIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [currentImageIndex, onScroll] as const
|
|
||||||
}
|
|
||||||
|
|
||||||
export default useImageIndexChange
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) JOB TODAY S.A. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {useState} from 'react'
|
|
||||||
|
|
||||||
const useRequestClose = (onRequestClose: () => void) => {
|
|
||||||
const [opacity, setOpacity] = useState(1)
|
|
||||||
|
|
||||||
return [
|
|
||||||
opacity,
|
|
||||||
() => {
|
|
||||||
setOpacity(0)
|
|
||||||
onRequestClose()
|
|
||||||
setTimeout(() => setOpacity(1), 0)
|
|
||||||
},
|
|
||||||
] as const
|
|
||||||
}
|
|
||||||
|
|
||||||
export default useRequestClose
|
|
||||||
@@ -14,10 +14,13 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import {
|
import {
|
||||||
Animated,
|
Animated,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
|
NativeSyntheticEvent,
|
||||||
|
NativeScrollEvent,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
View,
|
View,
|
||||||
VirtualizedList,
|
VirtualizedList,
|
||||||
@@ -29,10 +32,7 @@ import {ModalsContainer} from '../../modals/Modal'
|
|||||||
import ImageItem from './components/ImageItem/ImageItem'
|
import ImageItem from './components/ImageItem/ImageItem'
|
||||||
import ImageDefaultHeader from './components/ImageDefaultHeader'
|
import ImageDefaultHeader from './components/ImageDefaultHeader'
|
||||||
|
|
||||||
import useAnimatedComponents from './hooks/useAnimatedComponents'
|
import {ImageSource, Dimensions as ScreenDimensions} from './@types'
|
||||||
import useImageIndexChange from './hooks/useImageIndexChange'
|
|
||||||
import useRequestClose from './hooks/useRequestClose'
|
|
||||||
import {ImageSource} from './@types'
|
|
||||||
import {Edge, SafeAreaView} from 'react-native-safe-area-context'
|
import {Edge, SafeAreaView} from 'react-native-safe-area-context'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -176,6 +176,73 @@ function ImageViewing({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INITIAL_POSITION = {x: 0, y: 0}
|
||||||
|
const ANIMATION_CONFIG = {
|
||||||
|
duration: 200,
|
||||||
|
useNativeDriver: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
const useAnimatedComponents = () => {
|
||||||
|
const headerTranslate = new Animated.ValueXY(INITIAL_POSITION)
|
||||||
|
const footerTranslate = new Animated.ValueXY(INITIAL_POSITION)
|
||||||
|
|
||||||
|
const toggleVisible = (isVisible: boolean) => {
|
||||||
|
if (isVisible) {
|
||||||
|
Animated.parallel([
|
||||||
|
Animated.timing(headerTranslate.y, {...ANIMATION_CONFIG, toValue: 0}),
|
||||||
|
Animated.timing(footerTranslate.y, {...ANIMATION_CONFIG, toValue: 0}),
|
||||||
|
]).start()
|
||||||
|
} else {
|
||||||
|
Animated.parallel([
|
||||||
|
Animated.timing(headerTranslate.y, {
|
||||||
|
...ANIMATION_CONFIG,
|
||||||
|
toValue: -300,
|
||||||
|
}),
|
||||||
|
Animated.timing(footerTranslate.y, {
|
||||||
|
...ANIMATION_CONFIG,
|
||||||
|
toValue: 300,
|
||||||
|
}),
|
||||||
|
]).start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const headerTransform = headerTranslate.getTranslateTransform()
|
||||||
|
const footerTransform = footerTranslate.getTranslateTransform()
|
||||||
|
|
||||||
|
return [headerTransform, footerTransform, toggleVisible] as const
|
||||||
|
}
|
||||||
|
|
||||||
|
const useRequestClose = (onRequestClose: () => void) => {
|
||||||
|
const [opacity, setOpacity] = useState(1)
|
||||||
|
|
||||||
|
return [
|
||||||
|
opacity,
|
||||||
|
() => {
|
||||||
|
setOpacity(0)
|
||||||
|
onRequestClose()
|
||||||
|
setTimeout(() => setOpacity(1), 0)
|
||||||
|
},
|
||||||
|
] as const
|
||||||
|
}
|
||||||
|
|
||||||
|
const useImageIndexChange = (imageIndex: number, screen: ScreenDimensions) => {
|
||||||
|
const [currentImageIndex, setImageIndex] = useState(imageIndex)
|
||||||
|
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||||
|
const {
|
||||||
|
nativeEvent: {
|
||||||
|
contentOffset: {x: scrollX},
|
||||||
|
},
|
||||||
|
} = event
|
||||||
|
|
||||||
|
if (screen.width) {
|
||||||
|
const nextIndex = Math.round(scrollX / screen.width)
|
||||||
|
setImageIndex(nextIndex < 0 ? 0 : nextIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [currentImageIndex, onScroll] as const
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
screen: {
|
screen: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
Reference in New Issue
Block a user