-
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.
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
- Loading branch information
1 parent
02ca95a
commit 7eac231
Showing
8 changed files
with
220 additions
and
125 deletions.
There are no files selected for viewing
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
110 changes: 32 additions & 78 deletions
110
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPointPreset.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 |
---|---|---|
@@ -1,89 +1,43 @@ | ||
// | ||
// AdaptiveModalInitialSnapPoint.swift | ||
// AdaptiveModalSnapPointPreset.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/23/23. | ||
// Created by Dominic Go on 5/31/23. | ||
// | ||
|
||
import UIKit | ||
import Foundation | ||
|
||
enum AdaptiveModalSnapPointPreset { | ||
case offscreenBottom, offscreenTop, offscreenLeft, offscreenRight; | ||
case edgeBottom, edgeTop, edgeLeft, edgeRight; | ||
case center; | ||
|
||
case layoutConfig(_ config: RNILayout); | ||
struct AdaptiveModalSnapPointPreset { | ||
|
||
let snapPointPreset: RNILayoutPreset; | ||
let animationKeyframe: AdaptiveModalAnimationConfig?; | ||
|
||
func computeSnapPoint( | ||
fromSnapPointConfig prevSnapPoint: RNILayout, | ||
withTargetRect targetRect: CGRect, | ||
currentSize: CGSize | ||
) -> RNILayout { | ||
init( | ||
snapPoint: RNILayoutPreset, | ||
animationKeyframe: AdaptiveModalAnimationConfig? = nil | ||
) { | ||
self.snapPointPreset = snapPoint; | ||
self.animationKeyframe = animationKeyframe; | ||
}; | ||
}; | ||
|
||
extension AdaptiveModalSnapPointPreset { | ||
static func getDefaultSnapPoint( | ||
forDirection direction: AdaptiveModalConfig.Direction | ||
) -> RNILayoutPreset { | ||
switch direction { | ||
case .bottomToTop: return .offscreenTop; | ||
case .topToBottom: return .offscreenBottom; | ||
case .leftToRight: return .offscreenLeft; | ||
case .rightToLeft: return .offscreenRight; | ||
}; | ||
}; | ||
|
||
let prevRect = prevSnapPoint.computeRect( | ||
withTargetRect: targetRect, | ||
currentSize: currentSize | ||
static func getDefault( | ||
forDirection direction: AdaptiveModalConfig.Direction | ||
) -> Self { | ||
Self.init( | ||
snapPoint: Self.getDefaultSnapPoint(forDirection: direction) | ||
); | ||
|
||
switch self { | ||
case .offscreenBottom: | ||
return .init( | ||
derivedFrom: prevSnapPoint | ||
); | ||
|
||
case .offscreenTop: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
verticalAlignment: .top, | ||
marginTop: -prevRect.height | ||
); | ||
|
||
case .offscreenLeft: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
horizontalAlignment: .left, | ||
marginLeft: -prevRect.width | ||
); | ||
|
||
case .offscreenRight: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
horizontalAlignment: .right, | ||
marginRight: prevRect.width | ||
); | ||
|
||
case .edgeBottom: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
verticalAlignment: .bottom | ||
); | ||
|
||
case .edgeTop: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
verticalAlignment: .top | ||
); | ||
|
||
case .edgeLeft: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
horizontalAlignment: .left | ||
); | ||
|
||
case .edgeRight: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
horizontalAlignment: .right | ||
); | ||
|
||
case .center: | ||
return .init( | ||
derivedFrom: prevSnapPoint, | ||
verticalAlignment: .center | ||
); | ||
|
||
case let .layoutConfig(config): | ||
return config; | ||
}; | ||
}; | ||
}; |
Oops, something went wrong.