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.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,
],
updateHeaderOffsetWhenNotBouncingOrLocked
)
// 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),
[
// y offset got bigger so scrolling down (content travels up the screen)
Animated.set(
const isInRegion = (
x: Animated.Node,
y: Animated.Node,
region: { x: number; y: number }
) => {
return and(
and(greaterOrEq(x, region.x), lessOrEq(x, region.x + BUTTON_SIZE)),
and(greaterOrEq(y, region.y), lessOrEq(y, region.y + BUTTON_SIZE))
);
};
useCode(() => cond(and(active, eq(command, target)), call([], onPress)), [
active,
);
}
if (mathType === 'reanimated') {
return Animated.or(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.and(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.lessThan(left, right);
}
return Number((left as number) < (right as number));
}
tabs.map((tab, i) =>
cond(
i === tabs.length - 1
? greaterOrEq(y, tab.anchor)
: and(
greaterOrEq(y, tab.anchor),
lessOrEq(y, tabs[i + 1].anchor)
),
set(index, i)
)
)
const isInRegion = (
x: Animated.Node,
y: Animated.Node,
region: { x: number; y: number }
) => {
return and(
and(greaterOrEq(x, region.x), lessOrEq(x, region.x + BUTTON_SIZE)),
and(greaterOrEq(y, region.y), lessOrEq(y, region.y + BUTTON_SIZE))
);
};
const inViewport = (
index: Animated.Node,
translateY: Animated.Node,
goingUp: Animated.Node<0 | 1>
) => {
const y = multiply(add(index, not(goingUp)), ITEM_HEIGHT);
const translate = multiply(translateY, -1);
return and(
greaterOrEq(y, translate),
lessOrEq(y, add(translate, CONTENT_HEIGHT))
);
};