-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow users to enable Flipper (#121)
- Loading branch information
Showing
13 changed files
with
254 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
android/app/src/flipper/java/com/sample/react/ReactNativeFlipper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.sample.react | ||
|
||
import android.content.Context | ||
import com.facebook.flipper.android.AndroidFlipperClient | ||
import com.facebook.flipper.android.utils.FlipperUtils | ||
import com.facebook.flipper.core.FlipperClient | ||
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin | ||
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin | ||
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin | ||
import com.facebook.flipper.plugins.inspector.DescriptorMapping | ||
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin | ||
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor | ||
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin | ||
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin | ||
import com.facebook.react.ReactInstanceManager | ||
import com.facebook.react.ReactInstanceManager.ReactInstanceEventListener | ||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.modules.network.NetworkingModule | ||
|
||
@Suppress("unused") | ||
object ReactNativeFlipper { | ||
@JvmStatic | ||
fun initialize(context: Context?, reactInstanceManager: ReactInstanceManager) { | ||
if (!FlipperUtils.shouldEnableFlipper(context)) { | ||
return | ||
} | ||
|
||
val client: FlipperClient = AndroidFlipperClient.getInstance(context) | ||
client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())) | ||
client.addPlugin(DatabasesFlipperPlugin(context)) | ||
client.addPlugin(SharedPreferencesFlipperPlugin(context)) | ||
client.addPlugin(CrashReporterPlugin.getInstance()) | ||
|
||
val networkFlipperPlugin = NetworkFlipperPlugin() | ||
NetworkingModule.setCustomClientBuilder { builder -> | ||
builder.addNetworkInterceptor(FlipperOkhttpInterceptor(networkFlipperPlugin)) | ||
} | ||
client.addPlugin(networkFlipperPlugin) | ||
|
||
client.start() | ||
|
||
// FrescoFlipperPlugin needs to ensure that ImagePipelineFactory is | ||
// initialized and must therefore be run after all native modules have | ||
// been initialized. | ||
val reactContext = reactInstanceManager.currentReactContext | ||
if (reactContext == null) { | ||
reactInstanceManager.addReactInstanceEventListener( | ||
object : ReactInstanceEventListener { | ||
override fun onReactContextInitialized(reactContext: ReactContext) { | ||
reactInstanceManager.removeReactInstanceEventListener(this) | ||
reactContext.runOnNativeModulesQueueThread { client.addPlugin(FrescoFlipperPlugin()) } | ||
} | ||
}) | ||
} else { | ||
client.addPlugin(FrescoFlipperPlugin()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.