-
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.
🆕 Add: Re-Add iOS-Related Source Files
- Loading branch information
1 parent
bd52878
commit d38b8b5
Showing
102 changed files
with
9,342 additions
and
0 deletions.
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,21 @@ | ||
// | ||
// CGSize+Init.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/28/23. | ||
// | ||
|
||
import UIKit | ||
|
||
public extension CGSize { | ||
init?(fromDict dict: NSDictionary){ | ||
guard let width = dict["width"] as? NSNumber, | ||
let height = dict["height"] as? NSNumber | ||
else { return nil }; | ||
|
||
self.init( | ||
width: width.doubleValue, | ||
height: height.doubleValue | ||
); | ||
}; | ||
}; |
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,132 @@ | ||
// | ||
// UIBlurEffect+Init.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 3/23/23. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIBlurEffect.Style: CaseIterable, CustomStringConvertible { | ||
|
||
/// The available `UIBlurEffect.Style` that can be used based on the current | ||
/// platform version | ||
/// | ||
public static var availableStyles: [UIBlurEffect.Style] { | ||
var styles: [UIBlurEffect.Style] = [ | ||
.light, | ||
.extraLight, | ||
.dark, | ||
]; | ||
|
||
if #available(iOS 10.0, *) { | ||
styles.append(contentsOf: [ | ||
.regular, | ||
.prominent, | ||
]); | ||
}; | ||
|
||
if #available(iOS 13.0, *) { | ||
styles.append(contentsOf: [ | ||
.systemUltraThinMaterial, | ||
.systemThinMaterial, | ||
.systemMaterial, | ||
.systemThickMaterial, | ||
.systemChromeMaterial, | ||
.systemMaterialLight, | ||
.systemThinMaterialLight, | ||
.systemUltraThinMaterialLight, | ||
.systemThickMaterialLight, | ||
.systemChromeMaterialLight, | ||
.systemChromeMaterialDark, | ||
.systemMaterialDark, | ||
.systemThickMaterialDark, | ||
.systemThinMaterialDark, | ||
.systemUltraThinMaterialDark, | ||
]); | ||
}; | ||
|
||
return styles; | ||
}; | ||
|
||
// MARK: - CaseIterable | ||
// -------------------- | ||
|
||
public static var allCases: [UIBlurEffect.Style] { | ||
return self.availableStyles; | ||
}; | ||
|
||
// MARK: - CustomStringConvertible | ||
// ------------------------------- | ||
|
||
/// Note:2023-03-23-23-14-57 | ||
/// | ||
/// * `UIBlurEffect.Style` is an objc enum, and as such, it's actually raw | ||
/// value internally is `Int`. | ||
/// | ||
/// * As such, `String(describing:)` a ` UIBlurEffect.Style` enum value | ||
/// outputs an `Int`. | ||
/// | ||
/// * Because of this, we have to manually map out the enum values to a string | ||
/// representation. | ||
/// | ||
public var description: String { | ||
switch self { | ||
// Adaptable Styles | ||
case .systemUltraThinMaterial: return "systemUltraThinMaterial"; | ||
case .systemThinMaterial : return "systemThinMaterial"; | ||
case .systemMaterial : return "systemMaterial"; | ||
case .systemThickMaterial : return "systemThickMaterial"; | ||
case .systemChromeMaterial : return "systemChromeMaterial"; | ||
|
||
// Light Styles | ||
case .systemMaterialLight : return "systemMaterialLight"; | ||
case .systemThinMaterialLight : return "systemThinMaterialLight"; | ||
case .systemUltraThinMaterialLight: return "systemUltraThinMaterialLight"; | ||
case .systemThickMaterialLight : return "systemThickMaterialLight"; | ||
case .systemChromeMaterialLight : return "systemChromeMaterialLight"; | ||
|
||
// Dark Styles | ||
case .systemChromeMaterialDark : return "systemChromeMaterialDark"; | ||
case .systemMaterialDark : return "systemMaterialDark"; | ||
case .systemThickMaterialDark : return "systemThickMaterialDark"; | ||
case .systemThinMaterialDark : return "systemThinMaterialDark"; | ||
case .systemUltraThinMaterialDark: return "systemUltraThinMaterialDark"; | ||
|
||
// Additional Styles | ||
case .regular : return "regular"; | ||
case .prominent : return "prominent"; | ||
case .light : return "light"; | ||
case .extraLight: return "extraLight"; | ||
case .dark : return "dark"; | ||
|
||
@unknown default: return ""; | ||
}; | ||
}; | ||
|
||
// MARK: - Init | ||
// ------------ | ||
|
||
init?(string: String){ | ||
|
||
/// Note:2023-03-23-23-21-21 | ||
/// | ||
/// * Normally, a simple `switch` + `case "foo": self = foo` would suffice, | ||
/// (especially since it's O(1) access), but the usable enum values depend | ||
/// on the platform version. | ||
/// | ||
/// * The useable enums are stored in `availableStyles`, and is used to | ||
/// communicate to JS the available enum values. | ||
/// | ||
/// * As such, we might as well re-use `availableStyles` for the parsing | ||
/// logic (even if it's less efficient). | ||
/// | ||
let style = Self.allCases.first{ | ||
$0.description == string | ||
}; | ||
|
||
guard let style = style else { return nil }; | ||
self = style; | ||
}; | ||
}; | ||
|
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,81 @@ | ||
// | ||
// UIModalPresentationStyle+Init.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 3/24/23. | ||
// | ||
|
||
import UIKit | ||
|
||
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, | ||
.pageSheet, | ||
.formSheet, | ||
.currentContext, | ||
.custom, | ||
.overFullScreen, | ||
.overCurrentContext, | ||
.popover, | ||
]; | ||
|
||
if #available(iOS 13.0, *) { | ||
styles.append(.automatic); | ||
}; | ||
|
||
#if !os(iOS) | ||
styles.append(.blurOverFullScreen); | ||
#endif | ||
|
||
return styles; | ||
}; | ||
|
||
|
||
public static var allCases: [UIModalPresentationStyle] { | ||
return self.availableStyles; | ||
}; | ||
|
||
// MARK: - CustomStringConvertible | ||
// ------------------------------- | ||
|
||
/// See: Note:2023-03-23-23-14-57 | ||
public var description: String { | ||
switch self { | ||
case .automatic : return "automatic"; | ||
case .none : return "none"; | ||
case .fullScreen : return "fullScreen"; | ||
case .pageSheet : return "pageSheet"; | ||
case .formSheet : return "formSheet"; | ||
case .currentContext : return "currentContext"; | ||
case .custom : return "custom"; | ||
case .overFullScreen : return "overFullScreen"; | ||
case .overCurrentContext: return "overCurrentContext"; | ||
case .popover : return "popover"; | ||
|
||
#if !os(iOS) | ||
case .blurOverFullScreen: return "blurOverFullScreen"; | ||
#endif | ||
|
||
@unknown default: return ""; | ||
}; | ||
}; | ||
|
||
|
||
// 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; | ||
}; | ||
}; |
67 changes: 67 additions & 0 deletions
67
ios/Extensions+Init/UISheetPresentationController+Init.swift
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,67 @@ | ||
// | ||
// UISheetPresentationController+Init.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/21/23. | ||
// | ||
|
||
import UIKit | ||
|
||
|
||
@available(iOS 15.0, *) | ||
extension UISheetPresentationController.Detent { | ||
|
||
// <UISheetPresentationControllerDetent: 0x600000e8f510: | ||
// _type=medium -> 2, | ||
// _identifier=com.apple.UIKit.medium | ||
// > | ||
// | ||
// <UISheetPresentationControllerDetent: 0x600000e8ffc0: | ||
// _type=large -> 1, | ||
// _identifier=com.apple.UIKit.large | ||
// > | ||
|
||
static func fromString( | ||
_ string: String | ||
) -> UISheetPresentationController.Detent? { | ||
|
||
switch string { | ||
case "medium": return .medium(); | ||
case "large" : return .large(); | ||
|
||
default: return nil; | ||
}; | ||
}; | ||
}; | ||
|
||
@available(iOS 15.0, *) | ||
extension UISheetPresentationController.Detent.Identifier: | ||
CustomStringConvertible { | ||
|
||
public var description: String { | ||
switch self { | ||
case .medium: return "medium"; | ||
case .large : return "large"; | ||
|
||
default: return self.rawValue; | ||
}; | ||
}; | ||
|
||
init?(fromSystemIdentifierString string: String) { | ||
switch string { | ||
case "medium": self = .medium; | ||
case "large" : self = .large; | ||
|
||
default: return nil; | ||
}; | ||
}; | ||
|
||
init(fromString string: String) { | ||
if let systemIdentifier = Self.init(fromSystemIdentifierString: string) { | ||
self = systemIdentifier; | ||
|
||
} else { | ||
self.init(string); | ||
}; | ||
}; | ||
}; |
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,61 @@ | ||
// | ||
// CAAnimation+Block.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/1/23. | ||
// | ||
|
||
import UIKit | ||
|
||
|
||
public class CAAnimationBlockDelegate: NSObject, CAAnimationDelegate { | ||
|
||
public typealias StartBlock = (CAAnimation) -> (); | ||
public typealias EndBlock = (CAAnimation, Bool) -> (); | ||
|
||
var onStartBlock: StartBlock? | ||
var onEndBlock: EndBlock? | ||
|
||
public func animationDidStart(_ anim: CAAnimation) { | ||
self.onStartBlock?(anim); | ||
}; | ||
|
||
public func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { | ||
self.onEndBlock?(anim, flag); | ||
}; | ||
}; | ||
|
||
public extension CAAnimation { | ||
|
||
private var multicastDelegate: CAAnimationMulticastDelegate { | ||
guard let delegate = self.delegate else { | ||
return CAAnimationMulticastDelegate(); | ||
}; | ||
|
||
guard let multicastDelegate = delegate as? CAAnimationMulticastDelegate else { | ||
let multicastDelegate = CAAnimationMulticastDelegate(); | ||
multicastDelegate.emitter.add(delegate); | ||
|
||
self.speed = 0; | ||
|
||
self.delegate = multicastDelegate; | ||
return multicastDelegate; | ||
}; | ||
|
||
return multicastDelegate; | ||
}; | ||
|
||
func startBlock(_ callback: @escaping CAAnimationBlockDelegate.StartBlock) { | ||
let blockDelegate = CAAnimationBlockDelegate(); | ||
self.multicastDelegate.emitter.add(blockDelegate); | ||
|
||
blockDelegate.onStartBlock = callback; | ||
}; | ||
|
||
func endBlock(_ callback: @escaping CAAnimationBlockDelegate.EndBlock) { | ||
let blockDelegate = CAAnimationBlockDelegate(); | ||
self.multicastDelegate.emitter.add(blockDelegate); | ||
|
||
blockDelegate.onEndBlock = callback; | ||
}; | ||
}; |
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,17 @@ | ||
// | ||
// CAAnimation+Helpers.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/1/23. | ||
// | ||
|
||
import UIKit | ||
|
||
public extension CAAnimation { | ||
func waitUntiEnd(_ block: @escaping () -> Void){ | ||
DispatchQueue.main.asyncAfter( | ||
deadline: .now() + self.duration, | ||
execute: block | ||
); | ||
}; | ||
}; |
Oops, something went wrong.