Repository: expo/expo
File: packages/expo-ui/src/swift-ui/modifiers/presentationModifiers.ts (TypeScript)

Code before:
 * @param detents - Array of detents the sheet can snap to.
 * @param options - Optional settings for tracking the selected detent.
 * @param options.selection - The currently selected detent.
 * @param options.onSelectionChange - Callback fired when the user changes the active detent by dragging.
 * @platform ios 16.0+
 * @platform tvos 16.0+
 * @see Official [SwiftUI documentation](https://developer.apple.com/documentation/swiftui/view/presentationdetents(_:selection:)).
 */
export const presentationDetents = (
  detents: PresentationDetent[],
  options?: {
    selection?: PresentationDetent;
    onSelectionChange?: (detent: PresentationDetent) => void;
  }
): ModifierConfig => {
  const params = { detents, selection: options?.selection };

  if (options?.onSelectionChange) {
    return createModifierWithEventListener(
      'presentationDetents',
      (args: { detent: PresentationDetent }) => {
        options.onSelectionChange!(args.detent);
      },
      params
    );
  }

  return createModifier('presentationDetents', params);
};

/**
 * Controls the visibility of the drag indicator on a sheet.
 * @param visibility - The visibility of the drag indicator.
 * @platform ios 16.0+
 * @platform tvos 16.0+
 * @see Official [SwiftUI documentation](https://developer.apple.com/documentation/swiftui/view/presentationdragindicator(_:)).
 */
export const presentationDragIndicator = (visibility: 'automatic' | 'visible' | 'hidden') =>
  createModifier('presentationDragIndicator', { visibility });

/**
 * Presentation background interaction type.
 */
export type PresentationBackgroundInteractionType =
  | 'automatic'
  | 'enabled'
  | 'disabled'
  | { type: 'enabledUpThrough'; detent: PresentationDetent };

/**
 * Controls interaction with the content behind a sheet.

Review comment (suggestion):
```suggestion
  const { onSelectionChange } = options;
  if (onSelectionChange) {
    return createModifierWithEventListener(
      'presentationDetents',
      (args: { detent: PresentationDetent }) => {
        onSelectionChange(args.detent);
      },
      params
    );
  }
```

avoid force unwrapping

Code after:
 * @param detents - Array of detents the sheet can snap to.
 * @param options - Optional settings for tracking the selected detent.
 * @param options.selection - The currently selected detent.
 * @param options.onSelectionChange - Callback fired when the user changes the active detent by dragging.
 * @platform ios 16.0+
 * @platform tvos 16.0+
 * @see Official [SwiftUI documentation](https://developer.apple.com/documentation/swiftui/view/presentationdetents(_:selection:)).
 */
export const presentationDetents = (
  detents: PresentationDetent[],
  options?: {
    selection?: PresentationDetent;
    onSelectionChange?: (detent: PresentationDetent) => void;
  }
): ModifierConfig => {
  const params = { detents, selection: options?.selection };

  const { onSelectionChange } = options ?? {};
  if (onSelectionChange) {
    return createModifierWithEventListener(
      'presentationDetents',
      (args: { detent: PresentationDetent }) => {
        onSelectionChange(args.detent);
      },
      params
    );
  }

  return createModifier('presentationDetents', params);
};

/**
 * Controls the visibility of the drag indicator on a sheet.
 * @param visibility - The visibility of the drag indicator.
 * @platform ios 16.0+
 * @platform tvos 16.0+
 * @see Official [SwiftUI documentation](https://developer.apple.com/documentation/swiftui/view/presentationdragindicator(_:)).
 */
export const presentationDragIndicator = (visibility: 'automatic' | 'visible' | 'hidden') =>
  createModifier('presentationDragIndicator', { visibility });

/**
 * Presentation background interaction type.
 */
export type PresentationBackgroundInteractionType =
  | 'automatic'
  | 'enabled'
  | 'disabled'
  | { type: 'enabledUpThrough'; detent: PresentationDetent };

/**