mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add NonNull annotation to Fabric Event classes
Summary: This diff annotates Fabric MountingManager and Events classes with NonNull annotations, this will help analysis of nullability plus improving integration with Kotlin clients Changelog: Add NonNull annotation to Fabric Event classes Reviewed By: shergin Differential Revision: D18010923 fbshipit-source-id: fb9d5683bbd51fa25dda9b2023f9c411c3ff541d
This commit is contained in:
committed by
Facebook Github Bot
parent
27d71fc725
commit
a58fcbff0b
@@ -8,6 +8,7 @@
|
||||
package com.facebook.react.fabric.events;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
@@ -31,7 +32,7 @@ public class EventBeatManager implements BatchEventDispatchedListener {
|
||||
|
||||
private native void beat();
|
||||
|
||||
public EventBeatManager(ReactApplicationContext reactApplicationContext) {
|
||||
public EventBeatManager(@NonNull ReactApplicationContext reactApplicationContext) {
|
||||
mHybridData = initHybrid();
|
||||
mReactApplicationContext = reactApplicationContext;
|
||||
}
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@
|
||||
package com.facebook.react.fabric.events;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
@@ -35,7 +36,7 @@ public class EventEmitterWrapper {
|
||||
mHybridData = initHybrid();
|
||||
}
|
||||
|
||||
private native void invokeEvent(String eventName, NativeMap params);
|
||||
private native void invokeEvent(@NonNull String eventName, @NonNull NativeMap params);
|
||||
|
||||
/**
|
||||
* Invokes the execution of the C++ EventEmitter.
|
||||
@@ -43,7 +44,7 @@ public class EventEmitterWrapper {
|
||||
* @param eventName {@link String} name of the event to execute.
|
||||
* @param params {@link WritableMap} payload of the event
|
||||
*/
|
||||
public void invoke(String eventName, @Nullable WritableMap params) {
|
||||
public void invoke(@NonNull String eventName, @Nullable WritableMap params) {
|
||||
NativeMap payload = params == null ? new WritableNativeMap() : (NativeMap) params;
|
||||
invokeEvent(eventName, payload);
|
||||
}
|
||||
|
||||
+14
-11
@@ -14,6 +14,7 @@ import static com.facebook.react.uimanager.events.TouchesHelper.TOP_TOUCH_END_KE
|
||||
import static com.facebook.react.uimanager.events.TouchesHelper.TOUCHES_KEY;
|
||||
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
@@ -29,16 +30,16 @@ import java.util.Set;
|
||||
|
||||
public class FabricEventEmitter implements RCTEventEmitter {
|
||||
|
||||
private static final String TAG = FabricEventEmitter.class.getSimpleName();
|
||||
private static final String TAG = "FabricEventEmitter";
|
||||
|
||||
private final FabricUIManager mUIManager;
|
||||
@NonNull private final FabricUIManager mUIManager;
|
||||
|
||||
public FabricEventEmitter(FabricUIManager uiManager) {
|
||||
public FabricEventEmitter(@NonNull FabricUIManager uiManager) {
|
||||
mUIManager = uiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveEvent(int reactTag, String eventName, @Nullable WritableMap params) {
|
||||
public void receiveEvent(int reactTag, @NonNull String eventName, @Nullable WritableMap params) {
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"FabricEventEmitter.receiveEvent('" + eventName + "')");
|
||||
@@ -48,7 +49,9 @@ public class FabricEventEmitter implements RCTEventEmitter {
|
||||
|
||||
@Override
|
||||
public void receiveTouches(
|
||||
String eventTopLevelType, WritableArray touches, WritableArray changedIndices) {
|
||||
@NonNull String eventTopLevelType,
|
||||
@NonNull WritableArray touches,
|
||||
@NonNull WritableArray changedIndices) {
|
||||
Pair<WritableArray, WritableArray> result =
|
||||
TOP_TOUCH_END_KEY.equalsIgnoreCase(eventTopLevelType)
|
||||
|| TOP_TOUCH_CANCEL_KEY.equalsIgnoreCase(eventTopLevelType)
|
||||
@@ -79,7 +82,7 @@ public class FabricEventEmitter implements RCTEventEmitter {
|
||||
}
|
||||
|
||||
/** TODO T31905686 optimize this to avoid copying arrays */
|
||||
private WritableArray copyWritableArray(WritableArray array) {
|
||||
private WritableArray copyWritableArray(@NonNull WritableArray array) {
|
||||
WritableNativeArray ret = new WritableNativeArray();
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
ret.pushMap(getWritableMap(array.getMap(i)));
|
||||
@@ -101,8 +104,8 @@ public class FabricEventEmitter implements RCTEventEmitter {
|
||||
* @param indices {WritableArray} Indices to remove from `touches`.
|
||||
* @return {Array<Touch>} Subsequence of removed touch objects.
|
||||
*/
|
||||
private Pair<WritableArray, WritableArray> removeTouchesAtIndices(
|
||||
WritableArray touches, WritableArray indices) {
|
||||
private @NonNull Pair<WritableArray, WritableArray> removeTouchesAtIndices(
|
||||
@NonNull WritableArray touches, @NonNull WritableArray indices) {
|
||||
WritableArray rippedOut = new WritableNativeArray();
|
||||
// use an unsafe downcast to alias to nullable elements,
|
||||
// so we can delete and then compact.
|
||||
@@ -131,8 +134,8 @@ public class FabricEventEmitter implements RCTEventEmitter {
|
||||
* @param changedIndices {@link WritableArray} Indices by which to pull subsequence.
|
||||
* @return {Array<Touch>} Subsequence of touch objects.
|
||||
*/
|
||||
private Pair<WritableArray, WritableArray> touchSubsequence(
|
||||
WritableArray touches, WritableArray changedIndices) {
|
||||
private @NonNull Pair<WritableArray, WritableArray> touchSubsequence(
|
||||
@NonNull WritableArray touches, @NonNull WritableArray changedIndices) {
|
||||
WritableArray result = new WritableNativeArray();
|
||||
for (int i = 0; i < changedIndices.size(); i++) {
|
||||
result.pushMap(getWritableMap(touches.getMap(changedIndices.getInt(i))));
|
||||
@@ -146,7 +149,7 @@ public class FabricEventEmitter implements RCTEventEmitter {
|
||||
*
|
||||
* @param readableMap {@link ReadableMap} source map
|
||||
*/
|
||||
private WritableMap getWritableMap(ReadableMap readableMap) {
|
||||
private @NonNull WritableMap getWritableMap(@NonNull ReadableMap readableMap) {
|
||||
WritableNativeMap map = new WritableNativeMap();
|
||||
map.merge(readableMap);
|
||||
return map;
|
||||
|
||||
+27
-24
@@ -12,6 +12,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
@@ -44,17 +45,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class MountingManager {
|
||||
public static final String TAG = MountingManager.class.getSimpleName();
|
||||
|
||||
private final ConcurrentHashMap<Integer, ViewState> mTagToViewState;
|
||||
private final JSResponderHandler mJSResponderHandler = new JSResponderHandler();
|
||||
private final ViewManagerRegistry mViewManagerRegistry;
|
||||
private final RootViewManager mRootViewManager = new RootViewManager();
|
||||
@NonNull private final ConcurrentHashMap<Integer, ViewState> mTagToViewState;
|
||||
@NonNull private final JSResponderHandler mJSResponderHandler = new JSResponderHandler();
|
||||
@NonNull private final ViewManagerRegistry mViewManagerRegistry;
|
||||
@NonNull private final RootViewManager mRootViewManager = new RootViewManager();
|
||||
|
||||
public MountingManager(ViewManagerRegistry viewManagerRegistry) {
|
||||
public MountingManager(@NonNull ViewManagerRegistry viewManagerRegistry) {
|
||||
mTagToViewState = new ConcurrentHashMap<>();
|
||||
mViewManagerRegistry = viewManagerRegistry;
|
||||
}
|
||||
|
||||
public void addRootView(int reactRootTag, View rootView) {
|
||||
public void addRootView(int reactRootTag, @NonNull View rootView) {
|
||||
if (rootView.getId() != View.NO_ID) {
|
||||
throw new IllegalViewOperationException(
|
||||
"Trying to add a root view with an explicit id already set. React Native uses "
|
||||
@@ -69,7 +70,7 @@ public class MountingManager {
|
||||
|
||||
/** Releases all references to given native View. */
|
||||
@UiThread
|
||||
private void dropView(View view) {
|
||||
private void dropView(@NonNull View view) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
int reactTag = view.getId();
|
||||
@@ -109,7 +110,7 @@ public class MountingManager {
|
||||
getViewGroupManager(parentViewState).addView(parentView, view, index);
|
||||
}
|
||||
|
||||
private ViewState getViewState(int tag) {
|
||||
private @NonNull ViewState getViewState(int tag) {
|
||||
ViewState viewState = mTagToViewState.get(tag);
|
||||
if (viewState == null) {
|
||||
throw new IllegalStateException("Unable to find viewState view for tag " + tag);
|
||||
@@ -134,7 +135,7 @@ public class MountingManager {
|
||||
}
|
||||
|
||||
if (viewState.mViewManager == null) {
|
||||
throw new IllegalStateException("Unable to find viewState manager for tag " + reactTag);
|
||||
throw new IllegalStateException("Unable to find viewManager for tag " + reactTag);
|
||||
}
|
||||
|
||||
if (viewState.mView == null) {
|
||||
@@ -144,7 +145,8 @@ public class MountingManager {
|
||||
viewState.mViewManager.receiveCommand(viewState.mView, commandId, commandArgs);
|
||||
}
|
||||
|
||||
public void receiveCommand(int reactTag, String commandId, @Nullable ReadableArray commandArgs) {
|
||||
public void receiveCommand(
|
||||
int reactTag, @NonNull String commandId, @Nullable ReadableArray commandArgs) {
|
||||
ViewState viewState = getNullableViewState(reactTag);
|
||||
|
||||
if (viewState == null) {
|
||||
@@ -181,7 +183,8 @@ public class MountingManager {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // prevents unchecked conversion warn of the <ViewGroup> type
|
||||
private static ViewGroupManager<ViewGroup> getViewGroupManager(ViewState viewState) {
|
||||
private static @NonNull ViewGroupManager<ViewGroup> getViewGroupManager(
|
||||
@NonNull ViewState viewState) {
|
||||
if (viewState.mViewManager == null) {
|
||||
throw new IllegalStateException("Unable to find ViewManager for view: " + viewState);
|
||||
}
|
||||
@@ -212,8 +215,8 @@ public class MountingManager {
|
||||
|
||||
@UiThread
|
||||
public void createView(
|
||||
ThemedReactContext themedReactContext,
|
||||
String componentName,
|
||||
@NonNull ThemedReactContext themedReactContext,
|
||||
@NonNull String componentName,
|
||||
int reactTag,
|
||||
@Nullable ReadableMap props,
|
||||
@Nullable StateWrapper stateWrapper,
|
||||
@@ -247,7 +250,7 @@ public class MountingManager {
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void updateProps(int reactTag, ReadableMap props) {
|
||||
public void updateProps(int reactTag, @Nullable ReadableMap props) {
|
||||
if (props == null) {
|
||||
return;
|
||||
}
|
||||
@@ -339,7 +342,7 @@ public class MountingManager {
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void updateLocalData(int reactTag, ReadableMap newLocalData) {
|
||||
public void updateLocalData(int reactTag, @NonNull ReadableMap newLocalData) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
ViewState viewState = getViewState(reactTag);
|
||||
if (viewState.mCurrentProps == null) {
|
||||
@@ -394,7 +397,7 @@ public class MountingManager {
|
||||
|
||||
@UiThread
|
||||
public void preallocateView(
|
||||
ThemedReactContext reactContext,
|
||||
@NonNull ThemedReactContext reactContext,
|
||||
String componentName,
|
||||
int reactTag,
|
||||
@Nullable ReadableMap props,
|
||||
@@ -410,7 +413,7 @@ public class MountingManager {
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void updateEventEmitter(int reactTag, EventEmitterWrapper eventEmitter) {
|
||||
public void updateEventEmitter(int reactTag, @NonNull EventEmitterWrapper eventEmitter) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
ViewState viewState = getViewState(reactTag);
|
||||
viewState.mEventEmitter = eventEmitter;
|
||||
@@ -471,15 +474,15 @@ public class MountingManager {
|
||||
|
||||
@AnyThread
|
||||
public long measure(
|
||||
Context context,
|
||||
String componentName,
|
||||
ReadableMap localData,
|
||||
ReadableMap props,
|
||||
ReadableMap state,
|
||||
@NonNull Context context,
|
||||
@NonNull String componentName,
|
||||
@NonNull ReadableMap localData,
|
||||
@NonNull ReadableMap props,
|
||||
@NonNull ReadableMap state,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
@NonNull YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode) {
|
||||
@NonNull YogaMeasureMode heightMode) {
|
||||
|
||||
return mViewManagerRegistry
|
||||
.get(componentName)
|
||||
|
||||
Reference in New Issue
Block a user