Socket
Socket
Sign inDemoInstall

react-native-focus

Package Overview
Dependencies
506
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-focus

Get iOS Focus status information in React Native


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
51.2 kB
Created
Weekly downloads
 

Readme

Source

react-native-focus

Get iOS Focus status information in React Native

This library only works on iOS. Running this library's code on Android will result in crashes.

Make sure you only run this code after you've verified the current platform is iOS.

Installation

npm install react-native-focus

or

yarn add react-native-focus

Linking

This package auto-links to your main Target. You need to create an Intent Extension to use the focus status listener.

Follow these instructions to get that setup.

Run pod install on your ios/ folder.

Setup

Open your app's Info.plist and add a NSFocusStatusUsageDescription key. The value should be a String describing to the user why your app needs permission to access the Focus Status.

To allow the focus status listener to work, refer to the Create Intents Extension README.

Usage

Refer to the Example Project for a simple usage of the library.

API

AuthorizationStatus

enum AuthorizationStatus {
  NotDetermined = 0,
  Restricted = 1,
  Denied = 2,
  Authorized = 3,
}

requestAuthorization()

Request the user for authorization to access the current focus status.

Returns

Promise<AuthorizationStatus> - The authorization status the user has chosen.

Example

import {requestAuthorization} from 'react-native-focus';

// ...

const status = await requestAuthorization();

getCurrentFocusStatus()

Get the current focus status.

Needs to have called requestAuthorization() and received AuthorizationStatus.Authorized, first.

This will not be updated when the focus status changes. You should use this for initialization only. Refer to the Create Intents Extension README.

Returns

boolean - Whether or not focus is currently enabled.

Example

import {getCurrentFocusStatus} from 'react-native-focus';

const isFocused = getCurrentFocusStatus();

addFocusStatusChangeListener(listener: (isFocused: boolean) => void)

Registers a listener that will get called whenever the focus status has changed.

Needs to have called requestAuthorization() and received AuthorizationStatus.Authorized, first.

Needs the Intents Extension to have been setup. Refer to the Create Intents Extension README.

Arguments

listener - The callback to call when focus status changes. Takes a boolean as an argument, with whether or not focus is enabled.

Returns

() => void - Callback to remove the the listener.

Example

import {addFocusStatusChangeListener} from 'react-native-focus';

const listener = (isFocused: boolean) => {
  console.log('Focus is:', isFocused ? 'Enabled' : 'Disabled');
};

const removeListener = addFocusStatusChangeListener(listener);

// When done with listener, or in clean-up.
removeListener();

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT License

Keywords

FAQs

Last updated on 24 Apr 2022

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