Skip to content

Commit

Permalink
UIManagerJSInterface: Fix getConstantsForViewManager types
Browse files Browse the repository at this point in the history
Summary:
If Flow can be trusted, getConstantsForViewManager always gets called with a non-null string:
1. The only call-site to getConstantsForViewManager is getViewManagerConfig: [PaperUIManager.js](https://github.com/facebook/react-native/blob/822bf52c29729d25b2bfb31655cf773609a9283d/packages/react-native/Libraries/ReactNative/PaperUIManager.js#L36-L80)
2. And getViewManagerConfig always passes in a non-null string.

So, let's just make the native argument type a non-nullable string.

Thoughts?

Changelog: [Internal]

Differential Revision: https://internalfb.com/D52628937

fbshipit-source-id: 52caff31eea7b6d72dd8ec0f0c40d897f43cb14f
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 20, 2024
1 parent 59ab740 commit 4966e96
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getUIManagerConstantsCached = (function () {
};
})();

const getConstantsForViewManager: ?(viewManagerName: string) => Object =
const getConstantsForViewManager: ?(viewManagerName: string) => ?Object =
global.RN$LegacyInterop_UIManager_getConstantsForViewManager;

const getDefaultEventTypes: ?() => Object =
Expand Down Expand Up @@ -157,7 +157,7 @@ const UIManagerJSUnusedAPIs = {

const UIManagerJSPlatformAPIs = Platform.select({
android: {
getConstantsForViewManager: (viewManagerName: string): Object => {
getConstantsForViewManager: (viewManagerName: string): ?Object => {
if (getConstantsForViewManager) {
return getConstantsForViewManager(viewManagerName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface Spec extends TurboModule {
) => void;

// Android only
+getConstantsForViewManager?: (viewManagerName: string) => Object;
+getConstantsForViewManager?: (viewManagerName: string) => ?Object;
+getDefaultEventTypes?: () => Array<string>;
+setLayoutAnimationEnabledExperimental?: (enabled: boolean) => void;
+sendAccessibilityEvent?: (reactTag: number, eventType: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7857,7 +7857,7 @@ exports[`public API should not change unintentionally Libraries/ReactNative/Nati
addAtIndices: Array<number>,
removeAtIndices: Array<number>
) => void;
+getConstantsForViewManager?: (viewManagerName: string) => Object;
+getConstantsForViewManager?: (viewManagerName: string) => ?Object;
+getDefaultEventTypes?: () => Array<string>;
+setLayoutAnimationEnabledExperimental?: (enabled: boolean) => void;
+sendAccessibilityEvent?: (reactTag: number, eventType: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,8 @@ public static Map<String, Object> createConstants(
}

@ReactMethod(isBlockingSynchronousMethod = true)
public @Nullable WritableMap getConstantsForViewManager(@Nullable String viewManagerName) {
ViewManager targetView =
viewManagerName != null ? mUIImplementation.resolveViewManager(viewManagerName) : null;
public @Nullable WritableMap getConstantsForViewManager(String viewManagerName) {
ViewManager targetView = mUIImplementation.resolveViewManager(viewManagerName);
if (targetView == null) {
return null;
}
Expand Down

0 comments on commit 4966e96

Please sign in to comment.