mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
add nullable annotations to some ViewManager methods (#23610)
Summary: Add nullable annotations to BaseViewManager and ViewManager methods. This will improve Kotlin developer experience and help Android Studio to offer better autocomplete. [Android] [Changed] - add nullable annotations to BaseViewManager and ViewManager methods. Might break ViewManagers in Kotlin. Pull Request resolved: https://github.com/facebook/react-native/pull/23610 Differential Revision: D14198630 Pulled By: mdvacca fbshipit-source-id: c596c88254e1d02f0af233a466f685200fac8917
This commit is contained in:
1 parent
0d5aebbd9a
commit
0b4f74176c
2 files changed
+45
-46
No files matched your search
@@ -20,6 +20,8 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup;
|
||||
import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@@ -31,7 +33,7 @@ import javax.annotation.Nullable;
|
||||
public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
extends BaseJavaModule {
|
||||
|
||||
public final void updateProperties(T viewToUpdate, ReactStylesDiffMap props) {
|
||||
public final void updateProperties(@Nonnull T viewToUpdate, ReactStylesDiffMap props) {
|
||||
ViewManagerPropertyUpdater.updateProps(this, viewToUpdate, props);
|
||||
onAfterUpdateTransaction(viewToUpdate);
|
||||
}
|
||||
@@ -39,8 +41,8 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
/**
|
||||
* Creates a view and installs event emitters on it.
|
||||
*/
|
||||
public final T createView(
|
||||
ThemedReactContext reactContext,
|
||||
public final @Nonnull T createView(
|
||||
@Nonnull ThemedReactContext reactContext,
|
||||
JSResponderHandler jsResponderHandler) {
|
||||
T view = createViewInstance(reactContext);
|
||||
addEventEmitters(reactContext, view);
|
||||
@@ -54,7 +56,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* @return the name of this view manager. This will be the name used to reference this view
|
||||
* manager from JavaScript in createReactNativeComponentClass.
|
||||
*/
|
||||
public abstract String getName();
|
||||
public abstract @Nonnull String getName();
|
||||
|
||||
/**
|
||||
* This method should return a subclass of {@link ReactShadowNode} which will be then used for
|
||||
@@ -65,7 +67,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
throw new RuntimeException("ViewManager subclasses must implement createShadowNodeInstance()");
|
||||
}
|
||||
|
||||
public C createShadowNodeInstance(ReactApplicationContext context) {
|
||||
public @Nonnull C createShadowNodeInstance(@Nonnull ReactApplicationContext context) {
|
||||
return createShadowNodeInstance();
|
||||
}
|
||||
|
||||
@@ -85,13 +87,13 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* Subclasses should return a new View instance of the proper type.
|
||||
* @param reactContext
|
||||
*/
|
||||
protected abstract T createViewInstance(ThemedReactContext reactContext);
|
||||
protected abstract @Nonnull T createViewInstance(@Nonnull ThemedReactContext reactContext);
|
||||
|
||||
/**
|
||||
* Called when view is detached from view hierarchy and allows for some additional cleanup by
|
||||
* the {@link ViewManager} subclass.
|
||||
*/
|
||||
public void onDropViewInstance(T view) {
|
||||
public void onDropViewInstance(@Nonnull T view) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +101,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* might want to override this method if your view needs to emit events besides basic touch events
|
||||
* to JS (e.g. scroll events).
|
||||
*/
|
||||
protected void addEventEmitters(ThemedReactContext reactContext, T view) {
|
||||
protected void addEventEmitters(@Nonnull ThemedReactContext reactContext, @Nonnull T view) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +110,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* you want to override this method you should call super.onAfterUpdateTransaction from it as
|
||||
* the parent class of the ViewManager may rely on callback being executed.
|
||||
*/
|
||||
protected void onAfterUpdateTransaction(T view) {
|
||||
protected void onAfterUpdateTransaction(@Nonnull T view) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +124,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
*
|
||||
* TODO(7247021): Replace updateExtraData with generic update props mechanism after D2086999
|
||||
*/
|
||||
public abstract void updateExtraData(T root, Object extraData);
|
||||
public abstract void updateExtraData(@Nonnull T root, Object extraData);
|
||||
|
||||
/**
|
||||
* Subclasses may use this method to receive events/commands directly from JS through the
|
||||
@@ -133,7 +135,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* @param commandId code of the command
|
||||
* @param args optional arguments for the command
|
||||
*/
|
||||
public void receiveCommand(T root, int commandId, @Nullable ReadableArray args) {
|
||||
public void receiveCommand(@Nonnull T root, int commandId, @Nullable ReadableArray args) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +211,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public @Nullable Object updateLocalData(T view, ReactStylesDiffMap props, ReactStylesDiffMap localData) {
|
||||
public @Nullable Object updateLocalData(@Nonnull T view, ReactStylesDiffMap props, ReactStylesDiffMap localData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user