From afb96ee862977b31015bcd2682a964a307eadf7d Mon Sep 17 00:00:00 2001 From: Orkhan Alikhanov Date: Tue, 6 Nov 2018 21:34:06 +0400 Subject: [PATCH] Added option for disabling snackbar layout edge inset calculation --- Sources/iOS/SnackbarController.swift | 30 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Sources/iOS/SnackbarController.swift b/Sources/iOS/SnackbarController.swift index 80de48142..9a84a348f 100644 --- a/Sources/iOS/SnackbarController.swift +++ b/Sources/iOS/SnackbarController.swift @@ -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. @@ -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() {