Skip to content

Commit

Permalink
⭐️ Impl: ModalSheetBottomAttachedOverlayLayoutConfigPreset
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 5, 2024
1 parent 25bd33b commit aca4b64
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ios/ModalSheet/ModalSheetBottomAttachedOverlayLayoutConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import Foundation

public struct ModalSheetBottomAttachedOverlayLayoutConfig {

typealias Presets = ModalSheetBottomAttachedOverlayLayoutConfigPreset;

// MARK: - Properties
// ------------------

public var horizontalPositionMode: ViewPositionHorizontal;

public var marginLeft: CGFloat;
Expand All @@ -18,6 +23,9 @@ public struct ModalSheetBottomAttachedOverlayLayoutConfig {
public var marginBottom: ModalSheetBottomDistance;
public var paddingBottom: ModalSheetBottomDistance;

// MARK: - Init
// ------------

init(
horizontalPositionMode: ViewPositionHorizontal,
marginLeft: CGFloat = 0,
Expand All @@ -32,6 +40,9 @@ public struct ModalSheetBottomAttachedOverlayLayoutConfig {
self.paddingBottom = paddingBottom;
};

// MARK: - Functions
// -----------------

public func createExternalHorizontalConstraints(
forView childView: UIView,
attachingTo parentView: UIView,
Expand Down Expand Up @@ -75,3 +86,12 @@ public struct ModalSheetBottomAttachedOverlayLayoutConfig {
);
};
};

// MARK: - ModalSheetBottomAttachedOverlayLayoutConfig+StaticAlias
// ---------------------------------------------------------------

public extension ModalSheetBottomAttachedOverlayLayoutConfig {

static let `default`: Self =
ModalSheetBottomAttachedOverlayLayoutConfigPreset.stretchWithSafeAreaPadding.config;
};
164 changes: 164 additions & 0 deletions ios/ModalSheet/ModalSheetBottomAttachedOverlayLayoutConfigPreset.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//
// ModalSheetBottomAttachedOverlayLayoutConfigPreset.swift
// react-native-ios-modal
//
// Created by Dominic Go on 10/6/24.
//

import Foundation

/// These are mainly used for testing
///
public enum ModalSheetBottomAttachedOverlayLayoutConfigPreset: String, CaseIterable {

case stretchWithSafeAreaPadding;

case centerFloatStretch80Percent;
case centerAttachedStretch90Percent;

case leadingFloatStretchQuarter;
case leadingFloatStretchHalf;
case leadingFloatStretchThreeQuarters;

case trailingFloatStretchQuarter;
case trailingFloatStretchHalf;
case trailingFloatStretchThreeQuarters;

case leadingAttachedStretchQuarter;
case leadingAttachedStretchHalf;
case leadingAttachedStretchThreeQuarters;

case trailingAttachedStretchQuarter;
case trailingAttachedStretchHalf;
case trailingAttachedStretchThreeQuarters;

// MARK: - Computed Properties
// ---------------------------

public var config: ModalSheetBottomAttachedOverlayLayoutConfig {
switch self {
case .stretchWithSafeAreaPadding:
return .init(
horizontalPositionMode: .stretch,
paddingBottom: .safeArea(
additionalValue: 0,
minValue: 0
)
);

case .centerFloatStretch80Percent:
return .init(
horizontalPositionMode: .centerStretch(percent: 0.8),
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .centerAttachedStretch90Percent:
return .init(
horizontalPositionMode: .centerStretch(percent: 0.9),
paddingBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .leadingFloatStretchQuarter:
return .init(
horizontalPositionMode: .leadingStretch(percent: 0.25),
marginLeft: 12,
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .leadingFloatStretchHalf:
return .init(
horizontalPositionMode: .leadingStretch(percent: 0.5),
marginLeft: 12,
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .leadingFloatStretchThreeQuarters:
return .init(
horizontalPositionMode: .leadingStretch(percent: 0.75),
marginLeft: 12,
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .trailingFloatStretchQuarter:
return .init(
horizontalPositionMode: .trailingStretch(percent: 0.25),
marginRight: 12,
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .trailingFloatStretchHalf:
return .init(
horizontalPositionMode: .trailingStretch(percent: 0.5),
marginRight: 12,
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .trailingFloatStretchThreeQuarters:
return .init(
horizontalPositionMode: .trailingStretch(percent: 0.75),
marginRight: 12,
marginBottom: .safeArea(
additionalValue: 0,
minValue: 12
)
);

case .leadingAttachedStretchQuarter:
return .init(
horizontalPositionMode: .leadingStretch(percent: 0.25),
paddingBottom: .safeArea(minValue: 12)
);

case .leadingAttachedStretchHalf:
return .init(
horizontalPositionMode: .leadingStretch(percent: 0.5),
paddingBottom: .safeArea(minValue: 12)
);

case .leadingAttachedStretchThreeQuarters:
return .init(
horizontalPositionMode: .leadingStretch(percent: 0.75),
paddingBottom: .safeArea(minValue: 12)
);

case .trailingAttachedStretchQuarter:
return .init(
horizontalPositionMode: .trailingStretch(percent: 0.25),
paddingBottom: .safeArea(minValue: 12)
);

case .trailingAttachedStretchHalf:
return .init(
horizontalPositionMode: .trailingStretch(percent: 0.5),
paddingBottom: .safeArea(minValue: 12)
);

case .trailingAttachedStretchThreeQuarters:
return .init(
horizontalPositionMode: .trailingStretch(percent: 0.5),
paddingBottom: .safeArea(minValue: 12)
);
};
};
};

0 comments on commit aca4b64

Please sign in to comment.