-
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: Prop -
ModalView.sheetDetents
Related: * `TODO:2023-04-20-23-58-24` - Impl. sheets + detents. * `TODO:2023-04-21-00-43-59` - Impl. prop `sheetDetents`. Summary: * Native - Impl. prop `RNIModalView.modalSheetDetents`. * Native - Impl. logic for parsing system defined detents (i.e. `UISheetPresentationController+Init`). * Native - Impl. logic for parsing custom detents (i.e. `RNIModalCustomSheetDetent`). * Types - Add types that maps to `UISheetPresentationController.Detents` (i.e. `TUISheetPresentationControllerDetents`). * Types - Add types that maps to `RNIModalCustomSheetDetent`. * Impl: Prop - `ModalView.modalSheetDetents`.
- Loading branch information
1 parent
d117b26
commit 5eab7db
Showing
10 changed files
with
205 additions
and
9 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
ios/src_library/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,21 @@ | ||
// | ||
// UISheetPresentationController+Init.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/21/23. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
@available(iOS 15.0, *) | ||
extension UISheetPresentationController.Detent { | ||
static func fromString(_ string: String) -> UISheetPresentationController.Detent? { | ||
switch string { | ||
case "medium": return .medium(); | ||
case "large" : return .large(); | ||
|
||
default: return nil; | ||
}; | ||
}; | ||
}; |
93 changes: 93 additions & 0 deletions
93
ios/src_library/React Native/RNIModal/RNIModalCustomSheetDetent.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,93 @@ | ||
// | ||
// RNIModalCustomSheetDetent.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/21/23. | ||
// | ||
|
||
import Foundation | ||
|
||
enum RNIModalCustomSheetDetentMode { | ||
|
||
case relative(value: Double); | ||
case constant(value: Double); | ||
|
||
var rawValueString: String { | ||
switch self { | ||
case .constant: return "constant"; | ||
case .relative: return "relative"; | ||
}; | ||
}; | ||
}; | ||
|
||
struct RNIModalCustomSheetDetent { | ||
|
||
typealias OnDetentDidCreate = ( | ||
_ containerTraitCollection: UITraitCollection, | ||
_ maximumDetentValue: CGFloat | ||
) -> Void; | ||
|
||
let mode: RNIModalCustomSheetDetentMode; | ||
let key: String; | ||
|
||
let onDetentDidCreate: OnDetentDidCreate?; | ||
|
||
init?( | ||
forDict dict: Dictionary<String, Any>, | ||
onDetentDidCreate: OnDetentDidCreate? = nil | ||
) { | ||
guard let rawMode = dict["mode"] as? String, | ||
let rawKey = dict["key"] as? String | ||
else { return nil }; | ||
|
||
self.key = rawKey; | ||
self.onDetentDidCreate = onDetentDidCreate; | ||
|
||
let mode: RNIModalCustomSheetDetentMode? = { | ||
switch rawMode { | ||
case "relative": | ||
guard let rawValue = dict["sizeMultiplier"] as? NSNumber | ||
else { return nil }; | ||
|
||
return .relative(value: rawValue.doubleValue); | ||
|
||
case "constant": | ||
guard let rawValue = dict["sizeConstant"] as? NSNumber | ||
else { return nil }; | ||
|
||
return .constant(value: rawValue.doubleValue); | ||
|
||
default: | ||
return nil; | ||
}; | ||
}(); | ||
|
||
guard let mode = mode else { return nil }; | ||
self.mode = mode; | ||
}; | ||
|
||
@available(iOS 15.0, *) | ||
var synthesizedDetentIdentifier: | ||
UISheetPresentationController.Detent.Identifier { | ||
|
||
UISheetPresentationController.Detent.Identifier(self.key); | ||
}; | ||
|
||
@available(iOS 16.0, *) | ||
var synthesizedDetent: UISheetPresentationController.Detent { | ||
return .custom(identifier: self.synthesizedDetentIdentifier) { | ||
self.onDetentDidCreate?( | ||
$0.containerTraitCollection, | ||
$0.maximumDetentValue | ||
); | ||
|
||
switch self.mode { | ||
case let .relative(value): | ||
return value * $0.maximumDetentValue; | ||
|
||
case let .constant(value): | ||
return value; | ||
}; | ||
} | ||
}; | ||
}; |
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
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
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
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,12 @@ | ||
// prettier-ignore | ||
|
||
/** Maps to `RNIModalCustomSheetDetent` */ | ||
export type RNIModalCustomSheetDetent = { | ||
mode: 'relative'; | ||
key: string; | ||
sizeMultiplier: number; | ||
} | { | ||
mode: 'constant'; | ||
key: string; | ||
sizeConstant: number; | ||
}; |
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