rtn-keepawake

1.0.3 • Public • Published

React Native Keep Awake

This React Native package allows you to prevent the screen from going to sleep while your app is active. It's useful for things like navigation or video playback, where the user expects the app to remain visible over long periods without touch interaction.

Based on New RN Arch (Also Supports Old Arch)

Installation

Using yarn

yarn add rtn-keepawake

For Ios cd ios && pod install && cd ..

Usage

example: hooks

import { useKeepAwake } from 'rtn-keepawake';
import React from 'react';
import { Text, View } from 'react-native';
export default function KeepAwakeExample {
  useKeepAwake();
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>This screen will never sleep!</Text>
    </View>
  );
}

example: components

import KeepAwake from 'rtn-keepawake';
import React from 'react';
import { Text, View } from 'react-native';
export default function KeepAwakeExample {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <KeepAwake />
      <Text>This screen will never sleep!</Text>
    </View>
  );
}

example: functions

import { activateKeepAwake, deactivateKeepAwake } from "rtn-keepawake";
import React from "react";
import { Button, View } from "react-native";
export default class KeepAwakeExample extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
        <Button onPress={this._activate}>Activate</Button>
        <Button onPress={this._deactivate}>Deactivate</Button>
      </View>
    );
  }
  _activate = () => {
    activateKeepAwake();
  };
  _deactivate = () => {
    deactivateKeepAwake();
  };
}

Package Sidebar

Install

npm i rtn-keepawake

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

8.87 kB

Total Files

10

Last publish

Collaborators

  • vishesht