有时会用到APP重启操作,比如更新代码或者特殊情况的用户注销。
0.62及以上版本只重启JS部分。
import {DevSettings} from 'react-native';
DevSettings.reload();
详细请参阅:https://reactnative.dev/docs/devsettings#reload
这种方法应该只对开发模式有用(从名称上猜测,未实测)。
react-native-restartnpm install --save react-native-restart
import RNRestart from 'react-native-restart'; // Import package from node modules
// Immediately reload the React Native Bundle
RNRestart.Restart();
实测发布版本也可以重启