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

Added option for disabling snackbar layout edge inset calculation #1187

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Changes from all commits
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
30 changes: 20 additions & 10 deletions Sources/iOS/SnackbarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ open class SnackbarController: TransitionController {
layoutSubviews()
}
}

/**
A boolean that controls if layoutEdgeInsets of snackbar is adjusted
automatically.
*/
@IBInspectable
open var automaticallyAdjustSnackbarLayoutEdgeInsets = true

/**
Animates to a SnackbarStatus.
Expand Down Expand Up @@ -179,17 +186,20 @@ open class SnackbarController: TransitionController {
snackbar.frame.origin.x = snackbarEdgeInsets.left
snackbar.frame.size.width = view.bounds.width - snackbarEdgeInsets.left - snackbarEdgeInsets.right
snackbar.frame.size.height = snackbar.heightPreset.rawValue
snackbar.layoutEdgeInsets = .zero
if .bottom == snackbarAlignment {
snackbar.frame.size.height += bottomLayoutGuide.length
snackbar.layoutEdgeInsets.bottom += bottomLayoutGuide.length
} else {
snackbar.frame.size.height += topLayoutGuide.length
snackbar.layoutEdgeInsets.top += topLayoutGuide.length
}

rootViewController.view.frame = view.bounds
layoutSnackbar(status: snackbar.status)
if automaticallyAdjustSnackbarLayoutEdgeInsets {
snackbar.layoutEdgeInsets = .zero
if .bottom == snackbarAlignment {
snackbar.frame.size.height += bottomLayoutGuide.length
snackbar.layoutEdgeInsets.bottom += bottomLayoutGuide.length
} else {
snackbar.frame.size.height += topLayoutGuide.length
snackbar.layoutEdgeInsets.top += topLayoutGuide.length
}

rootViewController.view.frame = view.bounds
layoutSnackbar(status: snackbar.status)
}
}

open override func prepare() {
Expand Down