Giter Club home page Giter Club logo

react-native-restart's Introduction

On October 7th, 2023 Hamas terrorists launched a unilateral attack on Israel, brutally killing thousands of civilians, including infants and children, taking 240 hostages, and injuring thousands more.

MORE THAN 110 HOSTAGES REMAIN IN CAPTIVITY. BRING THEM HOME NOW! #BringThemHomeNow

React Native Restart

npm version npm downloads Build status

Sometimes you want to reload your app bundle during app runtime. This package will allow you to do it.

iOS GIF Android GIF

Installation

With yarn

$ yarn add react-native-restart

With npm

$ npm install --save react-native-restart

Auto-Linking Setup (react-native >= 0.60)

iOS

$ cd ios
$ pod install

Android

No further steps should be taken

Automatic Installation (Without Auto-Linking)

react-native link react-native-restart or npm install -g rnpm && rnpm link react-native-restart

Manual Android Installation

In android/settings.gradle

...

include ':react-native-restart'
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')

In android/app/build.gradle

...

dependencies {
    ...

    implementation project(':react-native-restart')
}

Register module (in MainApplication.java)

import com.reactnativerestart.RestartPackage;  // <--- Import

public class MainApplication extends Application implements ReactApplication {

	private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
  		......

	      /**
	     * A list of packages used by the app. If the app uses additional views
	     * or modules besides the default ones, add more packages here.
	     */
	    @Override
	    protected List<ReactPackage> getPackages() {
	        ...
	        return Arrays.<ReactPackage>asList(
	                new MainReactPackage(),
	                new RestartPackage() // Add this line
	        );
	    }
	};
	......
};

Manual iOS Installation

Importing The Library

  • Drag the file Restart.xcodeproj from /node_modules/react-native-restart/ios into the Libraries group in the Project navigator. Ensure that Copy items if needed is UNCHECKED!

Add Files To...

Library Imported Successfully

  • Ensure that libRestart.a is linked through Link Binary With Libraries on Build Phases:

Library Linked

  • Ensure that Header Search Paths on Build Settings has the path $(SRCROOT)/../node_modules/react-native-restart set to recursive:

  • You're All Set!

CocoaPod iOS Installation

In your ios/Podfile make sure to use react-native-restart from the local node_modules/. With that, only your project Pod needs to be linked and no extra configuration is required:

target 'MyReactApp' do
  # Make sure you're also using React-Native from ../node_modules
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'RCTActionSheet',
	# ... whatever else you use
  ]
  # React-Native dependencies such as yoga:
  pod 'yoga', path: '../node_modules/react-native/ReactCommon/yoga'

  # The following line uses react-native-restart, linking with
  # the library and setting the Header Search Paths for you
  pod 'react-native-restart', :path => '../node_modules/react-native-restart'
end

Remember to run cd ios && pod install to update files used by Xcode.

Usage

import RNRestart from 'react-native-restart'; // Import package from node modules

// Immediately reload the React Native Bundle
RNRestart.Restart(); // Deprecated
RNRestart.restart();

Contributing

Contributions are welcome. Please see CONTRIBUTING.md if you like to contribute to this library.

Credits

Thanks to Microsoft CodePush library. I simply extracted the code from their library's logic to reload the React Native Bundle.

react-native-restart's People

Contributors

allan-cornet-eove avatar avishayil avatar ayaahmed177 avatar azizghuloum avatar barbieri avatar barzhomi avatar burtonrodman avatar bweissbart avatar dependabot[bot] avatar freeboub avatar hammzahm avatar jasonalmaturner avatar jkomyno avatar kingdark1234 avatar l-x-c avatar lachenmayer avatar madsleejensen avatar mehthabux avatar mortezaalizadeh avatar newomble avatar o-verbeek avatar parndt avatar psiiirus avatar rafao avatar raphcayou avatar saeedzhiany avatar tikitdo avatar vanenshi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-restart's Issues

Help requested

Hello!

I'm trying to play with your react-native-restart with my Andorid hybrid app but having some issues. If you can help me narrow down to what I'm doing wrong that would be appreciated. Here's what I've:
RN 0.55.2. I've followed your instructions to install your npm module. Comparing to your example, the only difference is that I'm using ReactInstanceManager.instance() mechanism instead of implementing ReactApplication as called out on your example suggests.
When I call RNRestart.Restart() on a JS exception, I get TypeError: cannot read property 'Restart' of undefined. It seems like my JS file is unable to find react-native-restart but don't know where to look for. Thanks for the help.
-Rajesh.

