Skip to content

visheshtgupta/rnt-keep-awake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();
  };
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published