Skip to content

Commit

Permalink
Return null when requesting constants for nonexistent View Managers i…
Browse files Browse the repository at this point in the history
…n RN Android

Summary:
This diff changes the behavior of UIImplementation.resolveViewManager() to return null instead of throwing an exception when trying to find an unexistent viewManager during the computation of constants for view Managers.

The C++/JS code manages exceptions and null results when a view manager doesn't exists, this diff simplifies the way this method operates.

changeLog: [internal]

Reviewed By: rickhanlonii

Differential Revision: D19624423

fbshipit-source-id: df31dcfae9a588bf325b61d529cec6ead59fb19d
  • Loading branch information
mdvacca authored and facebook-github-bot committed Feb 1, 2020
1 parent d3b2ac3 commit e4194a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public final ReactShadowNode resolveShadowNode(int reactTag) {
return mShadowNodeRegistry.getNode(reactTag);
}

protected final ViewManager resolveViewManager(String className) {
return mViewManagers.get(className);
protected final @Nullable ViewManager resolveViewManager(String className) {
return mViewManagers.getViewManagerIfExists(className);
}

/*package*/ UIViewOperationQueue getUIViewOperationQueue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,49 @@ public ViewManagerRegistry(Map<String, ViewManager> viewManagerMap) {
mViewManagerResolver = null;
}

/**
* @param className {@link String} that identifies the {@link ViewManager} inside the {@link
* ViewManagerRegistry}. This methods {@throws IllegalViewOperationException} if there is no
* view manager registered for the className received as a parameter.
* @return the {@link ViewManager} registered to the className received as a parameter
*/
public ViewManager get(String className) {
ViewManager viewManager = mViewManagers.get(className);
if (viewManager != null) {
return viewManager;
}
if (mViewManagerResolver != null) {
viewManager = mViewManagerResolver.getViewManager(className);
if (viewManager != null) {
mViewManagers.put(className, viewManager);
return viewManager;
}
viewManager = getViewManagerFromResolver(className);
if (viewManager != null) return viewManager;
throw new IllegalViewOperationException("ViewManagerResolver returned null for " + className);
}
throw new IllegalViewOperationException("No ViewManager found for class " + className);
}

private @Nullable ViewManager getViewManagerFromResolver(String className) {
@Nullable ViewManager viewManager;
viewManager = mViewManagerResolver.getViewManager(className);
if (viewManager != null) {
mViewManagers.put(className, viewManager);
}
return viewManager;
}

/**
* @param className {@link String} that identifies the {@link ViewManager} inside the {@link
* ViewManagerRegistry}.
* @return the {@link ViewManager} registered to the className received as a parameter or null if
* there is no ViewManager associated to the className received as a parameter.
*/
@Nullable
ViewManager getViewManagerIfExists(String className) {
ViewManager viewManager = mViewManagers.get(className);
if (viewManager != null) {
return viewManager;
}
if (mViewManagerResolver != null) {
return getViewManagerFromResolver(className);
}
return null;
}
}

0 comments on commit e4194a2

Please sign in to comment.