Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General layout issues #268

Closed
jackdem opened this issue Oct 18, 2017 · 30 comments
Closed

General layout issues #268

jackdem opened this issue Oct 18, 2017 · 30 comments
Milestone

Comments

@jackdem
Copy link

jackdem commented Oct 18, 2017

General Information

  • MessageKit Version: latest

  • iOS Version(s): 11

  • Swift Version: 3

  • Devices/Simulators: 8 sim

  • Reproducible in ChatExample? (Yes/No):

What happened?

I have several layout issues with the library, for example the chat window is hidden behind the message typing box, the view doesnt scroll to the bottom on load, opening the full keyboard doesnt life the chat view and obscures it.

screen shot 2017-10-18 at 11 59 56 am

screen shot 2017-10-18 at 12 02 28 pm

screen shot 2017-10-18 at 12 02 55 pm

What did you expect to happen?

adapts correctly

@SD10
Copy link
Member

SD10 commented Oct 18, 2017

Hey @jackdem,
There is a bug with the top content inset on master. It should be fixed with the next relase.

As for scrolling/keyboard handling. You should look at the scrollsToBottomOnFirstLoad and scrollsToBottomOnKeyboardDidBeginEditing properties of MessagesViewController. If there are any other layout problems please be specific

Sent with GitHawk

@SD10 SD10 added the bug? label Oct 18, 2017
@jackdem
Copy link
Author

jackdem commented Oct 19, 2017

do i need to do any additional setup for those calls as either of them in the viewDidLoad doesnt scroll down correctly

override func viewDidLoad() {
        super.viewDidLoad()
        self.title = self.conversation.firstname + " " + self.conversation.lastname
        messagesCollectionView.messagesDataSource = self
        messagesCollectionView.messagesLayoutDelegate = self
        messagesCollectionView.messagesDisplayDelegate = self
        messagesCollectionView.messageCellDelegate = self
        messageInputBar.delegate = self
        scrollsToBottomOnFirstLayout = true
        scrollsToBottomOnKeybordBeginsEditing = true
        scheduledTimerWithTimeInterval()
        self.tabBarController?.tabBar.isHidden = true
    }

@SD10
Copy link
Member

SD10 commented Oct 20, 2017

what do you mean by not scrolling down correctly @jackdem?

@jackdem
Copy link
Author

jackdem commented Oct 20, 2017

as shown in the screenshots, when the view loads, itll load in the middle of a convo, it doesnt scroll to the latest message

@SD10
Copy link
Member

SD10 commented Oct 20, 2017

Ok @jackdem I'll take a look, thanks for reporting this

@jackdem
Copy link
Author

jackdem commented Oct 20, 2017

thanks, i assumed those library methods would allow the auto scroll as you mentioned, but as you can see in the viewdidload code above, im using them and its not triggering

@Terens777
Copy link

how did you solve this problem?

@jackdem
Copy link
Author

jackdem commented Oct 23, 2017

i didnt, its messed up until the next release

@Terens777
Copy link

understood, we will work with it ourselves

@Terens777
Copy link

Yes, I did this, I can not say anything about further work with this, but at the moment to solve this problem, simply replace the scrollToBottom method with this one

 public func scrollToBottomAnimated(animated: Bool) {
    
    guard numberOfSections > 0 else{
        return
    }
    
    let items = numberOfItems(inSection: 0)
    
    if items == 0 { return }
    
    let collectionViewHeight = collectionViewLayout.collectionViewContentSize.height
    
    scrollRectToVisible(CGRect(x: 0, y: collectionViewHeight - 1, width: 1, height: 1), animated: animated)
}

@jackdem
Copy link
Author

jackdem commented Oct 24, 2017

did you put this in the framework its self or in the viewcontroller in app?

@SD10
Copy link
Member

SD10 commented Oct 24, 2017

@jackdem he put it in the framework itself

@jackdem
Copy link
Author

jackdem commented Oct 24, 2017

can we get a pull request update? be good to get this issue resolved

@SD10
Copy link
Member

SD10 commented Oct 24, 2017

@jackdem I’m pretty sure that’s not the fix, hopefully it’s fixed already in the next release. You can check the v0.10.0 example app to see if this issue is still present.

Sent with GitHawk

@Terens777
Copy link

As I wrote this is a temporary solution

@stefanluptak
Copy link

As of the weird scrollToBottom behaviour, all what I had to adjust was to change line
scrollToItem(at: indexPath, at: .bottom, animated: animated)
to
scrollToItem(at: indexPath, at: .top, animated: animated)
inside method scrollToBottom(animated:) in file MessagesCollectionView.swift
(difference is in .bottom vs .top (see: https://developer.apple.com/documentation/uikit/uicollectionviewscrollposition)

@jackdem
Copy link
Author

jackdem commented Oct 26, 2017

that lets me scroll to the top which works, but thats not really useful for a conversation? you would want to go to the bottom, which isnt working still

@stefanluptak
Copy link

@jackdem did you try it? For me it solved the situation when the bottom message is partialy visible and partialy hidden.

@Terens777
Copy link

in 30 minutes I will return for the workplace and take off the option as I decided this problem

@jackdem
Copy link
Author

jackdem commented Oct 26, 2017

yes i tried, for me it loads the conversation at the top only, opening the keyboard still crops the conversation and not auto scrolling to the latest messages in a messaging app isnt good

@SD10
Copy link
Member

SD10 commented Oct 26, 2017

Please let me know if this is still happening in v0.10.0. I'm going to look at UICollectionViewScrollPosition too.

@jackdem
Copy link
Author

jackdem commented Oct 26, 2017

im on the latest version on cocapods whichever that is. nothings resolved or improved the situation for me

@SD10
Copy link
Member

SD10 commented Oct 26, 2017

The problem is when scrollToBottom(animated:) is called for isFirstLayout, the messagesCollectionView.numberOfSections is zero. I have to figure out what caused this because it was working before 🤔 I even had to disable it in the example because it was annoying me that the page opened at the bottom 😅

@SD10 SD10 added confirmed bug and removed bug? labels Oct 26, 2017
@SD10 SD10 added this to the 0.11.0 milestone Oct 26, 2017
@Terens777
Copy link

at the moment I use it this way

public func scrollToBottom(animated: Bool = false) {
    
    guard let indexPath = indexPathForLastItem else { return }
    scrollToItem(at: indexPath, at: .bottom, animated: animated)
}
public func scrollToBottomAnimated(animated: Bool) {
    
    guard numberOfSections > 0 else{
        return
    }
    
    let items = numberOfItems(inSection: 0)
    
    if items == 0 { return }
    
    let collectionViewHeight = collectionViewLayout.collectionViewContentSize.height
    
    let isContentTooSmall: Bool = (collectionViewHeight < frame.size.height)
    
    if isContentTooSmall {
        
        scrollRectToVisible(CGRect(x: 0, y: collectionViewHeight - 1, width: 1, height: 1), animated: animated)
        return
    }
    
    scrollToBottom(animated: true)
}

@bayareahank
Copy link

Tried the latest release (0.10), when message is just one line, screen scrolls up correctly and show the new message. When longer than one line, screen just won't scroll up, the new message is thus hidden.

@SD10
Copy link
Member

SD10 commented Nov 10, 2017

Hey @Terens777, thanks for providing that code. I'm wondering why you perform the check isContentTooSmall and then fall back on scrollRectToVisible?

Could we not just use scrollRectToVisible 100% of the time?

@SD10
Copy link
Member

SD10 commented Nov 17, 2017

This is proving pretty difficult to solve. #301 fails to resolve the issue consistently.

The code snippet provided by @Terens777 doesn't seem to work without being wrapped in Dispatch.main.async

@SD10 SD10 modified the milestones: 0.11.0, 0.12.0 Dec 4, 2017
@festrs
Copy link

festrs commented Dec 11, 2017

I found some topic on stack overflow that might help!

https://stackoverflow.com/questions/17751985/animated-scroll-to-item-in-uicollectionview-doesnt-always-work

I'll try to implement a fix and them submit a PR!

@SD10
Copy link
Member

SD10 commented Dec 11, 2017

@festrs #395 Attempts to solve this one, thank you for taking interest 👍

@SD10
Copy link
Member

SD10 commented Dec 12, 2017

This should be resolved in #395 when 0.12.0 is released

@SD10 SD10 closed this as completed Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants