How to use the react-native-reanimated.createAnimatedComponent 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 rodolfovilaca / AnimationsExperiments / src / screens / speed.js View on Github external
import React, {useState} from 'react';
import {Dimensions, StyleSheet, View, Text} from 'react-native';
import Svg, {Defs, LinearGradient, Stop, Path} from 'react-native-svg';
import Animated from 'react-native-reanimated';
import {useSpring} from '../hooks';
import PoliceCar from '../../assets/svgs/police-car.svg';
import Warning from '../../assets/svgs/warning.svg';
import Camera from '../../assets/svgs/cctv.svg';

const {interpolate, multiply, useCode, call, round} = Animated;
const {width} = Dimensions.get('window');
const size = width - 32;
const strokeWidth = 20;
const AnimatedPath = Animated.createAnimatedComponent(Path);
const {PI, cos, sin} = Math;
const r = (size - strokeWidth) / 2;
const cx = size / 2;
const cy = size / 2;
const A = PI + PI * 0.6;
const startAngle = PI + PI * 0.3;
const endAngle = 2 * PI - PI * 0.3;
// A rx ry x-axis-rotation large-arc-flag sweep-flag x y
const x1 = cx - r * cos(startAngle);
const y1 = -r * sin(startAngle) + cy;
const x2 = cx - r * cos(endAngle);
const y2 = -r * sin(endAngle) + cy;
const d = `M ${x1} ${y1} A ${r} ${r} 0 1 0 ${x2} ${y2}`;
const circumference = r * A;

const Counter = ({progress}) => {
github react-native-community / react-native-tab-view / src / ViewPagerBackend.tsx View on Github external
import * as React from 'react';
import { Keyboard } from 'react-native';
import ViewPager from '@react-native-community/viewpager';
import Animated from 'react-native-reanimated';
import { PanGestureHandler } from 'react-native-gesture-handler';

import {
  Layout,
  NavigationState,
  Route,
  Listener,
  PagerCommonProps,
  EventEmitterProps,
} from './types';

const AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);

