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.
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.
react-native-restart https://github.com/avishayil/react-native-restart not working in this case.
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.