Skip to content

An AppEventListenerEnhance for React Native app which provides addEventListener functions that are safely cleaned up when the component unmounts

License

Notifications You must be signed in to change notification settings

react-native-component/react-native-smart-app-event-listener-enhance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-smart-app-event-listener-enhance

npm npm npm npm

A AppEventListenerEnhance for React Native app which provides addEventListener functions that are safely cleaned up when the component unmounts

Installation

npm install react-native-smart-app-event-listener-enhance --save

Full Demo

see ReactNativeComponentDemos

Usage

Install the AppEventListenerEnhance from npm with npm install react-native-smart-app-event-listener-enhance --save. Then, require it from your app's JavaScript files with import AppEventListenerEnhance from 'react-native-smart-app-event-listener-enhance'.

import React, {
    Component,
} from 'react'

import AppEventListenerEnhance from 'react-native-smart-app-event-listener-enhance'

class AppEventListenerEnhanceDemo extends Component {

    componentDidMount() {
        //you can use like this
        //this.addAppEventListener(
        //    this.props.navigator.navigationContext.addListener('didfocus', this._didFocus)
        //).addAppEventListener(
        //    this.props.navigator.navigationContext.addListener('didfocus', this._didFocus)
        //)

        //or you can use like this
        //this.addAppEventListener(
        //    this.props.navigator.navigationContext.addListener('didfocus', this._didFocus),
        //    this.props.navigator.navigationContext.addListener('didfocus', this._didFocus)
        //)

        this.addAppEventListener(
            this.props.navigator.navigationContext.addListener('didfocus', this._didFocus)
        )
    }

    render() {
        return null
    }

    _didFocus = () => {
        console.log(`didfocus`)
    }
}

export default AppEventListenerEnhance(AppEventListenerEnhanceDemo)

About

An AppEventListenerEnhance for React Native app which provides addEventListener functions that are safely cleaned up when the component unmounts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published