Skip to content

Fix wrong separated components in messageInputBar - #577

Merged
SD10 merged 2 commits into
MessageKit:masterfrom
zhongwuzw:fix-inputBar
Mar 21, 2018
Merged

SD10 merged 2 commits into
MessageKit:masterfrom
zhongwuzw:fix-inputBar

Conversation

@zhongwuzw

Copy link
Copy Markdown
Member

Fix #569

@zhongwuzw zhongwuzw changed the title Fix wrong seperated components in messageInputBar Fix wrong separated components in messageInputBar Mar 19, 2018
@zhongwuzw
zhongwuzw requested review from SD10 and nathantannar4 March 19, 2018 08:50

@SD10 SD10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this but I got lost on the second half of the logic. It may be good to wait and have @nathantannar4 review this as he is the original author.

}
}

var curLocation = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhongwuzw Can you help me understand the code from here? I just want to understand before we merge if Nathan doesn't have time to look at this one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SD10 , First we should enumerate all .attachment, get its image and range, then we can split text and image based on the range.

}
}

var curLocation = 0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SD10 , First we should enumerate all .attachment, get its image and range, then we can split text and image based on the range.

}

var curLocation = 0
if attachments.count == 0 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SD10 If no images, just text.

let (range, image) = attachment
if curLocation < range.location {
let textRange = NSMakeRange(curLocation, range.location)
let text = attributedText.attributedSubstring(from: textRange).string.trimmingCharacters(in: .whitespacesAndNewlines)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add text and image to components

curLocation = range.location + range.length
components.append(image)
}
if curLocation < length - 1 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After last image, maybe still has text, so we should append it to components.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is length - 1 here? Sorry 😓

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 It's because we add a new line after image, so we decrease 1 to prevent unnecessary calculation.

@SD10 SD10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhongwuzw Thanks for walking me through this 👍

@SD10 SD10 removed the under review label Mar 21, 2018
@SD10
SD10 merged commit 278a13a into MessageKit:master Mar 21, 2018
@zhongwuzw
zhongwuzw deleted the fix-inputBar branch March 21, 2018 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants