微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 如何使用InteractionManager.runAfterInteractions使导航器转换更快

由于逻辑复杂,我必须在this.props.navigator.push(),慢导航器转换使应用程序不可用时渲染许多组件.

然后我注意到here提供了InteractionManager.runAfterInteractions api来解决这个问题,

我需要在导航器动画完成后将大部分消耗很长时间的组件带回来,但我不知道我应该在哪里调用它,

也许一个简单的例子就足够了,

谢谢你的时间.

解决方法

以下是高性能 Navigator场景的完整示例:
import {Component} from 'react';
import {InteractionManager,Text} from 'react-native';

class OptimizedScene extends Component {

  state = {interactionsComplete: false};

  componentDidMount() {
    InteractionManager.runAfterInteractions(() => {
      this.setState({interactionsComplete: true});
    });
  }

  render() {
    if (!this.state.interactionsComplete) {
      return <Text>loading...</Text>;
    }

    return (
      <ExpensiveComponent/>
    );
  }
}

这已被提取a library以使其更容易:

import {AfterInteractions} from 'react-native-interactions';

function MyScene() {
  return (
    <AfterInteractions placeholder={<CheapPlaceholder/>}>
      <ExpensiveComponent/>
    </AfterInteractions>
  );
}

原文地址:https://www.jb51.cc/iOS/333123.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