mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove reflection in OkHttpCallUtil (#48308)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48308 Reflection is overkill here, we can simply suppress the deprecation "error". Changelog: [Internal] Reviewed By: javache Differential Revision: D67337980 fbshipit-source-id: 12076258ed4cb5c8737c84378621dda3072ec5a0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dfdacb84ce
commit
e577e48ad7
+4
-8
@@ -5,9 +5,10 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION_ERROR") // Conflicting okhttp versions
|
||||
|
||||
package com.facebook.react.common.network
|
||||
|
||||
import okhttp3.Dispatcher
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
/**
|
||||
@@ -15,13 +16,8 @@ import okhttp3.OkHttpClient
|
||||
*/
|
||||
internal object OkHttpCallUtil {
|
||||
@JvmStatic
|
||||
public fun cancelTag(client: OkHttpClient, tag: Any) {
|
||||
// client.dispatcher is private, so we need to use reflection to access
|
||||
// it via method dispatcher() otherwise we will get a compile error:
|
||||
// Using 'dispatcher(): Dispatcher' is an error. moved to val
|
||||
val dispatcherMethod = OkHttpClient::class.java.getMethod("dispatcher")
|
||||
dispatcherMethod.setAccessible(true)
|
||||
val dispatcher = dispatcherMethod.invoke(client) as Dispatcher
|
||||
fun cancelTag(client: OkHttpClient, tag: Any) {
|
||||
val dispatcher = client.dispatcher()
|
||||
for (call in dispatcher.queuedCalls()) {
|
||||
if (tag == call.request().tag()) {
|
||||
call.cancel()
|
||||
|
||||
Reference in New Issue
Block a user