Skip to content

Commit

Permalink
Add reloadWithReason to DevSettings
Browse files Browse the repository at this point in the history
Summary:
This diff adds reloadWithReason to the NativeDevSettings and updates the exposed DevSettings.reload method to send to it if it's available (setting an 'uncategorized' reason if one isn't set.

[General][Feature] Update DevSettings.reload to accept a reason

Reviewed By: RSNara

Differential Revision: D17499343

fbshipit-source-id: e8c9724800f93d3b9a5d2a8fe9f689d51947d39b
  • Loading branch information
rickhanlonii authored and facebook-github-bot committed Sep 30, 2019
1 parent 2ccc8fb commit 549cac6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ + (RCTManagedPointer *)JS_NativeAsyncStorage_SpecGetAllKeysCallbackError:(id)jso
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "reload", @selector(reload), args, count);
}

static facebook::jsi::Value __hostFunction_NativeDevSettingsSpecJSI_reloadWithReason(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "reloadWithReason", @selector(reloadWithReason:), args, count);
}

static facebook::jsi::Value __hostFunction_NativeDevSettingsSpecJSI_setHotLoadingEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "setHotLoadingEnabled", @selector(setHotLoadingEnabled:), args, count);
}
Expand Down Expand Up @@ -816,6 +820,9 @@ + (RCTManagedPointer *)JS_NativeAsyncStorage_SpecGetAllKeysCallbackError:(id)jso
methodMap_["reload"] = MethodMetadata {0, __hostFunction_NativeDevSettingsSpecJSI_reload};


methodMap_["reloadWithReason"] = MethodMetadata {1, __hostFunction_NativeDevSettingsSpecJSI_reloadWithReason};


methodMap_["setHotLoadingEnabled"] = MethodMetadata {1, __hostFunction_NativeDevSettingsSpecJSI_setHotLoadingEnabled};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ namespace facebook {
@protocol NativeDevSettingsSpec <RCTBridgeModule, RCTTurboModule>

- (void)reload;
- (void)reloadWithReason:(NSString *)reason;
- (void)setHotLoadingEnabled:(BOOL)isHotLoadingEnabled;
- (void)setIsDebuggingRemotely:(BOOL)isDebuggingRemotelyEnabled;
- (void)setProfilingEnabled:(BOOL)isProfilingEnabled;
Expand Down
1 change: 1 addition & 0 deletions Libraries/NativeModules/specs/NativeDevSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';

export interface Spec extends TurboModule {
+reload: () => void;
+reloadWithReason?: (reason: string) => void;
+setHotLoadingEnabled: (isHotLoadingEnabled: boolean) => void;
+setIsDebuggingRemotely: (isDebuggingRemotelyEnabled: boolean) => void;
+setProfilingEnabled: (isProfilingEnabled: boolean) => void;
Expand Down
11 changes: 9 additions & 2 deletions Libraries/Utilities/DevSettings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

Expand Down Expand Up @@ -36,8 +39,12 @@ class DevSettings extends NativeEventEmitter {
});
}

reload() {
NativeDevSettings.reload();
reload(reason: string) {
if (typeof NativeDevSettings.reloadWithReason === 'function') {
NativeDevSettings.reloadWithReason(reason || 'Uncategorized from JS');
} else {
NativeDevSettings.reload();
}
}

// TODO: Add other dev setting methods exposed by the native module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public void run() {
}
}

@ReactMethod
public void reloadWithReason(String reason) {
this.reload();
}

@ReactMethod
public void setHotLoadingEnabled(boolean isHotLoadingEnabled) {
mDevSupportManager.setHotModuleReplacementEnabled(isHotLoadingEnabled);
Expand Down

0 comments on commit 549cac6

Please sign in to comment.