New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-focus

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-focus

Get iOS Focus status information in React Native

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 24 Apr 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc