ssap_app/node_modules/react-native-screens/ios/gamma/split-view/RNSSplitViewNavigationContr...

47 lines
1.8 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
import UIKit
/// @brief A protocol that observes origin changes in a RNSSplitViewNavigationControllers view frame.
///
/// The subscriber will be notified when the view's origin changes.
protocol RNSSplitViewNavigationControllerViewFrameObserver: AnyObject {
func splitViewNavCtrlViewDidChangeFrameOrigin(
_ splitViewNavCtrl: RNSSplitViewNavigationController)
}
/// @class RNSSplitViewNavigationController
/// @brief A subclass of UINavigationController, creates a view that wraps view associated with RNSSplitViewScreenController.
///
/// This subclass is responsible for tracking when the underlying view's frame origin changes,
/// allowing for syncing the ShadowTree layout.
///
/// It observes origin changes via key-value observer and notifies a delegate.
@objc
public class RNSSplitViewNavigationController: UINavigationController {
private var viewFrameObservation: NSKeyValueObservation?
weak var viewFrameOriginChangeObserver: RNSSplitViewNavigationControllerViewFrameObserver?
///
/// @brief Called after the view controllers view has been loaded.
///
/// Sets up a frame-origin Key-Value Observer to monitor view position changes and propagate them via delegate to RNSSplitViewHostController.
///
override public func viewDidLoad() {
super.viewDidLoad()
viewFrameObservation?.invalidate()
viewFrameObservation = self.view.observe(\.frame, options: [.old, .new]) {
[weak self] (view, change) in
guard let oldFrame = change.oldValue, let newFrame = change.newValue else { return }
if oldFrame.origin != newFrame.origin {
self?.onViewOriginChange()
}
}
}
private func onViewOriginChange() {
viewFrameOriginChangeObserver?.splitViewNavCtrlViewDidChangeFrameOrigin(self)
}
}