Animate transform
This commit is contained in:
@@ -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 {MeasuredDimensions} from 'react-native-reanimated'
|
import {interpolate, MeasuredDimensions} from 'react-native-reanimated'
|
||||||
import Animated, {
|
import Animated, {
|
||||||
runOnJS,
|
runOnJS,
|
||||||
useAnimatedStyle,
|
useAnimatedStyle,
|
||||||
@@ -100,8 +100,42 @@ function ImageViewing({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Apply transform
|
const initialTransform = calculateOverlayTransform(SCREEN, thumbDims)
|
||||||
// const initialTransform = calculateOverlayTransform(SCREEN, thumbDims)
|
const activeImageStyle = useAnimatedStyle(() => {
|
||||||
|
if (openProgress.value === 1) {
|
||||||
|
return {
|
||||||
|
transform: [{translateY: dismissSwipeTranslateY.value}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!initialTransform) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
transform: [
|
||||||
|
{
|
||||||
|
scale: interpolate(
|
||||||
|
openProgress.value,
|
||||||
|
[0, 1],
|
||||||
|
[initialTransform.scale, 1],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
translateX: interpolate(
|
||||||
|
openProgress.value,
|
||||||
|
[0, 1],
|
||||||
|
[initialTransform.translateX, 0],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
translateY: interpolate(
|
||||||
|
openProgress.value,
|
||||||
|
[0, 1],
|
||||||
|
[initialTransform.translateY, 0],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const dismissSwipePan = Gesture.Pan()
|
const dismissSwipePan = Gesture.Pan()
|
||||||
.enabled(!isScaled)
|
.enabled(!isScaled)
|
||||||
@@ -111,7 +145,6 @@ function ImageViewing({
|
|||||||
.onUpdate(e => {
|
.onUpdate(e => {
|
||||||
'worklet'
|
'worklet'
|
||||||
dismissSwipeTranslateY.value = e.translationY
|
dismissSwipeTranslateY.value = e.translationY
|
||||||
console.log(dismissSwipeTranslateY.value)
|
|
||||||
})
|
})
|
||||||
.onEnd(e => {
|
.onEnd(e => {
|
||||||
'worklet'
|
'worklet'
|
||||||
@@ -147,7 +180,7 @@ function ImageViewing({
|
|||||||
const backdropStyle = useAnimatedStyle(() => {
|
const backdropStyle = useAnimatedStyle(() => {
|
||||||
let opacity
|
let opacity
|
||||||
if (openProgress.value < 1) {
|
if (openProgress.value < 1) {
|
||||||
opacity = openProgress.value
|
opacity = Math.sqrt(openProgress.value)
|
||||||
} else {
|
} else {
|
||||||
opacity =
|
opacity =
|
||||||
1 -
|
1 -
|
||||||
@@ -158,11 +191,6 @@ function ImageViewing({
|
|||||||
}
|
}
|
||||||
return {opacity}
|
return {opacity}
|
||||||
})
|
})
|
||||||
const activeImageStyle = useAnimatedStyle(() => {
|
|
||||||
return {
|
|
||||||
transform: [{translateY: dismissSwipeTranslateY.value}],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return null
|
return null
|
||||||
@@ -388,7 +416,7 @@ const EnhancedImageViewing = (props: Props) => (
|
|||||||
|
|
||||||
function withClampedSpring(value: any) {
|
function withClampedSpring(value: any) {
|
||||||
'worklet'
|
'worklet'
|
||||||
return withSpring(value, {overshootClamping: true, stiffness: 300})
|
return withSpring(value, {overshootClamping: true, stiffness: 150})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default EnhancedImageViewing
|
export default EnhancedImageViewing
|
||||||
|
|||||||
Reference in New Issue
Block a user