Giter VIP home page Giter VIP logo

animations's People

Contributors

amymc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

animations's Issues

Native spring fails

I think something has changed in react-spring ...

So, say I have this view:

App Vertical
marginTop 100
onClick <
width 100
backgroundColor #ffaa00
when <isClicked
width 150 spring bounciness 20 speed 20
Label Text
text Hi

If I morph it as native I get this:

/* eslint-disable jsx-a11y/accessible-emoji, no-unused-vars */
import React from 'react';
import {
  Animated,
  StyleSheet,
  Text,
  TouchableWithoutFeedback,
} from 'react-native';
import { Spring } from '@viewstools/animations/native';

const styles = StyleSheet.create({
  App1: { marginTop: 100, backgroundColor: '#ffaa00' },
});

class App extends React.Component {
  render() {
    const { props } = this;

    return (
      <Spring
        bounciness={20}
        speed={20}
        delay={0}
        to={{ width: props.isClicked ? 150 : 100 }}
      >
        {animatedApp => (
          <TouchableWithoutFeedback
            activeOpacity={0.7}
            onPress={props.onClick}
            underlayColor="transparent"
          >
            <Animated.View
              testID={`${props['testID'] || 'App'}|${
                props.isClicked ? 'isClicked|' : ''
              }`}
              style={[styles.App1, { width: animatedApp.width }]}
            >
              <Text testID={`App.Label|`}>Hi</Text>
              {props.children}
            </Animated.View>
          </TouchableWithoutFeedback>
        )}
      </Spring>
    );
  }
}

export default App;

It renders fine, but when I try to click on the button I get this:

screen shot 2018-09-12 at 22 51 12

According to this we should use regular RN components and extend them with animated(Component), like this const SpringView = animated(View) but for that to work I had to

  • import the Spring component directly from react-spring
  • and apply the style directly on the element rather than using styleSheet.create.

Here's what worked for me:

/* eslint-disable jsx-a11y/accessible-emoji, no-unused-vars */
import React from 'react';
import {
  Text,
  TouchableWithoutFeedback,
  View
} from 'react-native';
import { Spring, animated } from 'react-spring/dist/native.cjs';

const SpringView = animated(View)

class App extends React.Component {
  render() {
    const { props } = this;

    return (
      <Spring
        native
        bounciness={20}
        speed={20}
        delay={0}
        to={{ width: props.isClicked ? 150 : 100 }}
      >
        {animatedApp => (
          <TouchableWithoutFeedback
            activeOpacity={0.7}
            onPress={props.onClick}
            underlayColor="transparent"
          >
            <SpringView
              testID={`${props['testID'] || 'App'}|${
                props.isClicked ? 'isClicked|' : ''
              }`}
              style={{ marginTop: 100, backgroundColor: '#ffaa00',  width: animatedApp.width }}
            >
              <Text testID={`App.Label|`}>Hi</Text>
              {props.children}
            </SpringView>
          </TouchableWithoutFeedback>
        )}
      </Spring>
    );
  }
}

export default App;

I guess it needs work on this repo and on the morpher. Happy to do it obviously but we should proabbly have a chat about it first, when you some time in a couple of weeks.

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.