Skip to content

Commit

Permalink
💫 Update: ModalView.modalSheetDetents Prop
Browse files Browse the repository at this point in the history
Summary: Update `ModalView.modalSheetDetents` to support `RNIComputableOffset`.
  • Loading branch information
dominicstop committed Apr 28, 2023
1 parent ae02c09 commit df4d829
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct RNIModalCustomSheetDetent {
let mode: RNIModalCustomSheetDetentMode;
let key: String;

let offset: RNIComputableOffset?;

let onDetentDidCreate: OnDetentDidCreate?;

init?(
Expand Down Expand Up @@ -64,6 +66,8 @@ struct RNIModalCustomSheetDetent {

guard let mode = mode else { return nil };
self.mode = mode;

self.offset = RNIComputableOffset(fromDict: dict as NSDictionary);
};

@available(iOS 15.0, *)
Expand All @@ -75,19 +79,30 @@ struct RNIModalCustomSheetDetent {

@available(iOS 16.0, *)
var synthesizedDetent: UISheetPresentationController.Detent {
return .custom(identifier: self.synthesizedDetentIdentifier) {
return .custom(identifier: self.synthesizedDetentIdentifier) { context in


let computedValueBase: Double = {
switch self.mode {
case let .relative(value):
return value * context.maximumDetentValue;

case let .constant(value):
return value;
};
}();

let computedValueWithOffset =
self.offset?.compute(withValue: computedValueBase);

let computedValue = computedValueWithOffset ?? computedValueBase;

self.onDetentDidCreate?(
$0.containerTraitCollection,
$0.maximumDetentValue
);

switch self.mode {
case let .relative(value):
return value * $0.maximumDetentValue;

case let .constant(value):
return value;
};
}
return computedValue;
};
};
};
6 changes: 4 additions & 2 deletions src/types/RNIModalTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// prettier-ignore
/* eslint-disable prettier/prettier */

import type { RNIComputableOffset } from "./RNIComputable";

/** Maps to `RNIModalCustomSheetDetent` */
export type RNIModalCustomSheetDetent = {
export type RNIModalCustomSheetDetent = Partial<RNIComputableOffset> & {
mode: 'relative';
key: string;
sizeMultiplier: number;
Expand Down

0 comments on commit df4d829

Please sign in to comment.