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]

Reviewed By: sammy-SC

Differential Revision: D52628937

fbshipit-source-id: 0ca68b38253cf134af29974af9e36380d66895a1
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 26, 2024
1 parent 4636029 commit d11dca7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 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 @@ -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
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

0 comments on commit d11dca7

Please sign in to comment.