Skip to content

Commit

Permalink
Add @nullable annotations to ViewUtils (#37877)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37877

# Changelog:
[Internal] -

A quick follow-up to #37851

There was a suggestion to add `Nullable` annotations, but the change had already landed at that point, so putting up another one.

Reviewed By: cortinico

Differential Revision: D46721095

fbshipit-source-id: 7361dec852160126c861ee2b22db240e586cc452
  • Loading branch information
rshest authored and facebook-github-bot committed Jun 14, 2023
1 parent de6bfec commit b3cc19c
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react.views.common;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.R;

/** Class containing static methods involving manipulations of Views */
Expand All @@ -19,9 +20,15 @@ public class ViewUtils {
* @param view View to get the testId value for
* @return the value of testId if defined for the view, otherwise null
*/
public static String getTestId(View view) {
return view.getTag(R.id.react_test_id) instanceof String
? (String) view.getTag(R.id.react_test_id)
: null;
public static @Nullable String getTestId(@Nullable View view) {
if (view == null) {
return null;
}
Object tag = view.getTag(R.id.react_test_id);
if (tag instanceof String) {
return (String) tag;
} else {
return null;
}
}
}

0 comments on commit b3cc19c

Please sign in to comment.