npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-focus

v1.2.0

Published

Get iOS Focus status information in React Native

Downloads

12

Readme

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