Git Product home page Git Product logo

react-native-retween's Introduction

React Native ReTween

Blazing fast and easy tween animation.

Installation

Open a Terminal in the project root and run:

yarn add react-native-retween

Now we need to install react-native-reanimated.

If you are using Expo (this might work slower with latest Expo SDK 35 than vanilla RN, since it has outdated version of reanimated with no proces), to ensure that you get the compatible versions of the libraries, run:

expo install react-native-reanimated

If you are not using Expo, run the following:

yarn add react-native-reanimated

If you are using Expo, you are done. Otherwise, continue to the next steps.

Next, we need to link these libraries. The steps depends on your React Native version:

  • React Native 0.60 and higher

    On newer versions of React Native, linking is automatic.

    To complete the linking on iOS, make sure you have Cocoapods installed. Then run:

    cd ios
    pod install
    cd ..
  • React Native 0.59 and lower

    If you're on an older React Native version, you need to manually link the dependencies. To do that, run:

    react-native link react-native-reanimated

Quick overview

You can find this in the example folder.

function TweenExample() {
  const { play, values, stop } = useTween(() => ({
    timing: {
      duration: 400,
    },
    // otherwise you can use spring
    // spring: {
    //   mass: 1,
    // },
    from: {
      width: 50,
      height: 50,
      left: 20,
      borderRadius: 0,
    },
    to: {
      width: 200,
      height: 200,
      left: windowWidth - 20 - 200,
      borderRadius: 2,
    },
  }));

  const [backward, setBackward] = React.useState(false);

  function onPress() {
    play(backward);
    setBackward((val) => !val);
  }

  return (
    <View style={s.animationContainer}>
      <View style={s.row}>
        <Button onPress={onPress} title="Toggle animation" />
        <Button onPress={stop} title="Stop" />
      </View>

      <Animated.View style={[s.animatedView, values]} />
    </View>
  );
}

License

MIT

react-native-retween's People

Contributors

terrysahaidak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-retween's Issues

_reactNativeReanimated.default.proc is not a function

Hi @terrysahaidak. Awesome idea!
Any attempt to make Reanimated easier to digest โ€“ I'm all for it :)

I followed your steps using an Expo build, and received the following error: _reactNativeReanimated.default.proc is not a function the error is at: runTiming.ts:13:21

Any idea where I'm going wrong?
Here are the relevant details from my package.json file and app.json respectively.

"react-native-reanimated": "~1.2.0",
"react-native-retween": "^0.2.0",
"expo": "^35.0.0",
"react": "16.8.3",
 "react-dom": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"sdkVersion": "35.0.0",

And here's the full component code for completeness:

import React, { useRef, useEffect, useState } from 'react'
import { Text } from 'react-native'
import Animated from 'react-native-reanimated'
import { useTween } from 'react-native-retween'

import styled from 'styled-components/native'
import { sharedStyles } from 'theme'

type PromptType = 'success' | 'warn' | 'error'

interface Props {
  children: React.ReactNode
  isVisible: boolean
  type?: PromptType
}

const mapColor = (type: PromptType = 'success') => {
  switch (type) {
    case 'error':
      return 'red'
    case 'warn':
      return 'yellow'
    case 'success':
      return 'green'
    default:
      return 'green'
  }
}

const animConfig = {
  spring: {
    mass: 1,
  },
  from: {
    opacity: 0,
  },
  to: {
    opacity: 1,
  },
}

const FormPrompt = ({ children, isVisible }: Props) => {
  const { play, values, stop } = useTween(() => animConfig)
  useEffect(() => {
    play(isVisible)
  }, [isVisible])
  return (
    <Animated.View style={values}>
      <Wrapper>
        <Text>{children}</Text>
      </Wrapper>
    </Animated.View>
  )
}

const Wrapper = styled.View<Pick<Props, 'type'>>`
  padding: ${sharedStyles.spacing.md};
  border-radius: ${sharedStyles.bdrs.sm};
  background-color: ${props => mapColor(props.type)};
`

export default FormPrompt

Let me know if there's anything else I can provide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.