RNRestart doesn't reset the RN states

Hello there.

Each time when RNRestart() is triggered, it does restart the app, but the app states are not reset.

So for example, if i got an error while login and after what i restarted the app, on next login app will freeze because something the state was not reset.

Is there any way to fix that?

Thanks.

No podspec found for `RCTRestart`

A fresh install on Xcode 9.4 and Cocoapods 1.5.3 using react-native-restart 0.0.6.

My ios/Podfile is like this

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'myApp' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for myApp
  pod 'Fabric'
  pod 'Firebase/Messaging'
  pod 'ReactNativeFabric', :path => '../node_modules/react-native-fabric'
  pod 'React', :path => '../node_modules/react-native', subspecs: [
    'Core',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket'
  ]
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'
  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
  pod 'RNImageCropPicker', :path =>  '../node_modules/react-native-image-crop-picker'
  pod 'RCTRestart', :path => '../node_modules/react-native-restart/ios'
  
end

Then I get the following error on a pod install while being in ios directory.

Fetching podspec for `RCTRestart` from `../node_modules/react-native-restart/ios`
[!] No podspec found for `RCTRestart` in `../node_modules/react-native-restart/ios`

And of course I checked that the module is in node_modules

Add typescript typings

It would be great if we could add simple typescript typings. Would you accept a PR? :)

RN 5.6.0

hi im on RN 5.6.0 it doesnt work
says undefined is not an object

I18nManager.forceRTL(!I18nManager.isRTL) does not affect on iOS at first restart [SOLVED]

Title is clear what the issue is, to reproduce the issue it's enough to add a button on screen and implement its onPress by this:

onPress={() => {
    I18nManager.allowRTL(!I18nManager.isRTL)
    I18nManager.forceRTL(!I18nManager.isRTL)
    RNRestart.Restart()
  }}

It works well on Android, but not on iOS (debug and release tested) (The logic behind this request is to implement RTL and LTR apps which works well on multi languages)

[Android] Restart() is Undefined

Hi,

I have been trying to get RNRestart.Restart(); to work for a while now. I have just recently noticed that the error stated that 'Restart is undefined.' The package seems to be imported just fine though (since it seems to recognise RNRestart), but somehow, I can't access Restart() nor getName().

I am new to React Native, and I properly have no idea what I am actually doing. I am using React Native version 0.37.0.

Thank you for your time.

old version of gradle has missing dependencies

Our build today failed with the following error:

FAILURE: Build failed with an exception.
  
* What went wrong:
A problem occurred configuring project ':react-native-restart'.
> Could not resolve all artifacts for configuration ':react-native-restart:classpath'.
   > Could not find com.android.tools:common:25.3.3.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/common/25.3.3/common-25.3.3.pom
         https://jcenter.bintray.com/com/android/tools/common/25.3.3/common-25.3.3.jar
     Required by:
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.build:manifest-merger:25.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.ddms:ddmlib:25.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.analytics-library:shared:25.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.analytics-library:tracker:25.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools:sdklib:25.3.3 > com.android.tools.layoutlib:layoutlib-api:25.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools:sdklib:25.3.3 > com.android.tools:dvlib:25.3.3
         project :react-native-restart > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools:sdklib:25.3.3 > com.android.tools:repository:25.3.3

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 36s

Upgrading to gradle 3.2.1 fixes the issue.
Will submit a PR soon.

Crash on android when restarting

Getting a crash on android, iOS works fine. Using RN version 0.55.4.
Having trouble fixing this. Any ideas?
Thanks

