Skip to content

Commit

Permalink
💫 Update: ModalView.onModalDetentDidCompute
Browse files Browse the repository at this point in the history
Summary: Update `ModalView.onModalDetentDidCompute` event - add event argument `computedDetentValue`, and `key`.
  • Loading branch information
dominicstop committed Apr 28, 2023
1 parent df4d829 commit 82f5abc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ struct RNIModalCustomSheetDetent {

typealias OnDetentDidCreate = (
_ containerTraitCollection: UITraitCollection,
_ maximumDetentValue: CGFloat
_ maximumDetentValue: CGFloat,
_ computedDetentValue: CGFloat,
_ sender: RNIModalCustomSheetDetent
) -> Void;

let mode: RNIModalCustomSheetDetentMode;
Expand Down Expand Up @@ -81,7 +83,6 @@ struct RNIModalCustomSheetDetent {
var synthesizedDetent: UISheetPresentationController.Detent {
return .custom(identifier: self.synthesizedDetentIdentifier) { context in


let computedValueBase: Double = {
switch self.mode {
case let .relative(value):
Expand All @@ -98,8 +99,10 @@ struct RNIModalCustomSheetDetent {
let computedValue = computedValueWithOffset ?? computedValueBase;

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

return computedValue;
Expand Down
2 changes: 2 additions & 0 deletions ios/src_library/React Native/RNIModal/RNIModalEventData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ public struct RNIModalDidChangeSelectedDetentIdentifierEventData: RNIDictionaryS

public struct RNIModalDetentDidComputeEventData: RNIDictionarySynthesizable {
public let maximumDetentValue: CGFloat;
public let computedDetentValue: CGFloat;
public let key: String;
};
6 changes: 4 additions & 2 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,12 @@ public class RNIModalView:
let dict = $0 as? Dictionary<String, Any> {

let customDetent = RNIModalCustomSheetDetent(forDict: dict) {
_, maximumDetentValue in
_, maximumDetentValue, computedDetentValue, sender in

let eventData = RNIModalDetentDidComputeEventData(
maximumDetentValue: maximumDetentValue
maximumDetentValue: maximumDetentValue,
computedDetentValue: computedDetentValue,
key: sender.key
);

self.onModalDetentDidCompute?(
Expand Down
2 changes: 2 additions & 0 deletions src/native_components/RNIModalView/RNIModalViewEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export type OnModalDidFocusEventObject = NativeSyntheticEvent<

export type OnModalDetentDidComputeEventObject = NativeSyntheticEvent<{
maximumDetentValue: number;
computedDetentValue: number;
key: string;
}>;

export type OnModalDidChangeSelectedDetentIdentifierEventObject =
Expand Down

0 comments on commit 82f5abc

Please sign in to comment.