mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate Nullable and NonNull annotations to AndroidX
Summary: This diff migrates the usages Nullable and NonNull annotations to AndroidX instead of javax. The purpose of this change is to bring consistency in the annotations used by the core of RN Reviewed By: makovkastar Differential Revision: D16054504 fbshipit-source-id: 21d888854da088d2a14615a90d4dc058e5286b91
This commit is contained in:
committed by
Facebook Github Bot
parent
96318e438f
commit
aa5edca0e2
@@ -9,6 +9,8 @@ import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import com.facebook.react.R;
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
@@ -24,8 +26,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Base class that should be suitable for the majority of subclasses of {@link ViewManager}. It
|
||||
@@ -85,12 +85,12 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
private static final String STATE_MIXED = "mixed";
|
||||
|
||||
@ReactProp(name = PROP_BACKGROUND_COLOR, defaultInt = Color.TRANSPARENT, customType = "Color")
|
||||
public void setBackgroundColor(@Nonnull T view, int backgroundColor) {
|
||||
public void setBackgroundColor(@NonNull T view, int backgroundColor) {
|
||||
view.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_TRANSFORM)
|
||||
public void setTransform(@Nonnull T view, @Nullable ReadableArray matrix) {
|
||||
public void setTransform(@NonNull T view, @Nullable ReadableArray matrix) {
|
||||
if (matrix == null) {
|
||||
resetTransformProperty(view);
|
||||
} else {
|
||||
@@ -99,17 +99,17 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
|
||||
@ReactProp(name = ViewProps.OPACITY, defaultFloat = 1.f)
|
||||
public void setOpacity(@Nonnull T view, float opacity) {
|
||||
public void setOpacity(@NonNull T view, float opacity) {
|
||||
view.setAlpha(opacity);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ELEVATION)
|
||||
public void setElevation(@Nonnull T view, float elevation) {
|
||||
public void setElevation(@NonNull T view, float elevation) {
|
||||
ViewCompat.setElevation(view, PixelUtil.toPixelFromDIP(elevation));
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_Z_INDEX)
|
||||
public void setZIndex(@Nonnull T view, float zIndex) {
|
||||
public void setZIndex(@NonNull T view, float zIndex) {
|
||||
int integerZIndex = Math.round(zIndex);
|
||||
ViewGroupManager.setViewZIndex(view, integerZIndex);
|
||||
ViewParent parent = view.getParent();
|
||||
@@ -119,12 +119,12 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_RENDER_TO_HARDWARE_TEXTURE)
|
||||
public void setRenderToHardwareTexture(@Nonnull T view, boolean useHWTexture) {
|
||||
public void setRenderToHardwareTexture(@NonNull T view, boolean useHWTexture) {
|
||||
view.setLayerType(useHWTexture ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_TEST_ID)
|
||||
public void setTestId(@Nonnull T view, String testId) {
|
||||
public void setTestId(@NonNull T view, String testId) {
|
||||
view.setTag(R.id.react_test_id, testId);
|
||||
|
||||
// temporarily set the tag and keyed tags to avoid end to end test regressions
|
||||
@@ -132,25 +132,25 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_NATIVE_ID)
|
||||
public void setNativeId(@Nonnull T view, String nativeId) {
|
||||
public void setNativeId(@NonNull T view, String nativeId) {
|
||||
view.setTag(R.id.view_tag_native_id, nativeId);
|
||||
ReactFindViewUtil.notifyViewRendered(view);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ACCESSIBILITY_LABEL)
|
||||
public void setAccessibilityLabel(@Nonnull T view, String accessibilityLabel) {
|
||||
public void setAccessibilityLabel(@NonNull T view, String accessibilityLabel) {
|
||||
view.setTag(R.id.accessibility_label, accessibilityLabel);
|
||||
updateViewContentDescription(view);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ACCESSIBILITY_HINT)
|
||||
public void setAccessibilityHint(@Nonnull T view, String accessibilityHint) {
|
||||
public void setAccessibilityHint(@NonNull T view, String accessibilityHint) {
|
||||
view.setTag(R.id.accessibility_hint, accessibilityHint);
|
||||
updateViewContentDescription(view);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ACCESSIBILITY_ROLE)
|
||||
public void setAccessibilityRole(@Nonnull T view, @Nullable String accessibilityRole) {
|
||||
public void setAccessibilityRole(@NonNull T view, @Nullable String accessibilityRole) {
|
||||
if (accessibilityRole == null) {
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ACCESSIBILITY_STATES)
|
||||
public void setViewStates(@Nonnull T view, @Nullable ReadableArray accessibilityStates) {
|
||||
public void setViewStates(@NonNull T view, @Nullable ReadableArray accessibilityStates) {
|
||||
boolean shouldUpdateContentDescription =
|
||||
view.getTag(R.id.accessibility_states) != null && accessibilityStates == null;
|
||||
view.setTag(R.id.accessibility_states, accessibilityStates);
|
||||
@@ -183,7 +183,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ACCESSIBILITY_STATE)
|
||||
public void setViewState(@Nonnull T view, @Nullable ReadableMap accessibilityState) {
|
||||
public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilityState) {
|
||||
if (accessibilityState == null) {
|
||||
return;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
}
|
||||
|
||||
private void updateViewContentDescription(@Nonnull T view) {
|
||||
private void updateViewContentDescription(@NonNull T view) {
|
||||
final String accessibilityLabel = (String) view.getTag(R.id.accessibility_label);
|
||||
final ReadableArray accessibilityStates =
|
||||
(ReadableArray) view.getTag(R.id.accessibility_states);
|
||||
@@ -268,7 +268,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
|
||||
@ReactProp(name = PROP_IMPORTANT_FOR_ACCESSIBILITY)
|
||||
public void setImportantForAccessibility(
|
||||
@Nonnull T view, @Nullable String importantForAccessibility) {
|
||||
@NonNull T view, @Nullable String importantForAccessibility) {
|
||||
if (importantForAccessibility == null || importantForAccessibility.equals("auto")) {
|
||||
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
|
||||
} else if (importantForAccessibility.equals("yes")) {
|
||||
@@ -283,36 +283,36 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
|
||||
@Deprecated
|
||||
@ReactProp(name = PROP_ROTATION)
|
||||
public void setRotation(@Nonnull T view, float rotation) {
|
||||
public void setRotation(@NonNull T view, float rotation) {
|
||||
view.setRotation(rotation);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ReactProp(name = PROP_SCALE_X, defaultFloat = 1f)
|
||||
public void setScaleX(@Nonnull T view, float scaleX) {
|
||||
public void setScaleX(@NonNull T view, float scaleX) {
|
||||
view.setScaleX(scaleX);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ReactProp(name = PROP_SCALE_Y, defaultFloat = 1f)
|
||||
public void setScaleY(@Nonnull T view, float scaleY) {
|
||||
public void setScaleY(@NonNull T view, float scaleY) {
|
||||
view.setScaleY(scaleY);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ReactProp(name = PROP_TRANSLATE_X, defaultFloat = 0f)
|
||||
public void setTranslateX(@Nonnull T view, float translateX) {
|
||||
public void setTranslateX(@NonNull T view, float translateX) {
|
||||
view.setTranslationX(PixelUtil.toPixelFromDIP(translateX));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ReactProp(name = PROP_TRANSLATE_Y, defaultFloat = 0f)
|
||||
public void setTranslateY(@Nonnull T view, float translateY) {
|
||||
public void setTranslateY(@NonNull T view, float translateY) {
|
||||
view.setTranslationY(PixelUtil.toPixelFromDIP(translateY));
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ACCESSIBILITY_LIVE_REGION)
|
||||
public void setAccessibilityLiveRegion(@Nonnull T view, @Nullable String liveRegion) {
|
||||
public void setAccessibilityLiveRegion(@NonNull T view, @Nullable String liveRegion) {
|
||||
if (liveRegion == null || liveRegion.equals("none")) {
|
||||
ViewCompat.setAccessibilityLiveRegion(view, ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE);
|
||||
} else if (liveRegion.equals("polite")) {
|
||||
@@ -322,8 +322,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
}
|
||||
|
||||
private static void setTransformProperty(@Nonnull View view, ReadableArray transforms) {
|
||||
sMatrixDecompositionContext.reset();
|
||||
private static void setTransformProperty(@NonNull View view, ReadableArray transforms) {
|
||||
TransformHelper.processTransform(transforms, sTransformDecompositionArray);
|
||||
MatrixMathHelper.decomposeMatrix(sTransformDecompositionArray, sMatrixDecompositionContext);
|
||||
view.setTranslationX(
|
||||
@@ -360,7 +359,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
}
|
||||
}
|
||||
|
||||
private static void resetTransformProperty(@Nonnull View view) {
|
||||
private static void resetTransformProperty(@NonNull View view) {
|
||||
view.setTranslationX(PixelUtil.toPixelFromDIP(0));
|
||||
view.setTranslationY(PixelUtil.toPixelFromDIP(0));
|
||||
view.setRotation(0);
|
||||
@@ -371,12 +370,12 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
|
||||
view.setCameraDistance(0);
|
||||
}
|
||||
|
||||
private void updateViewAccessibility(@Nonnull T view) {
|
||||
private void updateViewAccessibility(@NonNull T view) {
|
||||
ReactAccessibilityDelegate.setDelegate(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAfterUpdateTransaction(@Nonnull T view) {
|
||||
protected void onAfterUpdateTransaction(@NonNull T view) {
|
||||
super.onAfterUpdateTransaction(view);
|
||||
updateViewAccessibility(view);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user