Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CM-1243] Support for reduce motion accessibility. #15

Merged
merged 4 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/YBottomSheet/Animation/BottomSheetAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class BottomSheetAnimator: NSObject {
/// Bottom sheet controller.
let sheetViewController: BottomSheetController

/// Accessibility reduce motion is enabled or not.
var isReduceMotionEnabled: Bool {
get {
UIAccessibility.isReduceMotionEnabled
mpospese marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Initializes a bottom sheet animator.
/// - Parameter sheetViewController: the sheet being animated.
init(sheetViewController: BottomSheetController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class BottomSheetDismissAnimator: BottomSheetAnimator {
delay: .zero,
options: [.beginFromCurrentState, sheet.appearance.dismissAnimationCurve]
) {
sheet.sheetView.frame = sheetFrame
if !self.isReduceMotionEnabled {
sheet.sheetView.frame = sheetFrame
}
mpospese marked this conversation as resolved.
Show resolved Hide resolved
} completion: { _ in
if !transitionContext.transitionWasCancelled {
fromViewController.view.removeFromSuperview()
Expand Down
12 changes: 7 additions & 5 deletions Sources/YBottomSheet/Animation/BottomSheetPresentAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class BottomSheetPresentAnimator: BottomSheetAnimator {
sheet.view.layoutSubviews()
sheet.dimmerView.alpha = 0

let toFinalFrame = transitionContext.finalFrame(for: toViewController)
var sheetFrame = sheet.sheetView.frame
sheetFrame.origin.y = toFinalFrame.maxY + (sheet.appearance.elevation?.extent.top ?? 0)
sheet.sheetView.frame = sheetFrame
sheet.view.setNeedsLayout()
if !isReduceMotionEnabled {
let toFinalFrame = transitionContext.finalFrame(for: toViewController)
var sheetFrame = sheet.sheetView.frame
sheetFrame.origin.y = toFinalFrame.maxY + (sheet.appearance.elevation?.extent.top ?? 0)
sheet.sheetView.frame = sheetFrame
sheet.view.setNeedsLayout()
}
mpospese marked this conversation as resolved.
Show resolved Hide resolved

let duration = transitionDuration(using: transitionContext)

Expand Down