@@ -87,34 +87,36 @@ private extension NoticePresenter {
8787 let noticeContainerView = NoticeContainerView ( noticeView: noticeView)
8888 addNoticeContainerToPresentingViewController ( noticeContainerView)
8989
90- let bottomConstraint = makeBottomConstraintForNoticeContainer ( noticeContainerView)
91-
9290 NSLayoutConstraint . activate ( [
9391 noticeContainerView. leadingAnchor. constraint ( equalTo: view. leadingAnchor) ,
9492 noticeContainerView. trailingAnchor. constraint ( equalTo: view. trailingAnchor) ,
95- bottomConstraint
93+ makeBottomConstraintForNoticeContainer ( noticeContainerView )
9694 ] )
9795
98- let fromState = {
96+ let offScreenState = {
9997 noticeView. alpha = UIKitConstants . alphaZero
100- bottomConstraint . constant = self . offscreenBottomOffset
98+ noticeContainerView . noticeBottomConstraint . constant = self . offscreenBottomOffset
10199
102- view . layoutIfNeeded ( )
100+ noticeContainerView . layoutIfNeeded ( )
103101 }
104102
105- let toState = {
103+ let onScreenState = {
106104 noticeView. alpha = UIKitConstants . alphaFull
107- bottomConstraint . constant = 0
105+ noticeContainerView . noticeBottomConstraint . constant = 0
108106
109- view. layoutIfNeeded ( )
107+ noticeContainerView. layoutIfNeeded ( )
108+ }
109+
110+ let hiddenState = {
111+ noticeView. alpha = UIKitConstants . alphaZero
110112 }
111113
112114 let dismiss = {
113115 guard noticeContainerView. superview != nil else {
114116 return
115117 }
116118
117- self . animatePresentation ( fromState: { } , toState: fromState , completion: {
119+ self . animatePresentation ( fromState: { } , toState: hiddenState , completion: {
118120 noticeContainerView. removeFromSuperview ( )
119121 self . dismiss ( )
120122 } )
@@ -126,7 +128,7 @@ private extension NoticePresenter {
126128 generator. notificationOccurred ( feedbackType)
127129 }
128130
129- animatePresentation ( fromState: fromState , toState: toState , completion: {
131+ animatePresentation ( fromState: offScreenState , toState: onScreenState , completion: {
130132 DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + Animations. dismissDelay, execute: dismiss)
131133 } )
132134 }
@@ -194,48 +196,89 @@ private class NoticeContainerView: UIView {
194196
195197 let containerMargin : CGFloat = 16.0
196198
199+ private let contentView : UIView = {
200+ let view = UIView ( )
201+ view. translatesAutoresizingMaskIntoConstraints = false
202+ return view
203+ } ( )
204+
205+ private let stackView : UIStackView = {
206+ let stackView = UIStackView ( )
207+ stackView. translatesAutoresizingMaskIntoConstraints = false
208+ stackView. axis = . horizontal
209+ stackView. spacing = 0
210+ return stackView
211+ } ( )
212+
213+ private( set) lazy var noticeBottomConstraint : NSLayoutConstraint = {
214+ return stackView. bottomAnchor. constraint ( equalTo: contentView. bottomAnchor)
215+ } ( )
216+
197217 let noticeView : NoticeView
198218
219+
220+ /// Designated Initializer
221+ ///
199222 init ( noticeView: NoticeView ) {
200223 self . noticeView = noticeView
201224
202225 super. init ( frame: . zero)
203226
204- translatesAutoresizingMaskIntoConstraints = false
205-
206- layoutMargins = UIEdgeInsets ( top: containerMargin, left: containerMargin, bottom: containerMargin, right: containerMargin)
207-
208- // Padding views on either side, of equal width to ensure centering
227+ /// Padding Setup: Padding views on either side, of equal width to ensure centering
228+ ///
209229 let leftPaddingView = UIView ( )
210230 let rightPaddingView = UIView ( )
211231 rightPaddingView. translatesAutoresizingMaskIntoConstraints = false
212232 leftPaddingView. translatesAutoresizingMaskIntoConstraints = false
213233
214- let stackView = UIStackView ( arrangedSubviews: [ leftPaddingView, noticeView, rightPaddingView] )
215- stackView. translatesAutoresizingMaskIntoConstraints = false
216- stackView. axis = . horizontal
217- stackView. spacing = 0
234+ /// StackView Setup
235+ ///
236+ stackView. addArrangedSubview ( leftPaddingView)
237+ stackView. addArrangedSubview ( noticeView)
238+ stackView. addArrangedSubview ( rightPaddingView)
239+
240+ contentView. addSubview ( stackView)
241+
242+ /// NoticeContainer Setup
243+ ///
244+ translatesAutoresizingMaskIntoConstraints = false
245+ layoutMargins = UIEdgeInsets ( top: containerMargin, left: containerMargin, bottom: containerMargin, right: containerMargin)
246+ addSubview ( contentView)
218247
248+ /// LayoutContraints: ContentView
249+ ///
250+ NSLayoutConstraint . activate ( [
251+ contentView. leadingAnchor. constraint ( equalTo: layoutMarginsGuide. leadingAnchor) ,
252+ contentView. trailingAnchor. constraint ( equalTo: layoutMarginsGuide. trailingAnchor) ,
253+ contentView. topAnchor. constraint ( equalTo: layoutMarginsGuide. topAnchor) ,
254+ contentView. bottomAnchor. constraint ( equalTo: layoutMarginsGuide. bottomAnchor)
255+ ] )
256+
257+ /// LayoutContraints: StackView
258+ ///
259+ NSLayoutConstraint . activate ( [
260+ stackView. leadingAnchor. constraint ( equalTo: contentView. leadingAnchor) ,
261+ stackView. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor) ,
262+ stackView. topAnchor. constraint ( equalTo: contentView. topAnchor) ,
263+ noticeBottomConstraint
264+ ] )
265+
266+ /// LayoutContraints: Padding
267+ ///
219268 let paddingWidthConstraint = leftPaddingView. widthAnchor. constraint ( equalToConstant: 0 )
220269 paddingWidthConstraint. priority = . defaultLow
221270
222- addSubview ( stackView)
223-
224271 NSLayoutConstraint . activate ( [
225272 paddingWidthConstraint,
226- leftPaddingView. widthAnchor. constraint ( equalTo: rightPaddingView. widthAnchor) ,
227- stackView. leadingAnchor. constraint ( equalTo: layoutMarginsGuide. leadingAnchor) ,
228- stackView. trailingAnchor. constraint ( equalTo: layoutMarginsGuide. trailingAnchor) ,
229- stackView. topAnchor. constraint ( equalTo: layoutMarginsGuide. topAnchor) ,
230- stackView. bottomAnchor. constraint ( equalTo: layoutMarginsGuide. bottomAnchor)
231- ] )
273+ leftPaddingView. widthAnchor. constraint ( equalTo: rightPaddingView. widthAnchor)
274+ ] )
232275 }
233276
234277 required init ? ( coder aDecoder: NSCoder ) {
235278 fatalError ( " init(coder:) has not been implemented " )
236279 }
237280
238- lazy var noticeWidthConstraint : NSLayoutConstraint = {
281+ private lazy var noticeWidthConstraint : NSLayoutConstraint = {
239282 // At regular width, the notice shouldn't be any wider than 1/2 the app's width
240283 return noticeView. widthAnchor. constraint ( equalTo: widthAnchor, multiplier: 0.5 )
241284 } ( )
0 commit comments