react-native-turbo-restart
v1.0.0
Published
TurboModule for restarting React Native apps (New Architecture)
Maintainers
Readme
react-native-turbo-restart
🔄 TurboModule for restarting React Native apps with New Architecture support.
Why this package?
The popular react-native-restart package hasn't been updated in 3+ years and has issues with RN 0.77+. This package provides a modern alternative built for New Architecture.
Features
- ✅ New Architecture ready (TurboModules)
- ✅ Works with React Native 0.76+
- ✅ TypeScript support
- ✅ Simple API
- ✅ iOS & Android support
Installation
npm install react-native-turbo-restart
# or
yarn add react-native-turbo-restartiOS
cd ios && pod installAndroid
No additional steps required. The package auto-links.
Requirements
| Requirement | Version | |-------------|---------| | React Native | >= 0.76.0 | | iOS | >= 13.4 | | Android | >= API 23 |
⚠️ This package is designed for New Architecture. For Old Architecture, consider using
react-native-restart(though it may have compatibility issues with newer RN versions).
Usage
import { TurboRestart } from 'react-native-turbo-restart';
// Restart the app
TurboRestart.restart();Example: Restart after language change
import { TurboRestart } from 'react-native-turbo-restart';
import AsyncStorage from '@react-native-async-storage/async-storage';
const changeLanguage = async (newLanguage: string) => {
await AsyncStorage.setItem('language', newLanguage);
TurboRestart.restart();
};Example: Restart button
import React from 'react';
import { Button } from 'react-native';
import { TurboRestart } from 'react-native-turbo-restart';
export const RestartButton = () => (
<Button
title="Restart App"
onPress={() => TurboRestart.restart()}
/>
);How it works
iOS
Uses RCTTriggerReloadCommandListeners to trigger a JavaScript bundle reload.
Android
Recreates the main activity using Intent.makeRestartActivityTask() and exits the process.
API Reference
TurboRestart.restart()
Restarts the React Native application.
- iOS: Triggers a reload of the JavaScript bundle
- Android: Recreates the main activity, effectively restarting the app
Returns: void
Troubleshooting
iOS: App doesn't restart in release mode
Make sure you're using React Native 0.76+ with New Architecture enabled.
Android: App crashes on restart
Ensure your MainActivity has the correct launch mode in AndroidManifest.xml:
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
...
/>Migration from react-native-restart
- import RNRestart from 'react-native-restart';
+ import { TurboRestart } from 'react-native-turbo-restart';
- RNRestart.restart();
+ TurboRestart.restart();Contributing
Contributions are welcome! Please read our contributing guidelines first.
License
MIT © Krzysztof Kabala
