Skip to content

Commit

Permalink
fix: Make reload on PortalUIView work (#37)
Browse files Browse the repository at this point in the history
* fix: Make `reload` on `PortalUIView` work
* fix: Reload webView on main thread
* fix: Update podspec for a minimum capacitor target of 3.7. This is required to have access to the `setServerBasePath` method on CAPWebView
  • Loading branch information
Steven0351 authored Aug 4, 2022
1 parent 3f3e69a commit 6d98e8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion IonicPortals.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.authors = { 'Ionic Team' => '[email protected]' }
s.source = { :git => 'https://github.com/ionic-team/ionic-portals-ios.git', :tag => s.version.to_s }
s.source_files = 'Sources/IonicPortals/*.swift'
s.dependency 'Capacitor', '~> 3.5'
s.dependency 'Capacitor', '~> 3.7'
s.dependency 'IonicLiveUpdates', '~> 0.1.2'
s.swift_version = '5.4'
end
18 changes: 7 additions & 11 deletions Sources/IonicPortals/PortalUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,16 @@ public class PortalUIView: UIView {

/// Reloads the underlying `WKWebView`
@objc public func reload() {
guard
let liveUpdate = portal.liveUpdateConfig,
let capViewController = bridge.viewController as? CAPBridgeViewController,
let latestAppPath = try? portal.liveUpdateManager.latestAppDirectory(for: liveUpdate.appId)
else { return }

if liveUpdatePath == nil || liveUpdatePath?.path != latestAppPath.path {
if let liveUpdate = portal.liveUpdateConfig,
let latestAppPath = try? portal.liveUpdateManager.latestAppDirectory(for: liveUpdate.appId),
liveUpdatePath == nil || liveUpdatePath?.path != latestAppPath.path {
liveUpdatePath = latestAppPath
capViewController.setServerBasePath(path: liveUpdatePath!.path)
return
return webView.setServerBasePath(path: latestAppPath.path)
}

// Reload the bridge to the existing start url
bridge.webView?.reload()
DispatchQueue.main.async { [weak self] in
self?.bridge.webView?.reload()
}
}

class InternalCapWebView: CAPWebView {
Expand Down

0 comments on commit 6d98e8e

Please sign in to comment.