type Props<T extends Route> = PagerCommonProps & {
  onIndexChange: (index: number) => void;
  navigationState: NavigationState<T>;
  layout: Layout;
  // Clip unfocused views to improve memory usage
  // Don't enable this on iOS where this is buggy and views don't re-appear
  removeClippedSubviews?: boolean;
  children: (
    props: EventEmitterProps & {
      // Animated value which represents the state of current index
      // It can include fractional digits as it represents the intermediate value
      position: Animated.Node<number>;
      // Function to actually render the content of the pager
      // The parent component takes care of rendering
      render: (children: React.ReactNode) => React.ReactNode;
github wcandillon / react-native-redash / src / ReText.tsx View on Github external
import * as React from "react";
import { TextInput, TextStyle } from "react-native";
import Animated from "react-native-reanimated";

const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);

interface TextProps {
  text: Animated.Node<string>;
  style?: TextStyle;
}

export default (props: TextProps) => {
  const { text, style } = { style: {}, ...props };
  return (
    <AnimatedTextInput
      underlineColorAndroid="transparent"
      editable={false}
      {...{ text, style }}
    />
  );
};
github react-navigation / stack / src / views / Stack / Stack.tsx View on Github external
const MaybeScreen = ({
  enabled,
  active,
  ...rest
}: ViewProps & {
  enabled: boolean;
  active: number | Animated.Node<number>;
  children: React.ReactNode;
}) => {
  if (Platform.OS !== 'ios' && enabled && Screens.screensEnabled()) {
    AnimatedScreen =
      AnimatedScreen || Animated.createAnimatedComponent(Screens.NativeScreen);

    return <AnimatedScreen active={active} {...rest} />;
  }

  return <View {...rest} />;
};
github keybase / client / shared / common-adapters / list2.native.tsx View on Github external
import React, {PureComponent} from 'react'
import * as Flow from '../util/flow'
import {FlatList, View} from 'react-native'
import * as Styles from '../styles'
import {smallHeight, largeHeight} from './list-item2'
import Animated from 'react-native-reanimated'
import {Props} from './list2'

const AnimatedFlatList = Animated.createAnimatedComponent(FlatList)

class List2<T> extends PureComponent<Props<T>> {
  static defaultProps = {
    keyboardShouldPersistTaps: 'handled',
  }

  _itemRender = ({item, index}: {item: T; index: number}) => {
    return this.props.renderItem(index, item)
  }

  _getItemLayout = (data: Array<T> | null, index: number) => {
    switch (this.props.itemHeight.type) {
      case 'fixed':
        return {index, length: this.props.itemHeight.height, offset: this.props.itemHeight.height * index}
      case 'fixedListItem2Auto': {
        const itemHeight = this.props.itemHeight.sizeType === 'Large' ? largeHeight : smallHeight
github rainbow-me / rainbow / src / components / add-cash / AddCashSelector.js View on Github external
positionDiff,
  componentWidths[1] +
    (componentWidths[0] > componentWidths[2] ? positionDiff : 0) -
    centerDiff,
];

const springConfig = {
  damping: 38,
  mass: 1,
  overshootClamping: false,
  restDisplacementThreshold: 0.001,
  restSpeedThreshold: 0.001,
  stiffness: 600,
};

const AnimatedShadowStack = Animated.createAnimatedComponent(ShadowStack);

const MiniCoinIcon = styled(CoinIcon).attrs({
  alignSelf: 'center',
  size: 26,
})`
  margin-left: 7px;
`;

const CoinButtonShadow = [
  [0, 0, 9, colors.shadowGrey, 0.1],
  [0, 5, 15, colors.shadowGrey, 0.12],
  [0, 10, 30, colors.shadowGrey, 0.06],
];

const CoinText = styled(Text)`
  color: ${colors.alpha(colors.blueGreyDark, 0.5)};
github rainbow-me / rainbow / src / components / value-chart / ValueChart.js View on Github external
TapGestureHandler,
} from 'react-native-gesture-handler';
import Animated, { Easing } from 'react-native-reanimated';
import Spline from 'cubic-spline';
import { contains, timing, delay } from 'react-native-redash';
import { View } from 'react-native';
import { data1, data2, data3, data4 } from './data';
import ValueText from './ValueText';
import { deviceUtils } from '../../utils';
import { colors } from '../../styles';
import TimestampText from './TimestampText';
import TimespanSelector from './TimespanSelector';
import ActivityIndicator from '../ActivityIndicator';

const amountOfPathPoints = 288;
const AnimatedPath = Animated.createAnimatedComponent(Path);

const {
  and,
  or,
  eq,
  add,
  sub,
  onChange,
  Value,
  Clock,
  block,
  event,
  concat,
  cond,
  call,
  set,
github rainbow-me / rainbow / src / components / asset-list / AssetListItemSkeleton.js View on Github external
import { CoinRow } from '../coin-row';
import { ColumnWithMargins, Row, RowWithMargins } from '../layout';

const {
  block,
  Clock,
  cond,
  interpolate,
  set,
  startClock,
  stopClock,
  timing,
  Value,
} = Animated;

const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient);

const Container = styled.View`
  height: ${CoinRow.height};
  opacity: ${({ descendingOpacity, index }) => (1 - (0.2 * (descendingOpacity ? index : 0)))};
  width: 100%;
`;

const FakeAvatar = styled.View`
  ${position.size(40)};
  background-color: ${colors.skeleton};
  border-radius: 20;
`;

const FakeRow = withProps({
  align: 'center',
  flex: 0,
github keybase / client / shared / common-adapters / list.native.tsx View on Github external
import React, {PureComponent} from 'react'
import {FlatList, View} from 'react-native'
import * as Styles from '../styles'
import {Props} from './list'
import Animated from 'react-native-reanimated'

const AnimatedFlatList = Animated.createAnimatedComponent(FlatList)

class List<Item> extends PureComponent<Props<Item>> {
  static defaultProps = {
    keyboardShouldPersistTaps: 'handled',
  }
  _itemRender = ({item, index}: {item: Item; index: number}) => {
    return this.props.renderItem(index, item)
  }

  _getItemLayout = (_: Array<Item> | null, index: number) => ({
    index,
    length: this.props.fixedHeight || 0,
    offset: (this.props.fixedHeight || 0) * index,
  })

  _keyExtractor = (item: Item, index: number) => {
github rainbow-me / rainbow / src / components / icons / Svg.js View on Github external
toClass,
} from 'recompact';
import SvgPrimitive from 'svgs';
import { reduceArrayToObject } from '../../utils';

const BlacklistedSVGProps = ['direction'];

const Svg = compose(
  omitProps(...BlacklistedSVGProps),
  mapProps(({ style, ...props }) => ({
    ...props,
    style: reduceArrayToObject(style),
  })),
)(SvgPrimitive);

export const AnimatedSvg = Animated.createAnimatedComponent(toClass(Svg));

export default Svg;