Logs:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.matific, PID: 28069
java.lang.RuntimeException: com.facebook.react.uimanager.IllegalViewOperationException: Trying to remove a view index above child count 1 view tag: 11
detail: View tag:-1
children(0): [
],
indicesToRemove(1): [
1,
],
tagsToDelete(1): [
670,
]

                                                             at com.facebook.react.bridge.ReactContext.handleException(ReactContext.java:311)
                                                             at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:23)
                                                             at android.os.Handler.handleCallback(Handler.java:751)
                                                             at android.os.Handler.dispatchMessage(Handler.java:95)
                                                             at android.os.Looper.loop(Looper.java:154)
                                                             at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
                                                          Caused by: com.facebook.react.uimanager.IllegalViewOperationException: Trying to remove a view index above child count 1 view tag: 11
                                                          detail: View tag:-1
                                                           children(0): [
                                                          ],
                                                           indicesToRemove(1): [
                                                         1,
                                                          ],
                                                           tagsToDelete(1): [
                                                         670,
                                                          ]
                                                         
                                                             at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:351)
                                                             at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:179)
                                                             at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:821)
                                                             at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:928)
                                                             at com.facebook.react.uimanager.UIViewOperationQueue.access$2100(UIViewOperationQueue.java:46)
                                                             at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded(UIViewOperationQueue.java:886)
                                                             at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:21)
                                                             	... 7 more

[Android] Restart() is Undefined

Same as the guy before. Restart function is not defined on react-native 0.36 for android. RNRestart is recognised but the Restart() function is not.

What info can I tell you to help you?

There is no issue

This is not an issue discussion.
I just want to say thank you for making this 👍. Have a nice day!

[Error] RNRestart. was called with 1 arguments but expects 0 arguments

Hey, found this repo today and it has proven to be great way to return from major unknown issues.
I am using RNRestart alongside react-native alert, i.e. error occurs and I show alert like this:

   Alert.alert(
      'Somethign went wrong',
      'It is taking more than usual to log in, try restarting the app',
      [{ text: 'Restar', onPress: () => RNRestart.Restart() }],
      { cancelable: false }
    );

This works fine 👍 so I tried to clean up the code and refactor onPress to

onPress: RNRestart.Restart

After making this change I am now getting error below:

RNRestart. was called with 1 arguments but expects 0 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.

This is not to big of a deal, but I'm curious to why it is not working? + this could confuse someone into thinking that library is not functioning properly.

144 MB size!!

Please remove build folder from ios example!
in this path:
node_modules/react-native-restart/Example/ios/build
Its size is 300 Mb!

Build with RN 0.58.3 and android SDK 28 fails

build release fails with RN 0.58.3 on android

ask :react-native-restart:verifyReleaseResources FAILED
Due to old compileSdkVersion and buildToolsVersion versions

fix:
replaces react-native-restart/android/build.gradle by attached file
build.gradle.zip

Standard way is to use rootProject.ext.compileSdkVersion and rootProject.ext.buildToolsVersion

iOS Deployment Target update needed

Would it be possible to update the iOS deployment target in ios/RCTRestart.xcodeproj/project.pbxproj from IPHONEOS_DEPLOYMENT_TARGET = 7.0 to IPHONEOS_DEPLOYMENT_TARGET = 8.0 as it is required for iOS 12 support.
Thank you

RCTFatalException: Exception '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array' was thrown

Works fine in Android, but on iOS we're getting:

Application threw exception RCTFatalException: Exception '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array' was thrown while invoking Restart on target RNRestart with params (
    "<null>"
)

I installed originally with react-native link. Then I added pods.

Both times I had the same error. Is the Importing The Library step required for iOS?

Cannot read property 'Restart' of undefined

Hi there,

I have the problem that when I try to use the library https://github.com/avishayil/react-native-restart and try to restart the app it isn't working.
I have it on stackoverflow as well because I wasn't sure if it is an issue or not.

I simply have the import and the function in a button to restart. Code:

import RNRestart from 'react-native-restart';

  restartApp() {
    // Immediately reload the React Native Bundle
    RNRestart.Restart();
  }

https://github.com/AlessandroVol23/Counter10000/blob/master/app/screens/ScreenOverview.js

It was suggested to add the imports to the index file as well but this hadn't changed anything.

image

Android build error

When trying to run gradleAssemble on a build i receive the following:

` Execution failed for task ':react-native-restart:verifyReleaseResources'.

java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/mcadmin/Desktop/MCGit/shopper/node_modules/react-native-restart/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
/Users/mcadmin/Desktop/MCGit/shopper/node_modules/react-native-restart/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
/Users/mcadmin/Desktop/MCGit/shopper/node_modules/react-native-restart/android/build/intermediates/res/merged/release/values/values.xml:2749: error: resource android:attr/fontVariationSettings not found.
/Users/mcadmin/Desktop/MCGit/shopper/node_modules/react-native-restart/android/build/intermediates/res/merged/release/values/values.xml:2750: error: resource android:attr/ttcIndex not found.
error: failed linking references. `

I've read elsewhere that opening react-native-restart > android > build.gradle and changing:

compileSdkVersion 27
buildToolsVersion "27.0.3"

but this has not resolved the issue

Android restarting doesn't affect forcing RTL

I am implementing a restart for the app to change the language and to switch the app view from Right to left or vice-versa.
that is my code here.

 if(this.state.firstItem && strings.getLanguage() === 'ar') {
        I18nManager.forceRTL(false)
        strings.setLanguage('en')
        console.log('language','en')
        AsyncStorage.setItem('@language:key','en');
    }else if(this.state.firstItem === false && strings.getLanguage() === 'en'){
         I18nManager.forceRTL(true)
        strings.setLanguage('ar')
        console.log('language','ar')
        AsyncStorage.setItem('@language:key','ar');
    }
    else {
        this.setState({ modalVisible: false});
        return ;
    }
    this.forceUpdate()
    RNRestart.Restart()
       //   RestartAndroid.restart()
  }

After restarting the app is in the other language but the Layout is not correct , I have to close the app and reopen it for the forcing Layout to take place.

Cannot read property Restart of undefined

I installed the latest version with npm, then linked it, running it resulted in: Cannot read property Restart of undefined. When I checked the header search path in XCode, it was set to non-recursive. Changing it to recursive fixed the issue.

macOS: 10.14
XCode: 10.1
react-native: 0.57.7

Error after update Android Repository

Building and installing the app on the device (cd android && ./gradlew installDebug...
File /Users/dev/.android/repositories.cfg could not be loaded.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugApk'.
A problem occurred configuring project ':react-native-restart'.
> Could not resolve all dependencies for configuration ':react-native-restart:_debugPublishCopy'.
> Could not find com.atlassian.mobile.video:okhttp-ws-compat:3.7.0-atlassian1.
Required by:
AuditChamber:react-native-restart:unspecified > com.facebook.react:react-native:0.42.3-atlassian-1

Please help

RNRestart.Restart() reloads the notification or universal link the app was originally opened with

I think a great feature would be the ability to restart without reloading the initial URL or push notification if the app was originally opened with either of those.

I'm using RNRestart when a user logs out, as an easy way to clear redux and all user data.

However, if the app was originally opened via push notification, the system shows that push again after reload.

It's also the case that if the app was opened via Universal link (iOS) or Deep link (Android), that initial URL is also reloaded. This isn't so much an issue in my case because the login screen prevents the app from routing elsewhere, but it could be an issue for other people.

/node_modules/react-native-restart: Appears to be a git repo or submodule

when i run

npm install 

with package.json

will show

npm ERR! path /Users/liuxiaocong/mutualFund/domestic-app/node_modules/react-native-restart
npm ERR! code EISGIT
npm ERR! git /Users/liuxiaocong/mutualFund/domestic-app/node_modules/react-native-restart: Appears to be a git repo or submodule.
npm ERR! git     /Users/liuxiaocong/mutualFund/domestic-app/node_modules/react-native-restart
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/liuxiaocong/.npm/_logs/2019-04-09T06_15_40_005Z-debug.log

Restarting app on iOS doesn't display splash screen

So I have a splash screen set up that is shown to the user upon starting the app. On android whenever the app is restarted the initial splash screen is shown. On iOS it only works when I actually start the app and not when calling RnRestart.Restart().
Is this expected behaviour on iOS or just an issue with my project?

Thank you for your time in advance

something went wrong while linking.

rnpm-link info Linking react-native-restart ios dependency
rnpm-link ERR! It seems something went wrong while linking.
Error: ENOENT: no such file or directory
,open 'C:\Users\MohamedSaeed\AwesomeProject\node_modules\react-native-restart\ios\RCTRestart.xcodeproj\project.pbxproj'

(node:3440) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): Error: ENOENT: no such file or directory, open 'C:\Users\MohamedSae
ed\AwesomeProject\node_modules\react-native-restart\ios\RCTRestart.xcodeproj\pro
ject.pbxproj'
(node:3440) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.

Podspec seems to be outdated

Hi,

I'm trying to build an iOS app using Podfile for managing react-native modules dependencies, but unfortunately, pod install return error that it wasn't able to find a branch

Installing RCTRestart 0.0.10

[!] Error installing RCTRestart
[!] /usr/local/bin/git clone git+https://github.com/avishayil/react-native-restart.git /var/folders/dj/7fqq1qld5nsdy4s32fcxpgch0000gn/T/d20190412-70857-ihgl6n --template= --single-branch --depth 1 --branch 0.0.10

Cloning into '/var/folders/dj/7fqq1qld5nsdy4s32fcxpgch0000gn/T/d20190412-70857-ihgl6n'...
warning: Could not find remote branch 0.0.10 to clone.
fatal: Remote branch 0.0.10 not found in upstream origin

I've inspected ios/RCTRestart.podspec file and it seems to be outdated, namely :

  1. :tag in source property contains only numbers and dots (for example 0.0.10), but all tags in a repository have a format like v0.0.10.
  2. the tag with name v0.0.10 doesn't exist, but last version of package.json has version 0.0.10
  3. Looks like several versions ago the folder structure of the project has changed and now after pod installation the pod folder is empty, i.e. source_files spec property is pointed to nowhere.

No view to update.

I am getting this when using RNRestart.Restart()
simulator screen shot feb 16 2017 12 50 02 pm

  • react-native-restart version 0.0.2
  • react-native version 0.40.0

Worked perfectly on react-native version 0.37.0

Restart application with initialProps

I want to know if it would be possible to pass parameters to know the status of the application. Example, the number of times that the application has been restarted.

Exemple:

RNRestart.Restart({
  restartCause: 'Lorem ipsum',
});

That would be great, thanks :)

RN-Windows Support

Do you have any interest in making this package compatible with UWP apps using react-native-windows?

Cannot read property 'Restart' of undefined

Hi there !

I am having some issues with using react-native-restart. I run into a "Cannot read property 'Restart' of undefined" error message when trying to restart my app on Android. I am unable to try on iOS at the moment.

My code is the following :

disconnect = () => {
    firebase.auth().signOut().then(() => RNRestart.Restart());
}

This function is called in an onPress event from a TouchableOpacity.
I checked in my MainActivity.Java file that the package was linked, and everything seems right (import and getPackages).

Is there anything I could do to fix this ?

Thanks !

Restart causes crashes on Android with error stack size 1038KB

RNRestart.Restart() works fine on IOS. But it crashes on Android.

screenshot_1540542312

Checking the log show error bellow

Exception in native call
java.lang.RuntimeException: Could not invoke RNRestart.Restart
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:154)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160) 
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29) 
at android.os.Looper.loop(Looper.java:154) 
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192) 
at java.lang.Thread.run(Thread.java:761) 
Caused by: java.lang.StackOverflowError: stack size 1038KB
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)
at com.testapp.MainApplication$1.getPackages(MainApplication.java:34)

Seems like the error stack size 1038KB is caused by a loop.

My versions:
react-native-cli: 2.0.1
react-native: 0.55.4

Restart doesn't make redux state reset ?

It seems after restart, the redux store is not reset to the initial state. I thought when reloading the whole bundle, the state should also be reset ?

When I had the error set to true in the state like bellow, an error screen is displayed with a REFRESH button, in which it call RNRestart.Restart:

state = {
  error: true
}

But after the restart, error is still true --- my error screen still appear :(

Redirect to specific screen after reset

Is possible reset and redirect to especific screen using react-navigation? If not, is possible add this feature?

Example:

RNRestart.Restart({
    screen: Favorites,
    restartParam: {
        param1: 'some param',
        param2: 'some param2'
    }
});

So, take this param on screen with this.props.navigation.getParam('restartParam'); or something like this...

Thanks.

Cannot read property Restart of undefined

When I install the dependency react-native-restart, I did the automatic installation via react-native link with successfully linked result.

Environment: macOs and iOS emulator

screen shot 2018-04-09 at 22 41 29

My usage is
import RNRestart from 'react-native-restart';

and then in one action I call
RNRestart.Restart();

but got error - 'Cannot read property Restart of undefined'

screen shot 2018-04-09 at 22 40 16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.