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>
  );
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...