Skip to content

Commit 83fd174

Browse files
Thomas Nardonefacebook-github-bot
authored andcommitted
Lazily create args in ResponseUtil (facebook#49270)
Summary: Pull Request resolved: facebook#49270 Changelog: [Internal] Reviewed By: Abbondanzo Differential Revision: D69316855 fbshipit-source-id: 1c7f58cb9364540c5bf7309b6c2f81162efcc178
1 parent fc15260 commit 83fd174

File tree

1 file changed

+27
-36
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network

1 file changed

+27
-36
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/ResponseUtil.kt

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ internal object ResponseUtil {
2121
progress: Long,
2222
total: Long
2323
) {
24-
val args =
24+
reactContext?.emitDeviceEvent(
25+
"didSendNetworkData",
2526
Arguments.createArray().apply {
2627
pushInt(requestId)
2728
pushInt(progress.toInt())
2829
pushInt(total.toInt())
29-
}
30-
31-
reactContext?.emitDeviceEvent("didSendNetworkData", args)
30+
})
3231
}
3332

3433
@JvmStatic
@@ -39,15 +38,14 @@ internal object ResponseUtil {
3938
progress: Long,
4039
total: Long
4140
) {
42-
val args =
41+
reactContext?.emitDeviceEvent(
42+
"didReceiveNetworkIncrementalData",
4343
Arguments.createArray().apply {
4444
pushInt(requestId)
4545
pushString(data)
4646
pushInt(progress.toInt())
4747
pushInt(total.toInt())
48-
}
49-
50-
reactContext?.emitDeviceEvent("didReceiveNetworkIncrementalData", args)
48+
})
5149
}
5250

5351
@JvmStatic
@@ -57,36 +55,33 @@ internal object ResponseUtil {
5755
progress: Long,
5856
total: Long
5957
) {
60-
val args =
58+
reactContext?.emitDeviceEvent(
59+
"didReceiveNetworkDataProgress",
6160
Arguments.createArray().apply {
6261
pushInt(requestId)
6362
pushInt(progress.toInt())
6463
pushInt(total.toInt())
65-
}
66-
67-
reactContext?.emitDeviceEvent("didReceiveNetworkDataProgress", args)
64+
})
6865
}
6966

7067
@JvmStatic
7168
fun onDataReceived(reactContext: ReactApplicationContext?, requestId: Int, data: String?) {
72-
val args =
69+
reactContext?.emitDeviceEvent(
70+
"didReceiveNetworkData",
7371
Arguments.createArray().apply {
7472
pushInt(requestId)
7573
pushString(data)
76-
}
77-
78-
reactContext?.emitDeviceEvent("didReceiveNetworkData", args)
74+
})
7975
}
8076

8177
@JvmStatic
8278
fun onDataReceived(reactContext: ReactApplicationContext?, requestId: Int, data: WritableMap?) {
83-
val args =
79+
reactContext?.emitDeviceEvent(
80+
"didReceiveNetworkData",
8481
Arguments.createArray().apply {
8582
pushInt(requestId)
8683
pushMap(data)
87-
}
88-
89-
reactContext?.emitDeviceEvent("didReceiveNetworkData", args)
84+
})
9085
}
9186

9287
@JvmStatic
@@ -96,28 +91,25 @@ internal object ResponseUtil {
9691
error: String?,
9792
e: Throwable?
9893
) {
99-
val args =
94+
reactContext?.emitDeviceEvent(
95+
"didCompleteNetworkResponse",
10096
Arguments.createArray().apply {
10197
pushInt(requestId)
10298
pushString(error)
103-
}
104-
105-
if ((e != null) && (e.javaClass == SocketTimeoutException::class.java)) {
106-
args.pushBoolean(true) // last argument is a time out boolean
107-
}
108-
109-
reactContext?.emitDeviceEvent("didCompleteNetworkResponse", args)
99+
if (e?.javaClass == SocketTimeoutException::class.java) {
100+
pushBoolean(true) // last argument is a time out boolean
101+
}
102+
})
110103
}
111104

112105
@JvmStatic
113106
fun onRequestSuccess(reactContext: ReactApplicationContext?, requestId: Int) {
114-
val args =
107+
reactContext?.emitDeviceEvent(
108+
"didCompleteNetworkResponse",
115109
Arguments.createArray().apply {
116110
pushInt(requestId)
117111
pushNull()
118-
}
119-
120-
reactContext?.emitDeviceEvent("didCompleteNetworkResponse", args)
112+
})
121113
}
122114

123115
@JvmStatic
@@ -128,14 +120,13 @@ internal object ResponseUtil {
128120
headers: WritableMap?,
129121
url: String?
130122
) {
131-
val args =
123+
reactContext?.emitDeviceEvent(
124+
"didReceiveNetworkResponse",
132125
Arguments.createArray().apply {
133126
pushInt(requestId)
134127
pushInt(statusCode)
135128
pushMap(headers)
136129
pushString(url)
137-
}
138-
139-
reactContext?.emitDeviceEvent("didReceiveNetworkResponse", args)
130+
})
140131
}
141132
}

0 commit comments

Comments
 (0)