解決辦法如下在入口的activity中加入以下代碼
手動強制讓rn reloadjs
private long lastTime = 0;
//監(jiān)聽鍵盤雙擊R事件
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
mReactInstanceManager.showDevOptionsDialog();
return true;
}
if(keyCode==46 && BuildConfig.DEBUG){ //press R
long currentTime = System.currentTimeMillis();
if(currentTime- lastTime < 300){
reloadJS();
}
lastTime =System.currentTimeMillis();
}
Log.e(TAG, "onKeyUp() called with: keyCode = [" + keyCode + "], event = [" + event + "]");
//log
return super.onKeyUp(keyCode, event);
}
//reload
private void reloadJS() {
Log.e(TAG, "reloadJS: " );
mReactInstanceManager.getDevSupportManager().handleReloadJS();
}