@@ -21,9 +21,9 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
2121 @IBOutlet private var heightTextContainerLayoutConstraint : NSLayoutConstraint !
2222 @IBOutlet private var heightDoubleButtonsLayoutConstraint : NSLayoutConstraint !
2323 @IBOutlet private var heightSingleButtonLayoutConstraint : NSLayoutConstraint !
24+ @IBOutlet private var heightPullViewLayoutConstraint : NSLayoutConstraint !
2425
2526 @IBOutlet private var appIconImageView : UIImageView !
26- @IBOutlet private var separatorView : UIView !
2727
2828 @IBOutlet var titleLabel : UILabel !
2929 @IBOutlet var subtitleLabel : UILabel !
@@ -51,7 +51,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
5151
5252 private var currentHeightContainerLayoutConstraint : NSLayoutConstraint ?
5353
54- private var initialHeightForNotification : CGFloat = 80
54+ private var initialHeightForNotification : CGFloat = 100 //+20
5555 private var shouldShowTextView : Bool {
5656
5757 get {
@@ -68,10 +68,10 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
6868
6969 get {
7070
71- var height = heightForText ( subtitleLabel. text ?? " " , width: subtitleLabel. frame. size. width) + 65
71+ var height = heightForText ( subtitleLabel. text ?? " " , width: subtitleLabel. frame. size. width) + 75
7272
7373 if let _ = currentHeightContainerLayoutConstraint {
74- height += 50
74+ height += 60
7575 }
7676
7777 return height
@@ -130,10 +130,16 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
130130 super. awakeFromNib ( )
131131
132132 appIconImageView. image = UIImage ( named: " AppIcon40x40 " )
133+
134+ NotificationCenter . default. addObserver ( self , selector: #selector( orientationDidChange) , name: . UIDeviceOrientationDidChange, object: nil )
133135 }
134136
135137 //MARK: - Deinitialization
136138
139+ deinit {
140+ NotificationCenter . default. removeObserver ( self )
141+ }
142+
137143 //MARK: - Actions
138144
139145 @IBAction func viewPanned( _ gestureRecognizer: UIPanGestureRecognizer ) {
@@ -169,7 +175,8 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
169175 rightActionButton. alpha = alpha
170176 singleActionButton. alpha = alpha
171177 textView. alpha = alpha
172- sendButton. alpha = alpha / 5
178+ sendButton. alpha = alpha
179+
173180 currentHeightContainerLayoutConstraint? . constant = 50 - ( maxHeightOfNotification - frame. size. height)
174181 }
175182 }
@@ -314,7 +321,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
314321
315322 tapGestureRecognizer. isEnabled = false
316323 panGestureRecognizer. isEnabled = false
317- sender. alpha = 0.2
324+ sender. alpha = 0.9
318325 }
319326
320327 @IBAction func actionButtonLeft( _ sender: UIButton ) {
@@ -328,6 +335,21 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
328335
329336 //MARK: - Internal
330337
338+ func orientationDidChange( ) {
339+
340+ if extendingIsFinished {
341+
342+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 as DispatchTime , execute: {
343+
344+ UIView . animate ( withDuration: 0.3 ) {
345+
346+ self . heightConstraintNotification. constant = self . maxHeightOfNotification
347+ self . superview? . layoutIfNeeded ( )
348+ }
349+ } )
350+ }
351+ }
352+
331353 func setupNotification( ) {
332354
333355 if let window = UIApplication . shared. keyWindow , !titleLabel. text!. isEmpty && !subtitleLabel. text!. isEmpty {
@@ -363,7 +385,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
363385 UIView . animate ( withDuration: 0.5 , animations: {
364386
365387 self . topConstraintNotification. constant = 0
366- self . layoutIfNeeded ( )
388+ self . superview ? . layoutIfNeeded ( )
367389 } )
368390
369391 if let soundName = soundName {
@@ -391,7 +413,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
391413 UIView . animate ( withDuration: 1 , delay: 0 , usingSpringWithDamping: 0.6 , initialSpringVelocity: 1 , options: . beginFromCurrentState, animations: {
392414
393415 self . topConstraintNotification. constant = - self . heightConstraintNotification. constant
394- self . layoutIfNeeded ( )
416+ self . superview ? . layoutIfNeeded ( )
395417
396418 } , completion: { finished in
397419
@@ -411,13 +433,12 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
411433
412434 //MARK: - Private
413435
414- fileprivate func setupActions( ) {
436+ private func setupActions( ) {
415437
416438 heightTextContainerLayoutConstraint. constant = 0
417439 heightSingleButtonLayoutConstraint. constant = 0
418440 heightDoubleButtonsLayoutConstraint. constant = 0
419441
420- separatorView. alpha = 0
421442 leftActionButton. alpha = 0
422443 rightActionButton. alpha = 0
423444 singleActionButton. alpha = 0
@@ -426,7 +447,6 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
426447
427448 if let actions = UIApplication . shared. currentUserNotificationSettings? . categories? . filter ( { return $0. identifier == categoryIdentifier } ) . first? . actions ( for: . default) , actions. count > 0 {
428449
429- separatorView. alpha = 0.2
430450 rightUserNotificationAction = actions [ 0 ]
431451 leftUserNotificationAction = actions. count >= 2 ? actions [ 1 ] : nil
432452
@@ -450,7 +470,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
450470 }
451471 }
452472
453- fileprivate func presentView( ) {
473+ private func presentView( ) {
454474
455475 UIView . animate ( withDuration: 1 , delay: 0 , usingSpringWithDamping: 0.6 , initialSpringVelocity: 1 , options: . beginFromCurrentState, animations: {
456476
@@ -459,8 +479,9 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
459479 self . rightActionButton. alpha = 1
460480 self . singleActionButton. alpha = 1
461481 self . textView. alpha = 1
462- self . sendButton. alpha = 0.2
482+ self . sendButton. alpha = 1
463483 self . currentHeightContainerLayoutConstraint? . constant = 50
484+ self . heightPullViewLayoutConstraint. constant = 0
464485
465486 self . layoutIfNeeded ( )
466487
@@ -471,20 +492,22 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
471492 if self . shouldShowTextView {
472493 self . textView. becomeFirstResponder ( )
473494 }
495+
496+
474497 } )
475498 }
476499
477- fileprivate func moveViewToTop( ) {
500+ private func moveViewToTop( ) {
478501
479502 UIView . animate ( withDuration: 1 , delay: 0 , usingSpringWithDamping: 0.6 , initialSpringVelocity: 1 , options: . beginFromCurrentState, animations: {
480503
481504 self . topConstraintNotification. constant = 0
482505 self . layoutIfNeeded ( )
483506
484- } , completion : nil )
507+ } )
485508 }
486509
487- fileprivate func updateNotificationHeightWithNewTextViewHeight( _ height: CGFloat ) {
510+ private func updateNotificationHeightWithNewTextViewHeight( _ height: CGFloat ) {
488511
489512 UIView . animate ( withDuration: 0.4 , animations: {
490513
@@ -495,7 +518,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
495518 } )
496519 }
497520
498- fileprivate func heightForText( _ text: String , width: CGFloat ) -> CGFloat {
521+ private func heightForText( _ text: String , width: CGFloat ) -> CGFloat {
499522
500523 let label = UILabel ( frame: CGRect ( x: 0 , y: 0 , width: width, height: CGFloat . greatestFiniteMagnitude) )
501524 label. numberOfLines = 0
@@ -514,11 +537,7 @@ class BSForegroundNotificationView: UIView, UITextViewDelegate {
514537
515538 func textViewDidChange( _ textView: UITextView ) {
516539
517- let isEmpty = textView. text. characters. isEmpty
518-
519- sendButton. alpha = isEmpty ? 0.2 : 1
520-
521- if isEmpty {
540+ if textView. text. characters. isEmpty {
522541 updateNotificationHeightWithNewTextViewHeight ( 50 )
523542 } else {
524543 updateNotificationHeightWithNewTextViewHeight ( max ( textView. contentSize. height + 20 , 50 ) )
0 commit comments