Socket
Socket
Sign inDemoInstall

react-native-app-state

Package Overview
Dependencies
626
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-app-state

A declarative way to use react-native's AppState


Version published
Weekly downloads
15
increased by36.36%
Maintainers
1
Install size
197 kB
Created
Weekly downloads
 

Readme

Source

react-native-app-state

npm version

react-native-app-state is a declarative way to use react-native's AppState. Internally it uses the new React 16.3 Context API.

react-native-app-state

I think you got it. It's definitely easier than:

react-native-app-state

Getting started

Requirements

Because this library uses the new React 16.3 Context API, you need at least React 16.3.

Installation

$ yarn add react-native-app-state

npm

$ npm install react-native-app-state --save

Usage

See the example project under example/

import AppState from 'react-native-app-state';

class App extends React.PureComponent {
  onAppStateChange = (appState, prevAppState) => {
    console.log(this.constructor.name, 'onAppStateChange()', prevAppState, '=>', appState);
    // E.g. output: "App onAppStateChange() background => active"
  };

  render() {
    return (
      <View>
        <AppState onChange={this.onAppStateChange}>
          {({ appState }) => (
            <View>
              <Text style={styles.text}>App state: {appState}</Text>
            </View>
          )}
        </AppState>
        {/* ------ OR ------ */}
        <AppState onChange={this.onAppStateChange}>
          <AppState.Active>
            <Text>App is active</Text>
          </AppState.Active>
          <AppState.Inactive>
            <Text>App is inactive</Text>
          </AppState.Inactive>
          <AppState.Background>
            <Text>App is in background</Text>
          </AppState.Background>
        </AppState>
      </View>
    );
  }
}

ToDO

  • Write tests
  • Add/Replace example with expo
  • Add usage examples
    • component based <AppState.Active>, <AppState.Inactive>, <AppState.Background>
    • <AppState.Foreground> alias for <AppState.Active> and <AppState.Inactive>
    • with render prop <AppState>{({ appState }) => (<View />)}</AppState>

Keywords

FAQs

Last updated on 01 Dec 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc