mirror of
https://github.com/RSSNext/Folo.git
synced 2026-10-29 03:46:58 +08:00
- Refactored WebViewManager to improve lifecycle management and state handling. - Introduced a debug panel for monitoring WebView state and actions in development mode. - Updated JavaScript injection methods to use a centralized dispatch system for better maintainability. - Improved handling of local HTML loading and state replay after process termination. - Added new functions for debugging, including state retrieval and flushing pending scripts. This update aims to enhance the overall performance and usability of the WebView component, providing developers with better tools for debugging and state management. Signed-off-by: Innei <tukon479@gmail.com>
49 lines
1.2 KiB
Swift
49 lines
1.2 KiB
Swift
import Combine
|
|
import ExpoModulesCore
|
|
import SnapKit
|
|
import SwiftUI
|
|
import WebKit
|
|
|
|
class WebViewView: ExpoView {
|
|
private var cancellable: AnyCancellable?
|
|
|
|
required init(appContext: AppContext? = nil) {
|
|
super.init(appContext: appContext)
|
|
|
|
clipsToBounds = true
|
|
cancellable = WebViewManager.state.$contentHeight
|
|
.receive(on: DispatchQueue.main)
|
|
.sink { [weak self] _ in
|
|
self?.layoutSubviews()
|
|
}
|
|
}
|
|
|
|
deinit {
|
|
cancellable?.cancel()
|
|
}
|
|
|
|
private let onContentHeightChange = ExpoModulesCore.EventDispatcher()
|
|
|
|
override func layoutSubviews() {
|
|
let rect = CGRect(
|
|
x: bounds.origin.x,
|
|
y: bounds.origin.y,
|
|
width: bounds.width,
|
|
height: WebViewManager.state.contentHeight
|
|
)
|
|
WebViewManager.updateFrame(rect)
|
|
frame = rect
|
|
onContentHeightChange(["height": Float(rect.height)])
|
|
|
|
}
|
|
|
|
override func didMoveToWindow() {
|
|
super.didMoveToWindow()
|
|
if window != nil {
|
|
WebViewManager.attach(to: self)
|
|
} else {
|
|
WebViewManager.detach(from: self)
|
|
}
|
|
}
|
|
}
|