Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
],
[
// y offset got smaller so scrolling up (content travels down the screen)
// if velocity is high enough or we're already moving the header up or we're near the top of the scroll view
// then move the header down (show it)
Animated.set(amountScrolledUpward, Animated.add(amountScrolledUpward, Animated.abs(scrollDiff))),
Animated.cond(Animated.or(upwardScrollThresholdBreached, headerIsNotFullyUp, nearTheTop), [
Animated.set(headerOffsetY, Animated.min(0, Animated.sub(headerOffsetY, scrollDiff))),
]),
]
)
// we don't want to manipulate the header position while bouncing at the top or the bottom of the scroll view
// cause it feels weeeird
const notBouncingAtTheTop = Animated.greaterThan(scrollOffsetY, 0)
const notBouncingAtTheBottom = Animated.lessThan(scrollOffsetY, Animated.sub(contentHeight, layoutHeight))
const updateHeaderOffsetWhenNotBouncing = Animated.cond(
Animated.and(notBouncingAtTheTop, notBouncingAtTheBottom),
updateHeaderOffset,
[
Animated.cond(
notBouncingAtTheTop,
[
// bouncing at the bottom,
// normally the header will be fully up at this point but sometimes
// the content is not tall enough to cause that, so we still need to
// update the header position just like above. The only difference is that
// when the bounce snaps back, we don't want to trigger opening the header
// like we do when the user explicitly scrolls back upward.
Animated.cond(
Animated.greaterThan(scrollDiff, 0),
Animated.set(headerOffsetY, Animated.max(-headerHeight, Animated.sub(headerOffsetY, scrollDiff))),
],
[
// y offset got smaller so scrolling up (content travels down the screen)
// if velocity is high enough or we're already moving the header up or we're near the top of the scroll view
// then move the header down (show it)
Animated.cond(Animated.or(upwardVelocityBreached, headerIsNotFullyUp, nearTheTop), [
Animated.set(headerOffsetY, Animated.min(0, Animated.sub(headerOffsetY, scrollDiff))),
]),
]
)
// we don't want to manipulate the header position while bouncing at the top or the bottom of the scroll view
// cause it feels weeeird
const notBouncingAtTheTop = Animated.greaterThan(scrollOffsetY, 0)
const notBouncingAtTheBottom = Animated.lessThan(scrollOffsetY, Animated.sub(contentHeight, layoutHeight))
const updateHeaderOffsetWhenNotBouncingOrLocked = Animated.cond(
Animated.and(notBouncingAtTheTop, notBouncingAtTheBottom, Animated.not(lockHeaderPosition)),
updateHeaderOffset,
// deref scroll diff to prevent diff buildup when ignoring changes
scrollDiff
)
// on first eval (when the component mounts) the scroll values will be nonsensical so ignore
const firstEval = new Animated.Value(1)
return Animated.cond(
firstEval,
[
Animated.set(firstEval, 0),
// again, deref scrollDiff to prevent buildup
scrollDiff,
() =>
block([
cond(
not(inViewport(index, translateY, goingUp)),
set(
translateY,
cond(
goingUp,
[add(translateY, ITEM_HEIGHT)],
[sub(translateY, ITEM_HEIGHT)]
)
)
)
]),
[goingUp, index, translateY]
})
return (
`${logPrefix} Cannot use operator "+" on array`
);
}
if (mathType === 'reanimated') {
return Animated.add(left, right);
}
return (left as number) + (right as number);
}
if (tree.token.value === '-') {
if (Array.isArray(left) || Array.isArray(right)) {
throw new InvalidExpressionError(
`${logPrefix} Cannot use operator "-" on array`
);
}
if (mathType === 'reanimated') {
return Animated.sub(left, right);
}
return (left as number) - (right as number);
}
if (tree.token.value === '/') {
if (Array.isArray(left) || Array.isArray(right)) {
throw new InvalidExpressionError(
`${logPrefix} Cannot use operator "/" on array`
);
}
if (mathType === 'reanimated') {
return Animated.divide(left, right);
}
return (left as number) / (right as number);
}
const normalizeProgressProc = Animated.proc((progress, isForward) =>
Animated.cond(
Animated.neq(isForward, 1),
Animated.sub(1, progress),
progress,
),
);
(scrollAmount: Animated.Node, maxScrollDistance: number) =>
Animated.multiply(
Platform.OS === 'android' && I18nManager.isRTL
? Animated.sub(maxScrollDistance, scrollAmount)
: scrollAmount,
I18nManager.isRTL ? 1 : -1
)
);