How to use the react-native-reanimated.Value 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.

github birkir / kvikmyndr-app / src / components / week-tab-view / WeekTabView.tsx View on Github external
const NAVBAR_HEIGHT = 56;
const INITIAL_LAYOUT = {
  height: 0,
  width: Dimensions.get('window').width,
};

@observer
export default class WeekTabView extends React.Component<IProps> {

  // tslint:disable max-line-length
  private tabBar: any;
  private tabBarUpdated: boolean = false;
  private panX = new Animated.Value(0);
  private scrollY = new Reanimated.Value(0);
  private scrollEndDragVelocity = new Reanimated.Value(10000000);
  private snapOffset = new Reanimated.Value(0);
  private clock = new Reanimated.Clock();
  private diffClampNode = Reanimated.diffClamp(Reanimated.add(this.scrollY, this.snapOffset), 0, NAVBAR_HEIGHT);
  private inverseDiffClampNode = Reanimated.multiply(this.diffClampNode, -1);
  private snapPoint = Reanimated.cond(Reanimated.lessThan(this.diffClampNode, NAVBAR_HEIGHT / 2), 0, -NAVBAR_HEIGHT);
  private animatedNavBarTranslateY = Reanimated.cond(
    Reanimated.neq(this.scrollEndDragVelocity, 10000000),
    runScrollEndSpring({
      diffClampNode: this.diffClampNode,
      clock: this.clock,
      from: this.inverseDiffClampNode,
      velocity: 0,
      toValue: this.snapPoint,
      scrollEndDragVelocity: this.scrollEndDragVelocity,
      snapOffset: this.snapOffset,
      height: NAVBAR_HEIGHT,
github rainbow-me / rainbow / src / components / fields / UnderlineField.js View on Github external
this.state = {
      isFocused: props.autoFocus,
      value: props.value,
    };
  }

  componentDidUpdate(prevProps) {
    const { value } = this.props;

    if (value !== prevProps.value) {
      // eslint-disable-next-line react/no-did-update-set-state
      this.setState({ value });
    }
  }

  animation = new Animated.Value(0);

  format = string => (this.props.format ? this.props.format(string) : string);

  onBlur = (...props) => {
    Animated.timing(this.animation, {
      duration: 1,
      easing: Easing.linear,
      toValue: 0,
    }).start();

    this.setState({ isFocused: false });

    if (this.props.onBlur) this.props.onBlur(...props);
  };

  onChange = event => {
github terrysahaidak / react-native-retween / src / useTween.ts View on Github external
function generateTweenAnimation<T extends AnimationInputValues>(
  props: TweenAnimationProps<T>,
): Animation<T> {
  const animationState = new A.Value<AnimationState>(
    AnimationState.START_POINT,
  );
  const keys = Object.keys(props.from);
  const masterValue = new A.Value(0);
  const inputRange: [number, number] = [0, 1];

  const values: ReanimatedValues<T> = keys.reduce(
    (acc, current) => {
      const from = props.from[current];
      const to = props.to[current];

      // if we are interpolating colors
      if (isRGB(from) && isRGB(to)) {
        acc[current] = bInterpolateColor(masterValue, {
          inputRange,
          outputRange: [from, to],
        });
        // currently only numbers are allowed
      } else if (isNumber(from) && isNumber(to)) {
        acc[current] = interpolate(masterValue, {
github react-navigation / experimental-transitioner / src / Shared.js View on Github external
const getLayout = (layoutsObj, id) => {
  if (!layoutsObj) {
    return null;
  }
  const layout =
    layoutsObj[id] ||
    (layoutsObj[id] = {
      hasMeasured: new Animated.Value(0),
      x: new Animated.Value(0),
      y: new Animated.Value(0),
      w: new Animated.Value(0),
      h: new Animated.Value(0),
    });
  return layout;
};
github terrysahaidak / react-native-retween / src / animations / runSpring.ts View on Github external
function transformSpringConfigToAnimatedValues(
  config: Partial<SpringConfig>,
): AnimatedSpringConfig {
  return {
    damping: config.damping
      ? new A.Value(config.damping)
      : defaultConfig.damping,
    stiffness: config.stiffness
      ? new A.Value(config.stiffness)
      : defaultConfig.stiffness,
    mass: config.mass ? new A.Value(config.mass) : defaultConfig.mass,
    restDisplacementThreshold: config.restDisplacementThreshold
      ? new A.Value(config.restDisplacementThreshold)
      : defaultConfig.restDisplacementThreshold,
    restSpeedThreshold: config.restSpeedThreshold
      ? new A.Value(config.restSpeedThreshold)
      : defaultConfig.restSpeedThreshold,
    overshootClamping: new A.Value(config.overshootClamping ? 1 : 0),
  };
}
github terrysahaidak / react-native-retween / src / animations / runSpring.ts View on Github external
): AnimatedSpringConfig {
  return {
    damping: config.damping
      ? new A.Value(config.damping)
      : defaultConfig.damping,
    stiffness: config.stiffness
      ? new A.Value(config.stiffness)
      : defaultConfig.stiffness,
    mass: config.mass ? new A.Value(config.mass) : defaultConfig.mass,
    restDisplacementThreshold: config.restDisplacementThreshold
      ? new A.Value(config.restDisplacementThreshold)
      : defaultConfig.restDisplacementThreshold,
    restSpeedThreshold: config.restSpeedThreshold
      ? new A.Value(config.restSpeedThreshold)
      : defaultConfig.restSpeedThreshold,
    overshootClamping: new A.Value(config.overshootClamping ? 1 : 0),
  };
}
github rainbow-me / rainbow / src / components / animations / FlyInAnimation.js View on Github external
Animated.timing(value, {
    duration: 175,
    easing: Easing.bezier(0.165, 0.84, 0.44, 1),
    isInteraction: false,
    toValue,
    useNativeDriver: true,
  }).start()
);

export default class FlyInAnimation extends PureComponent {
  static propTypes = {
    children: PropTypes.any,
    style: PropTypes.object,
  };

  animation = new Animated.Value(0)

  componentDidMount = () => buildAnimation(this.animation, 1)

  componentWillUnmount = () => buildAnimation(this.animation, 0)

  buildInterpolation = outputRange => (
    Animated.interpolate(this.animation, {
      inputRange: [0, 1],
      outputRange,
    })
  )

  render = () => (
    <Animated.View
      style={{
        ...this.props.style,
github wcandillon / can-it-be-done-in-react-native / season2 / spotify-player / components / AnimatedHelpers / Gestures.ts View on Github external
export const preserveMultiplicativeOffset = (
  value: Animated.Adaptable<number>,
  state: Animated.Adaptable<number>
) => {
  const previous = new Animated.Value(1);
  const offset = new Animated.Value(1);

  return block([
    cond(
      eq(state, State.BEGAN),
      [set(previous, 1)],
      [
        set(offset, multiply(offset, divide(value, previous))),
        set(previous, value)
      ]
    ),
    offset
  ]);
};
github browniefed / react-native-ticker / index.tsx View on Github external
  const widthAnim = useInitRef(() => new Animated.Value(measurement.width));
  const stylePos = useInitRef(() => new Animated.Value(position));
github react-navigation / navigation-ex / packages / stack / src / views / Stack / CardAnimation.tsx View on Github external
import Animated from 'react-native-reanimated';
import { State as GestureState } from 'react-native-gesture-handler';

export type Binary = 0 | 1;

const TRUE_NODE = new Animated.Value(1);
const FALSE_NODE = new Animated.Value(0);
const UNSET_NODE = new Animated.Value(-1);

const NOOP_NODE = FALSE_NODE;

const {
  abs,
  add,
  and,
  block,
  cond,
  divide,
  eq,
  greaterThan,
  lessThan,
  max,
  min,