9

我指的是官方文档的这个页面:https ://wix.github.io/react-native-navigation/#/screen-api?id=listen-to-visibility-events-globally

创建此类后,我如何告诉导航器使用它?

4

1 回答 1

4

ScreenVisibilityListener通过 react-native eventDispatcher 监听原生端触发的全局事件,导航器不需要知道。

示例用法:

import {ScreenVisibilityListener} from 'react-native-navigation';

new ScreenVisibilityListener({
  willAppear: ({screen}) => {
    console.log(`Displaying screen ${screen}`) 
  },
  didAppear: ({screen, startTime, endTime, commandType}) => {
    console.log('screenVisibility', `Screen ${screen} displayed in ${endTime - startTime} millis [${commandType}]`)
  },
  willDisappear: ({screen}) => {
    console.log(`Screen will disappear ${screen}`) 
  },
  didDisappear: ({screen}) => {
    console.log(`Screen disappeared ${screen}`)
  }
}).register();
于 2018-04-11T11:53:39.390 回答