Skip to content

Commit

Permalink
Merge pull request #1187 from OrkhanAlikhanov/snackbar-layout
Browse files Browse the repository at this point in the history
Added option for disabling snackbar layout edge inset calculation
  • Loading branch information
DanielDahan authored Jan 16, 2019
2 parents 9834fd5 + afb96ee commit d3d17bb
Showing 1 changed file with 20 additions and 10 deletions.
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

0 comments on commit d3d17bb

Please sign in to comment.