Skip to content

Commit

Permalink
⭐️ Impl: ViewPositionHorizontal+Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 5, 2024
1 parent 2fd39e3 commit 72a9fcd
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
29 changes: 29 additions & 0 deletions ios/Temp/String+Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// String+Helpers.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/6/24.
//

import Foundation


public extension String {

var capitalizedFirstLetter: Self {
var copy = self;
copy.capitalizeFirstLetter();
return copy;
};

mutating func capitalizeFirstLetter() {
guard let firstLetter = self.first else {
return;
};

self.replaceSubrange(
...self.startIndex,
with: firstLetter.uppercased()
);
};
};
41 changes: 41 additions & 0 deletions ios/Temp/UIView+Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// UIView+Helpers.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/6/24.
//

import Foundation
import DGSwiftUtilities


public extension UIView {

func recursivelyFindConstraint(
withIdentifier identifier: String
) -> NSLayoutConstraint? {

var indexOfConstraintInView: Int?;

let match = self.recursivelyFindSubview {
let match = $0.constraints.enumerated().first {
$0.element.identifier == identifier;
};

guard let match = match else {
return false;
};

indexOfConstraintInView = match.offset;
return true;
};

guard let match = match,
let indexOfConstraintInView = indexOfConstraintInView
else {
return nil;
};

return match.constraints[indexOfConstraintInView];
};
};
44 changes: 43 additions & 1 deletion ios/Temp/ViewPositionHorizontal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
//

import Foundation

import DGSwiftUtilities

public enum ViewPositionHorizontal {

public typealias Identifier = ViewPositionHorizontalIdentifier;

// MARK: - Case Members
// --------------------

case stretch;
case stretchPercent(percent: CGFloat);

Expand Down Expand Up @@ -357,3 +363,39 @@ public enum ViewPositionHorizontal {
return constraints;
};
};

// MARK: ViewPositionHorizontal+Helpers
// ------------------------------------

public extension ViewPositionHorizontal {

func findConstraint(
inConstraints constraints: [NSLayoutConstraint],
withIdentifier identifierPreset: Identifier
) -> NSLayoutConstraint? {

constraints.first {
$0.identifier == identifierPreset.identifier;
};
};

func findConstraint(
inView view: UIView,
withIdentifier identifierPreset: Identifier
) -> NSLayoutConstraint? {

view.constraints.first {
$0.identifier == identifierPreset.identifier;
};
};

func recursivelyFindConstraint(
inView view: UIView,
withIdentifier identifierPreset: Identifier
) -> NSLayoutConstraint? {

view.recursivelyFindConstraint(
withIdentifier: identifierPreset.identifier
);
};
};
26 changes: 26 additions & 0 deletions ios/Temp/ViewPositionHorizontalIdentifiers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ViewPositionHorizontalIdentifiers.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/6/24.
//

import Foundation
import DGSwiftUtilities

public enum ViewPositionHorizontalIdentifier: String {
case leading;
case trailing;
case width;
case centerX;
case leadingMin;
case trailingMin;

public var identifier: String {
let prefix = "generatedHorizontalPosition";
let suffix = "Constraint";

let center = self.rawValue.capitalizedFirstLetter;
return prefix + center + suffix;
};
};

0 comments on commit 72a9fcd

Please sign in to comment.