Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a global ScreenVisibilityListener class?

I'm referring to this page of the official doc: https://wix.github.io/react-native-navigation/#/screen-api?id=listen-to-visibility-events-globally

After I create this class, how I tell navigator to use it?

like image 943
realtebo Avatar asked Mar 08 '18 10:03

realtebo


People also ask

What is FindViewById Android studio?

FindViewById(Int32) Finds a view that was identified by the android:id XML attribute that was processed in #onCreate . FindViewById<T>(Int32) Finds a view that was identified by the id attribute from the XML layout resource.

What is view in Android with example?

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of other views (child views) and other ViewGroup.


1 Answers

ScreenVisibilityListener listens to global events fired on the native side through react-native eventDispatcher, the navigator doesn't need to know about it.

Example usage:

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();
like image 78
yogevbd Avatar answered Oct 25 '22 01:10

yogevbd