diff --git a/packages/turbo/ios/RNSession.swift b/packages/turbo/ios/RNSession.swift index f9907cc3..3f9061f3 100644 --- a/packages/turbo/ios/RNSession.swift +++ b/packages/turbo/ios/RNSession.swift @@ -34,15 +34,14 @@ class RNSession: NSObject { private var visitableView: RNVisitableView? private var sessionHandle: NSString private var wkUiDelegate: WKUIDelegate? - private var sessionConfiguration: RNSessionConfiguration + private var webViewConfiguration: WKWebViewConfiguration - init(sessionHandle: NSString, sessionConfiguration: RNSessionConfiguration) { + init(sessionHandle: NSString, webViewConfiguration: WKWebViewConfiguration) { self.sessionHandle = sessionHandle - self.sessionConfiguration = sessionConfiguration + self.webViewConfiguration = webViewConfiguration } public lazy var turboSession: Session = { - let webViewConfiguration = sessionConfiguration.webViewConfiguration webViewConfiguration.userContentController.add(self, name: "nativeApp") self.wkUiDelegate = TurboUIDelegate(uiHandler: self) diff --git a/packages/turbo/ios/RNSessionConfiguration.swift b/packages/turbo/ios/RNSessionConfiguration.swift deleted file mode 100644 index 015bda7a..00000000 --- a/packages/turbo/ios/RNSessionConfiguration.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// RNSessionConfiguration.swift -// RNTurbo -// -// Created by Patryk Klatka on 22/04/2024. -// - -import Foundation - -class RNSessionConfiguration { - var sessionDelegate: RNSession? = nil { - didSet { - updateConfiguration() - } - } - - var webViewConfiguration: WKWebViewConfiguration = WKWebViewConfiguration() - var isScrollEnabled: Bool = true { - didSet { - updateConfiguration() - } - } - - func updateConfiguration() { - sessionDelegate?.webView.scrollView.isScrollEnabled = isScrollEnabled - } -} diff --git a/packages/turbo/ios/RNSessionManager.swift b/packages/turbo/ios/RNSessionManager.swift index c308e01a..9949b0a3 100644 --- a/packages/turbo/ios/RNSessionManager.swift +++ b/packages/turbo/ios/RNSessionManager.swift @@ -14,10 +14,10 @@ class RNSessionManager: NSObject { private var processPool = WKProcessPool() static var shared: RNSessionManager = RNSessionManager() - func findOrCreateSession(sessionHandle: NSString, sessionConfiguration: RNSessionConfiguration) -> RNSession { + func findOrCreateSession(sessionHandle: NSString, webViewConfiguration: WKWebViewConfiguration) -> RNSession { if(sessions[sessionHandle] == nil) { - sessionConfiguration.webViewConfiguration.processPool = processPool - sessions[sessionHandle] = RNSession(sessionHandle: sessionHandle, sessionConfiguration: sessionConfiguration) + webViewConfiguration.processPool = processPool + sessions[sessionHandle] = RNSession(sessionHandle: sessionHandle, webViewConfiguration: webViewConfiguration) } return sessions[sessionHandle]! } diff --git a/packages/turbo/ios/RNVisitableView.swift b/packages/turbo/ios/RNVisitableView.swift index 309428fa..c246f522 100644 --- a/packages/turbo/ios/RNVisitableView.swift +++ b/packages/turbo/ios/RNVisitableView.swift @@ -23,17 +23,17 @@ class RNVisitableView: UIView, RNSessionSubscriber { } @objc var applicationNameForUserAgent: NSString? = nil { didSet { - sessionConfiguration.webViewConfiguration.applicationNameForUserAgent = applicationNameForUserAgent as? String + configuration.applicationNameForUserAgent = applicationNameForUserAgent as? String } } @objc var scrollEnabled: Bool = true { didSet { - sessionConfiguration.isScrollEnabled = scrollEnabled + configuration.scrollEnabled = scrollEnabled } } @objc var pullToRefreshEnabled: Bool = true { didSet { - controller!.visitableView.allowsPullToRefresh = pullToRefreshEnabled + configuration.pullToRefreshEnabled = pullToRefreshEnabled } } @objc var onMessage: RCTDirectEventBlock? @@ -53,12 +53,17 @@ class RNVisitableView: UIView, RNSessionSubscriber { private var onAlertHandler: (() -> Void)? private lazy var session: RNSession = { - let session = RNSessionManager.shared.findOrCreateSession(sessionHandle: sessionHandle!, sessionConfiguration: sessionConfiguration) - sessionConfiguration.sessionDelegate = session + let session = RNSessionManager.shared.findOrCreateSession(sessionHandle: sessionHandle!, webViewConfiguration: configuration.webViewConfiguration) + configuration.webView = session.webView return session }() private lazy var webView: WKWebView = session.webView - private var sessionConfiguration: RNSessionConfiguration = RNSessionConfiguration() + + private lazy var configuration: RNVisitableViewConfiguration = { + let configuration = RNVisitableViewConfiguration() + configuration.visitableView = controller!.visitableView + return configuration + }() lazy var controller: RNVisitableViewController? = RNVisitableViewController(reactViewController: reactViewController(), delegate: self) @@ -97,7 +102,7 @@ class RNVisitableView: UIView, RNSessionSubscriber { controller!.endAppearanceTransition() } - sessionConfiguration.updateConfiguration() + configuration.updateWebViewConfiguration() } override func removeFromSuperview() { diff --git a/packages/turbo/ios/RNVisitableViewConfiguration.swift b/packages/turbo/ios/RNVisitableViewConfiguration.swift new file mode 100644 index 00000000..463b9a29 --- /dev/null +++ b/packages/turbo/ios/RNVisitableViewConfiguration.swift @@ -0,0 +1,46 @@ +// +// RNSessionConfiguration.swift +// RNTurbo +// +// Created by Patryk Klatka on 22/04/2024. +// + +import Foundation + +class RNVisitableViewConfiguration { + var visitableView: VisitableView? = nil { + didSet { + updateVisitableViewConfiguration() + } + } + var webView: WKWebView? = nil { + didSet { + updateWebViewConfiguration() + } + } + var webViewConfiguration: WKWebViewConfiguration = WKWebViewConfiguration() + + var pullToRefreshEnabled: Bool = true { + didSet { + updateVisitableViewConfiguration() + } + } + var applicationNameForUserAgent: String? = nil { + didSet { + webViewConfiguration.applicationNameForUserAgent = applicationNameForUserAgent + } + } + var scrollEnabled: Bool = true { + didSet { + updateWebViewConfiguration() + } + } + + func updateVisitableViewConfiguration() { + visitableView?.allowsPullToRefresh = pullToRefreshEnabled + } + + func updateWebViewConfiguration() { + webView?.scrollView.isScrollEnabled = scrollEnabled + } +}