Skip to content

Commit

Permalink
⭐️ Impl: UIModalPresentationStyle+Init
Browse files Browse the repository at this point in the history
Related:
* TODO:2023-03-04-06-34-28 - Library Native Cleanup
* TODO:2023-03-22-13-18-14 - Refactor: Move `fromString` to enum init

Summary:
* Impl. `UIModalPresentationStyle+Init`.
* Remove `UIModalPresentationStyle+Helpers`.
* Replace `UIModalPresentationStyle+Helpers`'s `UIModalPresentationStyle.fromString` usage w/ `UIModalPresentationStyle+Init`'s  + `UIModalPresentationStyle.init`.
  • Loading branch information
dominicstop committed Mar 24, 2023
1 parent 2684696 commit 983f359
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
//
// UIModalPresentationStyle+Helpers.swift
// nativeUIModulesTest
// UIModalPresentationStyle+Init.swift
// react-native-ios-modal
//
// Created by Dominic Go on 6/28/20.
// Created by Dominic Go on 3/24/23.
//

import Foundation

extension UIModalPresentationStyle: CaseIterable {
extension UIModalPresentationStyle: CaseIterable, CustomStringConvertible {

/// The available `UIModalPresentationStyle` that can be used based on the
/// current platform version
///
public static var availableStyles: [UIModalPresentationStyle] {
var styles: [UIModalPresentationStyle] = [
.fullScreen,
Expand All @@ -30,12 +34,17 @@ extension UIModalPresentationStyle: CaseIterable {

return styles;
};


public static var allCases: [UIModalPresentationStyle] {
return self.availableStyles;
};

func stringDescription() -> String {
// MARK: - CustomStringConvertible
// -------------------------------

/// See: Note:2023-03-23-23-14-57
public var description: String {
switch self {
case .automatic : return "automatic";
case .none : return "none";
Expand All @@ -56,11 +65,17 @@ extension UIModalPresentationStyle: CaseIterable {
};
};

static func fromString(_ string: String) -> UIModalPresentationStyle? {
return self.allCases.first{ $0.stringDescription() == string };
};

static func fromString(_ string: NSString) -> UIModalPresentationStyle? {
return self.fromString(string as String);
// MARK: - Init
// ------------

init?(string: String){
/// See: Note:2023-03-23-23-21-21
let style = Self.allCases.first{
$0.description == string
};

guard let style = style else { return nil };
self = style;
};
};
8 changes: 4 additions & 4 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class RNIModalView: UIView, RNIModalPresentation {
guard #available(iOS 13.0, *) else { return .overFullScreen };
return .automatic;
}();
// TODO:2023-03-22-13-18-14 - Refactor: Move `fromString` to enum init
guard let style = UIModalPresentationStyle.fromString(self.modalPresentationStyle)
else {

guard let style = UIModalPresentationStyle(
string: self.modalPresentationStyle as String
) else {
#if DEBUG
print(
"RNIModalView - synthesizedModalPresentationStyle: Unable to parse "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RNIModalViewManager: RCTViewManager {
.availableStyles.map { $0.description },

"availablePresentationStyles": UIModalPresentationStyle
.availableStyles.map { $0.stringDescription() },
.availableStyles.map { $0.description },
];
};
};
Expand Down

0 comments on commit 983f359

Please sign in to comment.