-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐️ Impl:
ViewPositionHorizontal+Helpers
- Loading branch information
1 parent
2fd39e3
commit 72a9fcd
Showing
4 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
}; |