mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
add nullability annotation for DefaultStyleValuesUtil (#43980)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43980 add nullability annotation to DefaultStyleValuesUtil.java Changelog: [Internal] internal Reviewed By: cortinico Differential Revision: D55784913 fbshipit-source-id: f51b4a469f7fdcf59981675344995023cd8e6bec
This commit is contained in:
1 parent
37eca5d6cd
commit
f5f7ba0be0
1 file changed
+14
-1
+14
-1
@@ -11,8 +11,11 @@ import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
|
||||
/** Utility class that access default values from style */
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public final class DefaultStyleValuesUtil {
|
||||
|
||||
private DefaultStyleValuesUtil() {
|
||||
@@ -25,6 +28,7 @@ public final class DefaultStyleValuesUtil {
|
||||
* @param context The Context
|
||||
* @return The ColorStateList for the hint text as defined in the style
|
||||
*/
|
||||
@Nullable
|
||||
public static ColorStateList getDefaultTextColorHint(Context context) {
|
||||
return getDefaultTextAttribute(context, android.R.attr.textColorHint);
|
||||
}
|
||||
@@ -35,6 +39,7 @@ public final class DefaultStyleValuesUtil {
|
||||
* @param context The Context
|
||||
* @return The ColorStateList for the text as defined in the style
|
||||
*/
|
||||
@Nullable
|
||||
public static ColorStateList getDefaultTextColor(Context context) {
|
||||
return getDefaultTextAttribute(context, android.R.attr.textColor);
|
||||
}
|
||||
@@ -46,9 +51,17 @@ public final class DefaultStyleValuesUtil {
|
||||
* @return The int for the highlight color as defined in the style
|
||||
*/
|
||||
public static int getDefaultTextColorHighlight(Context context) {
|
||||
return getDefaultTextAttribute(context, android.R.attr.textColorHighlight).getDefaultColor();
|
||||
ColorStateList defaultTextAttribute =
|
||||
getDefaultTextAttribute(context, android.R.attr.textColorHighlight);
|
||||
if (defaultTextAttribute == null) {
|
||||
// it would be rare that the highlight color is not defined in the theme,
|
||||
// but if it is, return black
|
||||
return 0;
|
||||
}
|
||||
return defaultTextAttribute.getDefaultColor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ColorStateList getDefaultTextAttribute(Context context, int attribute) {
|
||||
Resources.Theme theme = context.getTheme();
|
||||
TypedArray textAppearances = null;
|
||||
|
||||
Reference in new issue
Block a user