How to use the react-native-reanimated.and function in react-native-reanimated

To help you get started, we’ve selected a few react-native-reanimated examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github artsy / emission / src / lib / Scenes / Partner / Components / StickyHeaderScrollView.tsx View on Github external
// 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
      )
github artsy / emission / src / lib / Components / StickyTabPage / StickyTabPageFlatList.tsx View on Github external
// 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(
github wcandillon / can-it-be-done-in-react-native / season3 / src / iPod / ClickWheel / Buttons.tsx View on Github external
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))
  );
};
github wcandillon / can-it-be-done-in-react-native / season3 / src / iPod / ClickWheel / Buttons.tsx View on Github external
  useCode(() => cond(and(active, eq(command, target)), call([], onPress)), [
    active,
github JonnyBurger / reanimated-formula / src / reduce-ast.ts View on Github external
);
		}
		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));
	}
github wcandillon / can-it-be-done-in-react-native / season3 / src / UberEats / TabHeader.tsx View on Github external
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)
          )
        )
github wcandillon / can-it-be-done-in-react-native / season3 / src / iPod / ClickWheel / Buttons.tsx View on Github external
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))
  );
};
github wcandillon / can-it-be-done-in-react-native / season3 / src / iPod / List / List.tsx View on Github external
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))
  );
};