Skip to content

Commit

Permalink
⭐️ Impl: RNIContentViewController Scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 7, 2024
1 parent de7e9d7 commit 9a581eb
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,82 @@ import UIKit
import DGSwiftUtilities
import react_native_ios_utilities


public class RNIModalSheetBottomAttachedOverlayController:
ModalSheetBottomAttachedOverlayController {

public var reactParentView: RNIContentViewParentDelegate?;

public override func setupContent() {
defer {
super.setupContent();
};

// MARK: TODO TEMP!
self.contentController = DummyContentController();
self.view.backgroundColor = .red;
guard let reactParentView = self.reactParentView else {
return;
};

let childVC = RNIContentViewController();
self.contentController = childVC;

childVC.reactContentParentView = reactParentView;
childVC.contentSizingMode = .sizingHeightFromReactAndWidthFromNative;

//self.contentController = DummyContentController();

};
};

// MARK: TODO - TEMP!
// MARK: - RNIContentViewController+RNIViewLifecycle
// -------------------------------------------------

extension RNIContentViewController: RNIViewLifecycle {

public func notifyOnUpdateLayoutMetrics(
sender: RNIContentViewParentDelegate,
oldLayoutMetrics: RNILayoutMetrics,
newLayoutMetrics: RNILayoutMetrics
) {

guard self.contentSizingMode.isSizingWidthOrHeightFromReact else {
return;
};

self.view.setNeedsLayout();

return;
self.view.updateConstraints()
self.reactContentParentView?.invalidateIntrinsicContentSize();

print(
"RNIContentViewController.\(#function)",
"\n - reactContentParentView.intrinsicContentSize", self.reactContentParentView?.intrinsicContentSize.debugDescription ?? "N/A",
"\n - reactContentParentView.intrinsicContentSize", self.reactContentParentView?.intrinsicContentSizeOverride.debugDescription ?? "N/A",
"\n - arg oldLayoutMetrics.frame", oldLayoutMetrics.frame.size.debugDescription,
"\n - arg oldLayoutMetrics.contentFrame", oldLayoutMetrics.contentFrame.size,
"\n - arg newLayoutMetrics", newLayoutMetrics.frame.size.debugDescription,
"\n - arg newLayoutMetrics.contentFrame", oldLayoutMetrics.contentFrame.size,
"\n"
);
}
};




public class DummyContentController: UIViewController {
public override func viewDidLoad() {
self.view.backgroundColor = .blue;

let size = self.view.bounds.size;

self.view.translatesAutoresizingMaskIntoConstraints = false;
NSLayoutConstraint.activate([
self.view.heightAnchor.constraint(equalToConstant: 100),
]);
};

public override func viewWillLayoutSubviews() {
let size = self.view.bounds.size;
print(size);
}
};
20 changes: 8 additions & 12 deletions ios/RNIModalSheetView/RNIModalSheetViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,14 @@ public final class RNIModalSheetViewDelegate: UIView, RNIContentView {
modalVC.modalLifecycleEventDelegates.add(self);
modalVC.sheetPresentationStateMachine.eventDelegates.add(self);
modalVC.modalFocusEventDelegates.add(self);

// TODO: TEMP!!
let childVC = RNIModalSheetBottomAttachedOverlayController();
modalVC.bottomOverlayController = childVC;

// if let sheetBottomAttachedOverlayParentView = self.sheetBottomAttachedOverlayParentView {
// let childVC = RNIModalSheetBottomAttachedOverlayController();
// self.sheetBottomAttachedOverlayController = childVC;
// modalVC.bottomAttachedOverlayController = childVC;
//
// childVC.mainContentView = sheetBottomAttachedOverlayParentView;
// };

if let sheetBottomAttachedOverlayParentView = self.sheetBottomAttachedOverlayParentView {
let childVC = RNIModalSheetBottomAttachedOverlayController();
self.sheetBottomAttachedOverlayController = childVC;
modalVC.bottomOverlayController = childVC;

childVC.reactParentView = sheetBottomAttachedOverlayParentView;
};

return modalVC;
};
Expand Down
113 changes: 113 additions & 0 deletions ios/Temp/RNIContentViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// RNIContentViewController.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/7/24.
//

import UIKit
import DGSwiftUtilities
import react_native_ios_utilities


public class RNIContentViewController: UIViewController {

public typealias ContentSizingMode = RNIContentSizingMode;
public typealias ContentPositioningMode = RNIContentPositioningMode;

// MARK: - Properties
// ------------------

public var contentSizingMode: ContentSizingMode = .sizingFromNative;
public var contentPositioningMode: ContentPositioningMode = .stretch;

public var nativeViewHeightConstraint: NSLayoutConstraint?;
public var nativeViewWidthConstraint: NSLayoutConstraint?;

public var reactContentParentView: RNIContentViewParentDelegate?;

// MARK: - View Controller Lifecycle
// ---------------------------------

public override func loadView() {
super.loadView();
};

public override func viewDidLoad() {
guard let reactContentParentView = self.reactContentParentView else {
return;
};

reactContentParentView.reactViewLifecycleDelegates.add(self);

reactContentParentView.translatesAutoresizingMaskIntoConstraints = false;
self.view.addSubview(reactContentParentView);

let constraints = self.contentPositioningMode.createConstraints(
forView: reactContentParentView,
attachingTo: self.view
);

// self.nativeViewHeightConstraint = self.view.heightAnchor.constraint(
// equalToConstant: reactContentParentView.cachedLayoutMetrics?.frame.height ?? 0
// );



// constraints.append(
// self.view.heightAnchor.constraint(
// equalTo: reactContentParentView.heightAnchor
// )
// );
//
// let constraints = [
// reactContentParentView.leadingAnchor.constraint(
// equalTo: self.view.leadingAnchor
// ),
// reactContentParentView.trailingAnchor.constraint(
// equalTo: self.view.trailingAnchor
// ),
// reactContentParentView.bottomAnchor.constraint(
// equalTo: self.view.bottomAnchor
// ),
// self.view.heightAnchor.constraint(
// equalTo: reactContentParentView.heightAnchor
// ),
// ];



// self.view.backgroundColor = .red;



NSLayoutConstraint.activate(constraints);

// MARK: Set Initial Size
let newSize = self.view.bounds.size;
let hasValidSize = !newSize.isZero;

if hasValidSize {
self.contentSizingMode.updateReactSizeIfNeeded(
forReactParent: reactContentParentView,
withNewSize: newSize
);
};
};

public override func viewWillLayoutSubviews() {
self.updateSizeIfNeeded();
};

public func updateSizeIfNeeded(){
guard let reactContentParentView = self.reactContentParentView else {
return;
};

let newSize = self.view.bounds.size;
self.contentSizingMode.updateReactSizeIfNeeded(
forReactParent: reactContentParentView,
withNewSize: newSize
);
};
};

0 comments on commit 9a581eb

Please sign in to comment.