Conslidate ImageView props
This commit is contained in:
@@ -4,7 +4,7 @@ import type {MeasuredDimensions} from 'react-native-reanimated'
|
|||||||
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'
|
||||||
|
|
||||||
type Lightbox = {
|
export type Lightbox = {
|
||||||
images: ImageSource[]
|
images: ImageSource[]
|
||||||
thumbDims: MeasuredDimensions | null
|
thumbDims: MeasuredDimensions | null
|
||||||
index: number
|
index: number
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ 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, MeasuredDimensions} from 'react-native-reanimated'
|
import {interpolate} from 'react-native-reanimated'
|
||||||
import Animated, {
|
import Animated, {
|
||||||
runOnJS,
|
runOnJS,
|
||||||
useAnimatedStyle,
|
useAnimatedStyle,
|
||||||
@@ -33,6 +33,7 @@ import {Trans} from '@lingui/macro'
|
|||||||
|
|
||||||
import {colors, s} from '#/lib/styles'
|
import {colors, s} from '#/lib/styles'
|
||||||
import {isIOS} from '#/platform/detection'
|
import {isIOS} from '#/platform/detection'
|
||||||
|
import {Lightbox} from '#/state/lightbox'
|
||||||
import {Button} from '#/view/com/util/forms/Button'
|
import {Button} from '#/view/com/util/forms/Button'
|
||||||
import {Text} from '#/view/com/util/text/Text'
|
import {Text} from '#/view/com/util/text/Text'
|
||||||
import {ScrollView} from '#/view/com/util/Views'
|
import {ScrollView} from '#/view/com/util/Views'
|
||||||
@@ -42,33 +43,25 @@ import ImageItem from './components/ImageItem/ImageItem'
|
|||||||
|
|
||||||
const SCREEN = Dimensions.get('screen')
|
const SCREEN = Dimensions.get('screen')
|
||||||
|
|
||||||
type Props = {
|
|
||||||
images: ImageSource[]
|
|
||||||
thumbDims: MeasuredDimensions | null
|
|
||||||
initialImageIndex: number
|
|
||||||
visible: boolean
|
|
||||||
onRequestClose: () => void
|
|
||||||
backgroundColor?: string
|
|
||||||
onPressSave: (uri: string) => void
|
|
||||||
onPressShare: (uri: string) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
const SCREEN_HEIGHT = Dimensions.get('window').height
|
const SCREEN_HEIGHT = Dimensions.get('window').height
|
||||||
|
|
||||||
function ImageViewing({
|
function ImageViewing({
|
||||||
images,
|
lightbox,
|
||||||
thumbDims,
|
|
||||||
initialImageIndex,
|
|
||||||
visible,
|
|
||||||
onRequestClose,
|
onRequestClose,
|
||||||
onPressSave,
|
onPressSave,
|
||||||
onPressShare,
|
onPressShare,
|
||||||
}: Props) {
|
}: {
|
||||||
|
lightbox: Lightbox
|
||||||
|
onRequestClose: () => void
|
||||||
|
onPressSave: (uri: string) => void
|
||||||
|
onPressShare: (uri: string) => void
|
||||||
|
}) {
|
||||||
const openProgress = useSharedValue(0)
|
const openProgress = useSharedValue(0)
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
openProgress.value = withClampedSpring(1)
|
openProgress.value = withClampedSpring(1)
|
||||||
}, [openProgress])
|
}, [openProgress])
|
||||||
|
|
||||||
|
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)
|
||||||
const [imageIndex, setImageIndex] = useState(initialImageIndex)
|
const [imageIndex, setImageIndex] = useState(initialImageIndex)
|
||||||
@@ -176,10 +169,6 @@ function ImageViewing({
|
|||||||
return {opacity}
|
return {opacity}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!visible) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView
|
<SafeAreaView
|
||||||
style={styles.screen}
|
style={styles.screen}
|
||||||
@@ -393,13 +382,34 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const EnhancedImageViewing = (props: Props) => (
|
function ImageViewingRoot({
|
||||||
<ImageViewing key={props.initialImageIndex} {...props} />
|
lightbox,
|
||||||
)
|
onRequestClose,
|
||||||
|
onPressSave,
|
||||||
|
onPressShare,
|
||||||
|
}: {
|
||||||
|
lightbox: Lightbox | null
|
||||||
|
onRequestClose: () => void
|
||||||
|
onPressSave: (uri: string) => void
|
||||||
|
onPressShare: (uri: string) => void
|
||||||
|
}) {
|
||||||
|
if (!lightbox) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<ImageViewing
|
||||||
|
key={lightbox.index}
|
||||||
|
lightbox={lightbox}
|
||||||
|
onRequestClose={onRequestClose}
|
||||||
|
onPressSave={onPressSave}
|
||||||
|
onPressShare={onPressShare}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function withClampedSpring(value: any) {
|
function withClampedSpring(value: any) {
|
||||||
'worklet'
|
'worklet'
|
||||||
return withSpring(value, {overshootClamping: true, stiffness: 150})
|
return withSpring(value, {overshootClamping: true, stiffness: 150})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default EnhancedImageViewing
|
export default ImageViewingRoot
|
||||||
|
|||||||
@@ -55,10 +55,7 @@ export function Lightbox() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ImageView
|
<ImageView
|
||||||
images={activeLightbox.images}
|
lightbox={activeLightbox}
|
||||||
initialImageIndex={activeLightbox.index}
|
|
||||||
thumbDims={activeLightbox.thumbDims}
|
|
||||||
visible
|
|
||||||
onRequestClose={onClose}
|
onRequestClose={onClose}
|
||||||
onPressSave={saveImageToAlbumWithToasts}
|
onPressSave={saveImageToAlbumWithToasts}
|
||||||
onPressShare={uri => shareImageModal({uri})}
|
onPressShare={uri => shareImageModal({uri})}
|
||||||
|
|||||||
Reference in New Issue
Block a user