react-native-autostarter
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

react-native-autostarter

This is a wrapper of Autostarter

Getting started

$ npm install react-native-autostarter --save

or

$ yarn add react-native-autostarter

Mostly automatic installation

$ react-native link react-native-autostarter

Usage

Basic usage

import Autostarter from "react-native-autostarter";
 
// check if the device model is available on the autostart permissions
Autostarter.isAutoStartPermissionAvailable().then(isAvailable => {
  Autostarter.getAutoStartPermission();
});

Or, you can display a fallback screen or overlay if auto-start permission is not available.

import React, { useCallback, useEffect, useState } from "react";
import { Button, FlatList, Text, View } from "react-native";
import Autostarter from "react-native-autostarter";
 
const AutoStarterOverlay = () => {
  const onPress = useCallback(() => {
    Autostarter.getAutoStartPermission();
  }, []);
 
  return (
    <View>
      <Text>
        To receive push notification, please remove it from battery optimization
      </Text>
      <Button onPress={onPress}>Enable</Button>
    </View>
  );
};
 
const MyApp = () => {
  const [autoStartPermission, setAutoStartPermission] = useState(false);
 
  useEffect(() => {
    Autostarter.isAutoStartPermissionAvailable().then(isAvailable => {
      setAutoStartPermission(isAvailable);
    });
  }, []);
 
  return (
      <View>
        {autoStartPermission ? <AutoStarterOverlay /> : null}
 
        <Text>Lorem Ipsum</Text>
      </View>
  );
};

Running the example

  1. cd example
  2. yarn
  3. react-native run-android

License

react-native-autostarter is MIT licensed, as found in the LICENSE file.

Readme

Keywords

Package Sidebar

Install

npm i react-native-autostarter

Weekly Downloads

3

Version

1.0.5

License

MIT

Unpacked Size

78.1 kB

Total Files

16

Last publish

Collaborators

  • karlmarxlopez