• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jmurzy/react-native-foldview: FoldView implemented in JavaScript ⛱

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

jmurzy/react-native-foldview

开源软件地址:

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

开源编程语言:

JavaScript 100.0%

开源软件介绍:

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap