Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Input view rendered incorrectly when NMessengerViewController is inside UITabBarController #122

Open
dodikk opened this issue Apr 14, 2017 · 2 comments

Comments

@dodikk
Copy link

dodikk commented Apr 14, 2017

There should be no whitespace between the keyboard prompt and the input field.

simulator screen shot apr 14 2017 11 11 20 am

@dodikk
Copy link
Author

dodikk commented Apr 14, 2017

Here is a fix of the NMessengerViewController class.
I'll file a pull request later.

    func keyboardNotification(_ notification: Notification)
    {
        if let userInfo = (notification as NSNotification).userInfo
        {
            let endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
            let duration:TimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
            let animationCurveRawNSN = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber
            let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIViewAnimationOptions().rawValue
            let animationCurve:UIViewAnimationOptions = UIViewAnimationOptions(rawValue: animationCurveRaw)
            
            
            let newKeyboardLocation = endFrame
            let keyboardHeight = newKeyboardLocation?.size.height ?? 0
            let inputBarHeight = inputBarView.frame.height
            
            let isInsideTabBar = (nil != self.tabBarController)
            let tabBarHeight = self.tabBarController?.tabBar.frame.size.height ?? 0
            
            let isKeyboardOffScreen =
                (newKeyboardLocation?.origin.y >= UIScreen.main.bounds.size.height)
            
            let inputViewShiftOffsetY = keyboardHeight - tabBarHeight
            
            if (isKeyboardOffScreen)
            {
                self.inputBarBottomSpacing.constant = 0
                /*let bottomInset*/ _ = inputBarView.frame.height
                self.isKeyboardIsShown = false
            }
            else
            {
                let isInputBarHasNoBottomSpacing = (self.inputBarBottomSpacing.constant == 0)
                
                if (isInputBarHasNoBottomSpacing)
                {
                    self.inputBarBottomSpacing.constant -= inputViewShiftOffsetY
                    /*let bottomInset*/ _ = inputViewShiftOffsetY + inputBarHeight
                }
                else
                {
                    self.inputBarBottomSpacing.constant = 0
                    self.inputBarBottomSpacing.constant -= inputViewShiftOffsetY
                    /*let bottomInset*/ _ = inputViewShiftOffsetY + inputBarHeight
                }
                self.isKeyboardIsShown = true
            }
            
            let animationsBlock: () -> Swift.Void =
            {
                self.view.layoutIfNeeded()
                if self.isKeyboardIsShown
                {
                    self.messengerView.scrollToLastMessage(animated: true)
                }
            }
            
            let noDelay: TimeInterval = 0
            UIView.animate(withDuration: duration,
                                  delay: noDelay,
                                options: animationCurve,
                             animations: animationsBlock,
                             completion: nil)
            
        }
    }

@dodikk
Copy link
Author

dodikk commented Apr 14, 2017

Fixed #123

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant