React-native: Reload app from js

Created on 30 Apr 2015  路  6Comments  路  Source: facebook/react-native

I'm currently testing push notifications so I need physical access to the device. Is there a way to reload (like cmd-r in the simulator) from a custom button call? I know you can shake the device to open the developer menu, but that's a bit cumbersome for every time I want to refresh.

Ideally I would like to add a button in my navbar to reload the application after JS changes.

Locked

Most helpful comment

Is there also a way to reload the app in production? I have a very specific case in which I need to reload the whole app.

All 6 comments

We don't have a way to do this currently, but you could add a method to a native module to do this. It would look like this:

RCT_EXPORT_METHOD(reloadBridge)
{
  [self.bridge reload];
}

I've just added a way to do this in the latest internal build. I'll give you more details once it's shipped.

I'm using this atm:

--- ReactDevModule.m ---
#import "RCTBridgeModule.h"
#import "RCTBridge.h"

@interface ReactDevModule : NSObject <RCTBridgeModule>
@end

@implementation ReactDevModule

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(reloadBridge)
{
  [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil userInfo:nil];
}
@end

Then in JavaScript:

var {
  NativeModules
} = React;

....
NativeModules.ReactDevModule.reloadBridge();
....

This should now be possible in the latest version by using:

NativeModules.DevMenu.reload();

Is there also a way to reload the app in production? I have a very specific case in which I need to reload the whole app.

same as @flavordaaave , I also need re-render the whole app after language loaded from server( by http request)

I am using react-native-i18n https://github.com/AlexanderZaytsev/react-native-i18n to do multi language support.

I have tried

I am Using RN 0.52 develop for Android

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grabbou picture grabbou  路  3Comments

madwed picture madwed  路  3Comments

DreySkee picture DreySkee  路  3Comments

phongyewtong picture phongyewtong  路  3Comments

jlongster picture jlongster  路  3Comments