Skip to content

Commit 198c6fc

Browse files
javachefacebook-github-bot
authored andcommitted
Make receiveCommand args non-nullable (#51806)
Summary: Pull Request resolved: #51806 Correct the type of args, which is always non-null. This is backwards-compatible as subclasses can override this method with a more permissive nullable type and still be substitutable. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D75869317 fbshipit-source-id: 8f6c9119140794447eca55be24483a35450d7bb6
1 parent 2c32bfa commit 198c6fc

18 files changed

Lines changed: 39 additions & 35 deletions

File tree

packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const PropSetterTemplate = ({propCases}: {propCases: string}) =>
7474
const CommandsTemplate = ({commandCases}: {commandCases: string}) =>
7575
`
7676
@Override
77-
public void receiveCommand(T view, String commandName, @Nullable ReadableArray args) {
77+
public void receiveCommand(T view, String commandName, ReadableArray args) {
7878
switch (commandName) {
7979
${commandCases}
8080
}

packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public class CommandNativeComponentManagerDelegate<T extends View, U extends Bas
221221
}
222222
223223
@Override
224-
public void receiveCommand(T view, String commandName, @Nullable ReadableArray args) {
224+
public void receiveCommand(T view, String commandName, ReadableArray args) {
225225
switch (commandName) {
226226
case \\"flashScrollIndicators\\":
227227
mViewManager.flashScrollIndicators(view);
@@ -272,7 +272,7 @@ public class CommandNativeComponentManagerDelegate<T extends View, U extends Bas
272272
}
273273
274274
@Override
275-
public void receiveCommand(T view, String commandName, @Nullable ReadableArray args) {
275+
public void receiveCommand(T view, String commandName, ReadableArray args) {
276276
switch (commandName) {
277277
case \\"handleRootTag\\":
278278
mViewManager.handleRootTag(view, args.getDouble(0));

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,6 +4646,7 @@ public abstract class com/facebook/react/uimanager/ViewManager : com/facebook/re
46464646

46474647
public abstract interface class com/facebook/react/uimanager/ViewManagerDelegate {
46484648
public abstract synthetic fun kotlinCompat$receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
4649+
public synthetic fun kotlinCompat$receiveCommandNullableArgs (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
46494650
public abstract synthetic fun kotlinCompat$setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
46504651
public fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V
46514652
public fun setProperty (Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ public boolean getViewExists(int reactTag) {
268268

269269
@Deprecated
270270
public void receiveCommand(
271-
int surfaceId, int reactTag, int commandId, @Nullable ReadableArray commandArgs) {
271+
int surfaceId, int reactTag, int commandId, ReadableArray commandArgs) {
272272
UiThreadUtil.assertOnUiThread();
273273
getSurfaceManagerEnforced(surfaceId, "receiveCommand:int")
274274
.receiveCommand(reactTag, commandId, commandArgs);
275275
}
276276

277277
public void receiveCommand(
278-
int surfaceId, int reactTag, String commandId, @Nullable ReadableArray commandArgs) {
278+
int surfaceId, int reactTag, String commandId, ReadableArray commandArgs) {
279279
UiThreadUtil.assertOnUiThread();
280280
getSurfaceManagerEnforced(surfaceId, "receiveCommand:string")
281281
.receiveCommand(reactTag, commandId, commandArgs);

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ public void updateProps(int reactTag, ReadableMap props) {
698698
}
699699

700700
@Deprecated
701-
public void receiveCommand(int reactTag, int commandId, @Nullable ReadableArray commandArgs) {
701+
public void receiveCommand(int reactTag, int commandId, ReadableArray commandArgs) {
702702
if (isStopped()) {
703703
return;
704704
}
@@ -726,8 +726,7 @@ public void receiveCommand(int reactTag, int commandId, @Nullable ReadableArray
726726
viewState.mViewManager.receiveCommand(viewState.mView, commandId, commandArgs);
727727
}
728728

729-
public void receiveCommand(
730-
int reactTag, @NonNull String commandId, @Nullable ReadableArray commandArgs) {
729+
public void receiveCommand(int reactTag, @NonNull String commandId, ReadableArray commandArgs) {
731730
if (isStopped()) {
732731
return;
733732
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class DispatchIntCommandMountItem(
1414
private val surfaceId: Int,
1515
private val reactTag: Int,
1616
private val commandId: Int,
17-
private val commandArgs: ReadableArray?
17+
private val commandArgs: ReadableArray
1818
) : DispatchCommandMountItem() {
1919

2020
override fun getSurfaceId(): Int = surfaceId

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class DispatchStringCommandMountItem(
1414
private val surfaceId: Int,
1515
private val reactTag: Int,
1616
private val commandId: String,
17-
private val commandArgs: ReadableArray?
17+
private val commandArgs: ReadableArray
1818
) : DispatchCommandMountItem() {
1919

2020
override fun getSurfaceId(): Int = surfaceId

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal object MountItemFactory {
1919
surfaceId: Int,
2020
reactTag: Int,
2121
commandId: Int,
22-
commandArgs: ReadableArray?
22+
commandArgs: ReadableArray
2323
): DispatchCommandMountItem =
2424
DispatchIntCommandMountItem(surfaceId, reactTag, commandId, commandArgs)
2525

@@ -29,7 +29,7 @@ internal object MountItemFactory {
2929
surfaceId: Int,
3030
reactTag: Int,
3131
commandId: String,
32-
commandArgs: ReadableArray?
32+
commandArgs: ReadableArray
3333
): DispatchCommandMountItem =
3434
DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs)
3535

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,5 @@ public abstract class BaseViewManagerDelegate<
149149
}
150150

151151
@Suppress("ACCIDENTAL_OVERRIDE")
152-
public override fun receiveCommand(view: T, commandName: String, args: ReadableArray?): Unit =
153-
Unit
152+
public override fun receiveCommand(view: T, commandName: String, args: ReadableArray): Unit = Unit
154153
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ protected void onAfterUpdateTransaction(@NonNull T view) {}
328328
* @param args optional arguments for the command
329329
*/
330330
@Deprecated
331-
public void receiveCommand(@NonNull T view, int commandId, @Nullable ReadableArray args) {}
331+
public void receiveCommand(@NonNull T view, int commandId, ReadableArray args) {}
332332

333333
/**
334334
* Subclasses may use this method to receive events/commands directly from JS through the {@link
@@ -339,7 +339,7 @@ public void receiveCommand(@NonNull T view, int commandId, @Nullable ReadableArr
339339
* @param commandId code of the command
340340
* @param args optional arguments for the command
341341
*/
342-
public void receiveCommand(@NonNull T view, String commandId, @Nullable ReadableArray args) {
342+
public void receiveCommand(@NonNull T view, String commandId, ReadableArray args) {
343343
getOrCreateViewManagerDelegate().receiveCommand(view, commandId, args);
344344
}
345345

0 commit comments

Comments
 (0)