diff --git a/ios/Temp/String+Helpers.swift b/ios/Temp/String+Helpers.swift new file mode 100644 index 0000000..1cac199 --- /dev/null +++ b/ios/Temp/String+Helpers.swift @@ -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() + ); + }; +}; diff --git a/ios/Temp/UIView+Helpers.swift b/ios/Temp/UIView+Helpers.swift new file mode 100644 index 0000000..1bc054d --- /dev/null +++ b/ios/Temp/UIView+Helpers.swift @@ -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]; + }; +}; diff --git a/ios/Temp/ViewPositionHorizontal.swift b/ios/Temp/ViewPositionHorizontal.swift index 2917f5c..3b0a088 100644 --- a/ios/Temp/ViewPositionHorizontal.swift +++ b/ios/Temp/ViewPositionHorizontal.swift @@ -6,9 +6,15 @@ // import Foundation - +import DGSwiftUtilities public enum ViewPositionHorizontal { + + public typealias Identifier = ViewPositionHorizontalIdentifier; + + // MARK: - Case Members + // -------------------- + case stretch; case stretchPercent(percent: CGFloat); @@ -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 + ); + }; +}; diff --git a/ios/Temp/ViewPositionHorizontalIdentifiers.swift b/ios/Temp/ViewPositionHorizontalIdentifiers.swift new file mode 100644 index 0000000..ed5559d --- /dev/null +++ b/ios/Temp/ViewPositionHorizontalIdentifiers.swift @@ -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; + }; +};