Coder Social home page Coder Social logo

corelogicllc / react-native-user-inactivity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blah2014/react-native-user-inactivity

0.0 3.0 0.0 131 KB

Simple component that alerts when the user is inactive (i.e. when the App surface hasn't been touched for X ms)

License: MIT License

JavaScript 36.93% Python 14.60% Java 11.13% Objective-C 37.34%

react-native-user-inactivity's Introduction

react-native-user-inactivity

Simple component that alerts when the user is inactive (i.e. when the App surface hasn't been touched for X ms).

Installation

  • with npm:
npm install --save react-native-user-inactivity
  • with yarn
yarn add react-native-user-inactivity

How to import

import UserInactivity from 'react-native-user-inactivity';

Basic Example

import React, { Component } from 'react';
import { Text } from 'react-native';
import UserInactivity from 'react-native-user-inactivity';

export default class App extends Component {

  state = {
    timeWentInactive: null,
  };

  onInactivity = (timeWentInactive) => {
    this.setState({
      timeWentInactive,
    });
  }

  render() {
    const { timeWentInactive } = this.state;
    return (
      <UserInactivity
        timeForInactivity={5000}
        checkInterval={1000}
        onInactivity={this.onInactivity}
      >
        <Text style={styles.paragraph}>
          Put your app here
          {timeWentInactive &&
            ` (inactive at: ${timeWentInactive})`}
        </Text>
      </UserInactivity>
    );
  }
}

Also, please checkout the Example directory and run the application (react-native run-android or react-native run-ios).

Props

The time is expressed in milliseconds (ms).

Prop Type Explanation Required Default Value
timeForInactivity number Inactivity time threshold no 10000
checkInterval number How often should we check inactivity no 2000
onInactivity function Callback for when the user becomes inactive yes -
style style The style of the wrapper no { flex: 1 }
children React Nested react nodes to wrap yes -

Issues

It seems that onPress events aren't captured by this library's PanResponder yet.

Contributing

Of course PRs are welcome!

react-native-user-inactivity's People

Contributors

jkomyno avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.