
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-native-invoke-app
Advanced tools
Headless JS is a way to run background tasks in a React Native app. Sometimes we may want to open the app from background task (Headless JS). You can use this module to bring your app to foreground in all the following three cases.
$ npm install --save react-native-invoke-app
# if your react-native version is <0.60
$ react-native link react-native-invoke-app
import invokeApp from 'react-native-invoke-app';
// Within your headless function
invokeApp();
You can pass an object to invokeApp method to pick it from DeviceEventEmitter by listening to appInvoked event.
Example:
const yourObject = { route: 'Dashboard' };
invokeApp({
data: yourObject,
})
Let's say you want to navigate to dashboard screen of the app after a specific task is completed. You can acheive it like,
import React, { Component } from 'react';
import { AppRegistry, DeviceEventEmitter, Text, View } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import invokeApp from 'react-native-invoke-app';
import Dashboard from './dashboard';
class App extends Component {
componentWillMount() {
DeviceEventEmitter.addListener('appInvoked', (data) => {
const { route } = data;
// Using react-navigation library for navigation.
this.props.navigation.navigate(route);
});
}
render() {
return (
<View>
<Text>
This is Home screen.
</Text>
</View>
)
}
}
const appStack = () => {
const Stack = createStackNavigator({
App,
Dashboard,
});
return <Stack />
}
const notificationActionHandler = async (data) => {
// Your background task
const yourObject = { route: 'Dashboard' };
invokeApp({
data: yourObject,
})
}
AppRegistry.registerHeadlessTask(
'RNPushNotificationActionHandlerTask', () => notificationActionHandler,
);
AppRegistry.registerComponent('testProject', () => appStack);
Event listener will work fine when your app is in background or foreground. If it is not running, to capture the first event we need to do some extra work. Make the following changes in your MainActivity.java file of React Native app,
package com.yourpackage;
+import android.os.Bundle;
import com.facebook.react.ReactActivity;
+import com.codegulp.invokeapp.RNInvokeApp;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "testProject";
}
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ RNInvokeApp.sendEvent();
+ }
}
MIT
FAQs
Bring React Native App to foreground from Headless JS
The npm package react-native-invoke-app receives a total of 106 weekly downloads. As such, react-native-invoke-app popularity was classified as not popular.
We found that react-native-invoke-app 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.