Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
react-native-focus
Advanced tools
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.
npm install react-native-focus
or
yarn add react-native-focus
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.
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.
Refer to the Example Project for a simple usage of the library.
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();
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT License
FAQs
Get iOS Focus status information in React Native
We found that react-native-focus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.