Giter Site home page Giter Site logo

react-native-foldview's Introduction

React Native FoldView Medium CircleCI npm version npm

FoldingCell implementation in JavaScript. This project was inspired by the folding cell animation seen on Dribbble.

Questions?

Feel free to reach out to me on Twitter @jmurzy.

Read it on Medium

To learn more about how FoldView was implemented, check out the article on Medium: Implementing FoldView in React Native.

Example

The demo app from the GIF can be found at examples/Simple.

To build and run the example app:

git clone https://github.com/jmurzy/react-native-foldview

cd react-native-foldview/examples/Simple
npm install

To deploy to iOS simulator:

npm run ios

Installation

Using npm:

$ npm install --save react-native-foldview

Using yarn:

$ yarn add react-native-foldview

Usage

import React, { Component } from 'react';

import FoldView from 'react-native-foldview';

const Frontface = (props) => (/*...*/);
const Backface = (props) => (/*...*/);
const Base = (props) => (/*...*/);

export default class Row extends Component {

  constructor(props) {
    super(props);

    this.state = {
      expanded: false,
    };
  }

  componentWillMount() {
    this.flip = this.flip.bind(this);
  }

  flip() {
    this.setState({
      expanded: !this.state.expanded,
    });
  }

  renderFrontface() {
    return (
      <Frontface />
    );
  }

  renderBackface() {
    /**
     * You can nest <FoldView>s here to achieve the folding effect shown in the GIF above.
     * A reference implementation can be found in examples/Simple.
     */
    return (
      <Backface />
    );
  }

  render() {
    return (
      <FoldView
        expanded={this.state.expanded}
        renderBackface={this.renderBackface}
        renderFrontface={this.renderFrontface}
      >
        <Base />
      </FoldView>
    );
  }
}

Props

Prop Type Description
children ReactElement<any> React Element(s) to render.
flipDuration ?number Length of flip animation in milliseconds. Default 280.
renderBackface () => ReactElement<any> Callback that renders a backface.
renderFrontface () => ReactElement<any> Callback that renders a frontface.
renderLoading ?() => ReactElement<any> Callback that renders a temporary view to display before base layout occurs. If not provided, renderFrontface is used instead.

Root-only Props

FoldViews can be nested. The following props can only be set on the root FoldView.

Prop Type Description
collapse ?(foldviews: Array<IFoldView>) => Promise Called when FoldView should collapse allowing you to have control over which FoldViews(s) to collapse. Default behavior is to wait until a FoldView is collapsed before collapsing the next one.
expand ?(foldviews: Array<IFoldView>) => Promise Called when FoldView should expand allowing you to have control over which FoldView(s) to expand. Default behavior is to wait until a FoldView is expanded before expanding the next one.
expanded boolean Allows you to expand and collapse the FoldView content.
onAnimationEnd ?(duration: number, height: number) => void Called when a collapse animation ends.
onAnimationStart ?(duration: number, height: number) => void Called before an expand animation starts.
perspective ?number Defines the space within which the 3D animation occurs.

Advanced Usage

You can customize the behavior of expand and collapse animations using the expand and collapse props on the root FoldView. For example, it's very much possible to collapse all FoldViews in a given stack altogether rather than one by one. You can do so as follows:

const collapse = async (foldViews) => {
  /**
   * Internally, FoldView turns off rasterization when collapsed as an optimization to decrease
   * memory usage. It's important to wrap your calls in a `Promise` here to avoid early disabling
   * of rasterization.
   */
  await Promise.all(foldViews.map(foldView => foldView.collapse()));
}

<FoldView
  collapse={collapse}
  renderBackface={/* ... */}
  renderFrontface={/* ... */}
>
  { /* ... */ }
</FoldView>

Platform Support

This library heavily depends on the overflow style property. Unfortunately, overflow defaults to hidden on Android and cannot be changed. Although it looks like a possible fix is in the making, currently, FoldingView is only supported on iOS.

Contributing

Contributions are very welcome: bug fixes, features, documentation, tests. Just make sure the CI is 👌.

Hacking

Unfortunately, React Native packager does not support symlinking so you cannot use npm link when hacking on this library. You can learn more about that, here.

The library code is specified as a [local dependency](local dependency) in the example's package.json. In order to hack on the library code, you need to sync it into examples/Simple/node_modules. To do so, run:

npm run watch

This will automatically watch the src directory and sync your changes into examples/Simple/node_modules every time something changes.

License

All pull requests that get merged will be made available under the MIT license, as the rest of the repository.

react-native-foldview's People

Contributors

errorpro avatar haroenv avatar jmurzy avatar juliaqiuxy avatar rajaishwary avatar rezof 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  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  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  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  avatar

react-native-foldview's Issues

Android?

On android the view doesn't fully unfold, and the animation it's more like a jump.
I wonder if it's an underlaying Animated issue?

PS. I'm only starting with RN 😄
rnfoldview

Thank you.

PropTypes are not part of React anymore

First of all: Awesome Work!

Your library isn't compatible to newer React-Versions, since PropTypes isn't part of React anymore.

You will need to import it directly now:

import PropTypes from 'prop-types';

3D doesn't work with react-native 0.44

Hi,
i've installed your lib in an app with rect-native 0.44 and it works, but the animations are all flat.
It's like the 3d effect doesn't work at all. I've even tried to install the 0.44 into your Simple project and i had the same result.
is there a way to fix it without rollback to previous react-native version?

Remote debug issue.

First let me say this is an excellent component.

After trying multiple ways of doing the same thing in react native without success, I realised was always working, however, because I had remote debugging on an error was thrown showed the error.

Error MEssage

" RCTJSONStringify() encountered the following error: Invalid number value (infinite) in JSON write"

If remote debugging is switched off then the component renders, any ideas fix etc?

I think the error is similar to this:

facebook/react-native#2616

ListView?

Hey!
Do you see any issue with using ListView over ScrollView? I was thinking about doing something similar with a much larger list and a only one or two flips instead of the three.

I ask because I am trying the example using ListView and it is doing some funky stuff and very slow.

Not sure if I have messed something up or there is a problem else.

Thanks

Invalid layout for (114)<RCTView:

Sorry to interrupt, can we fix this?

2017-01-23 09:48:24.028 [info][tid:com.facebook.react.JavaScript] Running application "Simple" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2017-01-23 09:48:24.311 [error][tid:main][UIView+React.m:152] Invalid layout for (114)<RCTView: 0x7f81e7c1cbf0; reactTag: 114; frame = (0 0; 0 0); layer = <CALayer: 0x608000038ca0>>. position: {280, nan}. bounds: {{0, 0}, {50, nan}}
2017-01-23 09:48:24.330 [error][tid:main][UIView+React.m:152] Invalid layout for (113)<RCTView: 0x7f81e7c1c980; reactTag: 113; frame = (0 0; 0 0); layer = <CALayer: 0x608000038c00>>. position: {152.5, nan}. bounds: {{0, 0}, {80, nan}}
2017-01-23 09:48:24.332 [error][tid:main][UIView+React.m:152] Invalid layout for (115)<RCTView: 0x7f81e7c1ce60; reactTag: 115; frame = (0 0; 0 0); layer = <CALayer: 0x608000038a60>>. position: {25, nan}. bounds: {{0, 0}, {50, nan}}

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.