Skip to content

Commit b9df3d4

Browse files
Thomas Nardonefacebook-github-bot
authored andcommitted
Nullsafe jcf/react/animated (facebook#48932)
Summary: Results of running nullsafe script with `--patch=apply_fixmes`, `--patch=mark_nullsafe`, with minimal manual fixes to get all checks passing. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D68629827
1 parent 73968dc commit b9df3d4

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.facebook.common.logging.FLog;
1515
import com.facebook.fbreact.specs.NativeAnimatedModuleSpec;
1616
import com.facebook.infer.annotation.Assertions;
17+
import com.facebook.infer.annotation.Nullsafe;
1718
import com.facebook.react.bridge.Arguments;
1819
import com.facebook.react.bridge.Callback;
1920
import com.facebook.react.bridge.LifecycleEventListener;
@@ -87,6 +88,7 @@
8788
* This isolates us from the problems that may be caused by concurrent updates of animated graph
8889
* while UI thread is "executing" the animation loop.
8990
*/
91+
@Nullsafe(Nullsafe.Mode.LOCAL)
9092
@ReactModule(name = NativeAnimatedModuleSpec.NAME)
9193
public class NativeAnimatedModule extends NativeAnimatedModuleSpec
9294
implements LifecycleEventListener, UIManagerListener {
@@ -117,6 +119,7 @@ private enum BatchExecutionOpCodes {
117119
OP_CODE_ADD_LISTENER(20), // ios only
118120
OP_CODE_REMOVE_LISTENERS(21); // ios only
119121

122+
// NULLSAFE_FIXME[Field Not Nullable]
120123
private static BatchExecutionOpCodes[] valueMap = null;
121124
private final int value;
122125

@@ -371,7 +374,9 @@ public void didDispatchMountItems(UIManager uiManager) {
371374
}
372375
}
373376

377+
// NULLSAFE_FIXME[Parameter Not Nullable]
374378
mPreOperations.executeBatch(batchNumber, getNodesManager());
379+
// NULLSAFE_FIXME[Parameter Not Nullable]
375380
mOperations.executeBatch(batchNumber, getNodesManager());
376381
}
377382

@@ -391,15 +396,19 @@ public void willDispatchViewUpdates(final UIManager uiManager) {
391396
UIBlock preOperationsUIBlock =
392397
new UIBlock() {
393398
@Override
399+
// NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
394400
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
401+
// NULLSAFE_FIXME[Parameter Not Nullable]
395402
mPreOperations.executeBatch(frameNo, getNodesManager());
396403
}
397404
};
398405

399406
UIBlock operationsUIBlock =
400407
new UIBlock() {
401408
@Override
409+
// NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
402410
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
411+
// NULLSAFE_FIXME[Parameter Not Nullable]
403412
mOperations.executeBatch(frameNo, getNodesManager());
404413
}
405414
};
@@ -1119,13 +1128,16 @@ public void execute(NativeAnimatedNodesManager animatedNodesManager) {
11191128
switch (command) {
11201129
case OP_CODE_CREATE_ANIMATED_NODE:
11211130
animatedNodesManager.createAnimatedNode(
1131+
// NULLSAFE_FIXME[Parameter Not Nullable]
11221132
opsAndArgs.getInt(i++), opsAndArgs.getMap(i++));
11231133
break;
11241134
case OP_CODE_UPDATE_ANIMATED_NODE_CONFIG:
11251135
animatedNodesManager.updateAnimatedNodeConfig(
1136+
// NULLSAFE_FIXME[Parameter Not Nullable]
11261137
opsAndArgs.getInt(i++), opsAndArgs.getMap(i++));
11271138
break;
11281139
case OP_CODE_GET_VALUE:
1140+
// NULLSAFE_FIXME[Parameter Not Nullable]
11291141
animatedNodesManager.getValue(opsAndArgs.getInt(i++), null);
11301142
break;
11311143
case OP_START_LISTENING_TO_ANIMATED_NODE_VALUE:
@@ -1163,6 +1175,7 @@ public void onValueUpdate(double value) {
11631175
enqueueFrameCallback();
11641176
}
11651177
animatedNodesManager.startAnimatingNode(
1178+
// NULLSAFE_FIXME[Parameter Not Nullable]
11661179
opsAndArgs.getInt(i++), opsAndArgs.getInt(i++), opsAndArgs.getMap(i++), null);
11671180
break;
11681181
case OP_CODE_STOP_ANIMATION:
@@ -1200,12 +1213,14 @@ public void onValueUpdate(double value) {
12001213
break;
12011214
case OP_CODE_ADD_ANIMATED_EVENT_TO_VIEW:
12021215
animatedNodesManager.addAnimatedEventToView(
1216+
// NULLSAFE_FIXME[Parameter Not Nullable]
12031217
opsAndArgs.getInt(i++), opsAndArgs.getString(i++), opsAndArgs.getMap(i++));
12041218
break;
12051219
case OP_CODE_REMOVE_ANIMATED_EVENT_FROM_VIEW:
12061220
viewTag = opsAndArgs.getInt(i++);
12071221
decrementInFlightAnimationsForViewTag(viewTag);
12081222
animatedNodesManager.removeAnimatedEventFromView(
1223+
// NULLSAFE_FIXME[Parameter Not Nullable]
12091224
viewTag, opsAndArgs.getString(i++), opsAndArgs.getInt(i++));
12101225
break;
12111226
case OP_CODE_ADD_LISTENER:

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.Nullable;
1212
import androidx.annotation.UiThread;
1313
import com.facebook.common.logging.FLog;
14+
import com.facebook.infer.annotation.Nullsafe;
1415
import com.facebook.react.bridge.Arguments;
1516
import com.facebook.react.bridge.Callback;
1617
import com.facebook.react.bridge.JSApplicationCausedNativeException;
@@ -51,6 +52,7 @@
5152
*
5253
* <p>IMPORTANT: This class should be accessed only from the UI Thread
5354
*/
55+
@Nullsafe(Nullsafe.Mode.LOCAL)
5456
public class NativeAnimatedNodesManager implements EventDispatcherListener {
5557

5658
private static final String TAG = "NativeAnimatedNodesManager";
@@ -252,7 +254,10 @@ public void extractAnimatedNodeOffset(int tag) {
252254

253255
@UiThread
254256
public void startAnimatingNode(
255-
int animationId, int animatedNodeTag, ReadableMap animationConfig, Callback endCallback) {
257+
int animationId,
258+
int animatedNodeTag,
259+
ReadableMap animationConfig,
260+
@Nullable Callback endCallback) {
256261
AnimatedNode node = mAnimatedNodes.get(animatedNodeTag);
257262
if (node == null) {
258263
throw new JSApplicationIllegalArgumentException(
@@ -306,6 +311,7 @@ private void stopAnimationsForNode(AnimatedNode animatedNode) {
306311
// Invoke animation end callback with {finished: false}
307312
WritableMap endCallbackResponse = Arguments.createMap();
308313
endCallbackResponse.putBoolean("finished", false);
314+
// NULLSAFE_FIXME[Nullable Dereference]
309315
endCallbackResponse.putDouble("value", animation.animatedValue.nodeValue);
310316
animation.endCallback.invoke(endCallbackResponse);
311317
} else if (mReactApplicationContext != null) {
@@ -315,6 +321,7 @@ private void stopAnimationsForNode(AnimatedNode animatedNode) {
315321
WritableMap params = Arguments.createMap();
316322
params.putInt("animationId", animation.id);
317323
params.putBoolean("finished", false);
324+
// NULLSAFE_FIXME[Nullable Dereference]
318325
params.putDouble("value", animation.animatedValue.nodeValue);
319326
if (events == null) {
320327
events = Arguments.createArray();
@@ -344,6 +351,7 @@ public void stopAnimation(int animationId) {
344351
// Invoke animation end callback with {finished: false}
345352
WritableMap endCallbackResponse = Arguments.createMap();
346353
endCallbackResponse.putBoolean("finished", false);
354+
// NULLSAFE_FIXME[Nullable Dereference]
347355
endCallbackResponse.putDouble("value", animation.animatedValue.nodeValue);
348356
animation.endCallback.invoke(endCallbackResponse);
349357
} else if (mReactApplicationContext != null) {
@@ -353,6 +361,7 @@ public void stopAnimation(int animationId) {
353361
WritableMap params = Arguments.createMap();
354362
params.putInt("animationId", animation.id);
355363
params.putBoolean("finished", false);
364+
// NULLSAFE_FIXME[Nullable Dereference]
356365
params.putDouble("value", animation.animatedValue.nodeValue);
357366
if (events == null) {
358367
events = Arguments.createArray();
@@ -537,8 +546,11 @@ public void addAnimatedEventToView(
537546
}
538547

539548
ReadableArray path = eventMapping.getArray("nativeEventPath");
549+
// NULLSAFE_FIXME[Nullable Dereference]
540550
List<String> pathList = new ArrayList<>(path.size());
551+
// NULLSAFE_FIXME[Nullable Dereference]
541552
for (int i = 0; i < path.size(); i++) {
553+
// NULLSAFE_FIXME[Nullable Dereference]
542554
pathList.add(path.getString(i));
543555
}
544556

@@ -562,8 +574,11 @@ public void removeAnimatedEventFromView(
562574
ListIterator<EventAnimationDriver> it = mEventDrivers.listIterator();
563575
while (it.hasNext()) {
564576
EventAnimationDriver driver = it.next();
577+
// NULLSAFE_FIXME[Nullable Dereference]
565578
if (eventName.equals(driver.eventName)
579+
// NULLSAFE_FIXME[Nullable Dereference]
566580
&& viewTag == driver.viewTag
581+
// NULLSAFE_FIXME[Nullable Dereference]
567582
&& animatedValueTag == driver.valueNode.tag) {
568583
it.remove();
569584
break;
@@ -664,6 +679,7 @@ public void runUpdates(long frameTimeNanos) {
664679
if (animation.endCallback != null) {
665680
WritableMap endCallbackResponse = Arguments.createMap();
666681
endCallbackResponse.putBoolean("finished", true);
682+
// NULLSAFE_FIXME[Nullable Dereference]
667683
endCallbackResponse.putDouble("value", animation.animatedValue.nodeValue);
668684
animation.endCallback.invoke(endCallbackResponse);
669685
} else if (mReactApplicationContext != null) {
@@ -673,6 +689,7 @@ public void runUpdates(long frameTimeNanos) {
673689
WritableMap params = Arguments.createMap();
674690
params.putInt("animationId", animation.id);
675691
params.putBoolean("finished", true);
692+
// NULLSAFE_FIXME[Nullable Dereference]
676693
params.putDouble("value", animation.animatedValue.nodeValue);
677694
if (events == null) {
678695
events = Arguments.createArray();
@@ -738,8 +755,11 @@ private void updateNodes(List<AnimatedNode> nodes) {
738755

739756
while (!nodesQueue.isEmpty()) {
740757
AnimatedNode nextNode = nodesQueue.poll();
758+
// NULLSAFE_FIXME[Nullable Dereference]
741759
if (nextNode.children != null) {
760+
// NULLSAFE_FIXME[Nullable Dereference]
742761
for (int i = 0; i < nextNode.children.size(); i++) {
762+
// NULLSAFE_FIXME[Nullable Dereference]
743763
AnimatedNode child = nextNode.children.get(i);
744764
child.activeIncomingNodes++;
745765
if (child.BFSColor != mAnimatedGraphBFSColor) {
@@ -780,6 +800,7 @@ private void updateNodes(List<AnimatedNode> nodes) {
780800
while (!nodesQueue.isEmpty()) {
781801
AnimatedNode nextNode = nodesQueue.poll();
782802
try {
803+
// NULLSAFE_FIXME[Nullable Dereference]
783804
nextNode.update();
784805
if (nextNode instanceof PropsAnimatedNode) {
785806
// Send property updates to native view manager
@@ -799,8 +820,11 @@ private void updateNodes(List<AnimatedNode> nodes) {
799820
// Potentially send events to JS when the node's value is updated
800821
((ValueAnimatedNode) nextNode).onValueUpdate();
801822
}
823+
// NULLSAFE_FIXME[Nullable Dereference]
802824
if (nextNode.children != null) {
825+
// NULLSAFE_FIXME[Nullable Dereference]
803826
for (int i = 0; i < nextNode.children.size(); i++) {
827+
// NULLSAFE_FIXME[Nullable Dereference]
804828
AnimatedNode child = nextNode.children.get(i);
805829
child.activeIncomingNodes--;
806830
if (child.BFSColor != mAnimatedGraphBFSColor && child.activeIncomingNodes == 0) {

packages/react-native/ReactAndroid/src/test/java/com/facebook/react/animated/NativeAnimatedNodeTraversalTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class NativeAnimatedNodeTraversalTest {
280280
}
281281

282282
private fun performSpringAnimationTestWithConfig(
283-
config: JavaOnlyMap?,
283+
config: JavaOnlyMap,
284284
testForCriticallyDamped: Boolean
285285
) {
286286
createSimpleAnimatedViewWithOpacity()

0 commit comments

Comments
 (0)