Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Fix editor launch freeze in debug mode when packager isn't running #29859

Merged
merged 3 commits into from
Mar 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import Network
import Aztec

// IMPORTANT: if you're seeing a warning with this import, keep in mind it's marked as a Swift
Expand Down Expand Up @@ -45,15 +46,6 @@ public class Gutenberg: NSObject {
return !bridge.isLoading
}

public var logThreshold: LogLevel {
get {
return LogLevel(RCTGetLogThreshold())
}
set {
RCTSetLogThreshold(RCTLogLevel(newValue))
}
}

private let bridgeModule = RNReactNativeGutenbergBridge()
private unowned let dataSource: GutenbergBridgeDataSource

Expand Down Expand Up @@ -106,7 +98,6 @@ public class Gutenberg: NSObject {
self.extraModules = extraModules
super.init()
bridgeModule.dataSource = dataSource
logThreshold = isPackagerRunning ? .trace : .error
}

public func invalidate() {
Expand Down Expand Up @@ -195,11 +186,6 @@ public class Gutenberg: NSObject {
bridgeModule.sendEventIfNeeded(.setFocusOnTitle, body: nil)
}

private var isPackagerRunning: Bool {
let url = sourceURL(for: bridge)
return !(url?.isFileURL ?? true)
}

public func updateTheme(_ editorTheme: GutenbergEditorTheme?) {

var themeUpdates = [String : Any]()
Expand All @@ -222,6 +208,22 @@ public class Gutenberg: NSObject {

extension Gutenberg: RCTBridgeDelegate {
public func sourceURL(for bridge: RCTBridge!) -> URL! {
#if DEBUG
var isOnCellularNetwork = false
let monitor = NWPathMonitor()
let semaphore = DispatchSemaphore(value: 0)
monitor.pathUpdateHandler = { path in
isOnCellularNetwork = path.isExpensive
semaphore.signal()
}
let monitorQueue = DispatchQueue(label: "org.wordpress.network-path-monitor")
monitor.start(queue: monitorQueue)
semaphore.wait(timeout: .distantFuture)
monitor.cancel()
if isOnCellularNetwork {
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
}
#endif
return RCTBundleURLProvider.sharedSettings()?.jsBundleURL(forBundleRoot: "index", fallbackResource: "")
}

Expand Down