Skip to content

Commit

Permalink
update for 3.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Sergey-K committed Nov 2, 2022
1 parent 851e51e commit ef8bb78
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Core/UDConfigurationStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,15 @@ public struct MessageButtonStyle {
textFont: UIFont = UIFont.systemFont(ofSize: 15),
cornerRadius: CGFloat = 8,
spacing: CGFloat = 8,
height: CGFloat = 36,
minHeight: CGFloat = 36,
margin: UIEdgeInsets = UIEdgeInsets(top: 0, left: 12, bottom: 8, right: 6),
maximumLine: Int = 1) {
maximumLine: Int = 3) {
self.color = color ?? UIColor(hexString: "333333")
self.textColor = textColor ?? UIColor(hexString: "FFFFFF")
self.textFont = textFont
self.cornerRadius = cornerRadius
self.spacing = spacing
self.minHeight = height
self.minHeight = minHeight
self.margin = margin
self.maximumLine = maximumLine
}
Expand Down
4 changes: 1 addition & 3 deletions Core/UDSocketResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ class UDSocketResponse {
var m: UDMessage? = nil
var messageFile: UDMessage? = nil
var messagesImageLink: [UDMessage] = []

var mutableAttributedString: NSMutableAttributedString? = nil
var textWithoutLinkImage: String? = nil
var linksImage: [String] = []
if var text = message!["text"] as? String {
Expand Down Expand Up @@ -235,7 +233,6 @@ class UDSocketResponse {
var messageFile: UDMessage? = nil
var messagesImageLink: [UDMessage] = []
if let message = mess as? [AnyHashable : Any] {
var mutableAttributedString: NSMutableAttributedString? = nil
var textWithoutLinkImage: String? = nil
var linksImage: [String] = []
if var text = message["text"] as? String {
Expand Down Expand Up @@ -467,6 +464,7 @@ class UDSocketResponse {
text = text.udRemoveFirstSymbol(with: "\n")
text = text.udRemoveLastSymbol(with: "\u{200b}")
text = text.udRemoveLastSymbol(with: "\n")
text.udConvertUrls()
do {
let doc: Document = try SwiftSoup.parse(text)
text = try doc.text()
Expand Down
38 changes: 38 additions & 0 deletions Core/UDStringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ extension String {
return resultString
}

func udRemoveFirstAndLastLineBreaksAndSpaces() -> String {
var resultString = self
while resultString.first == " " || resultString.first == "\n" || resultString.last == " " || resultString.last == "\n" {
resultString = resultString.udRemoveFirstSymbol(with: "\n")
resultString = resultString.udRemoveFirstSymbol(with: " ")
resultString = resultString.udRemoveLastSymbol(with: "\n")
resultString = resultString.udRemoveLastSymbol(with: " ")
}
return resultString
}

mutating func udRemoveMarkdownUrlsAndReturnLinks() -> [String] {
var links: [String] = []
var count = 0
Expand Down Expand Up @@ -173,6 +184,33 @@ extension String {
}
return links
}

mutating func udConvertUrls() {
var count = 0
var flag = true
while count < 9000 && flag {
if let range = self.range(of: "<http") {
let startIndex = range.lowerBound
var isFindEnd = false
var index = 0
while !isFindEnd {
if let searchEndIndex = self.index(startIndex, offsetBy: index, limitedBy: self.endIndex) {
if self[searchEndIndex] == ">" {
isFindEnd = true
self = self.replacingOccurrences(of: self[searchEndIndex...searchEndIndex], with: "")
self = self.replacingOccurrences(of: self[startIndex...startIndex], with: "")
}
} else {
isFindEnd = true
}
index += 1
}
} else {
flag = false
}
count += 1
}
}

private func singleLineHeight(attributes: [NSAttributedString.Key : Any]) -> CGFloat {
let attributedString = NSAttributedString(string: "0", attributes: attributes)
Expand Down
2 changes: 1 addition & 1 deletion Core/UseDeskSDKHelp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UseDeskSDKHelp {
let payload: [String : Any] = [
"sdk" : "iOS",
"type" : "sdk",
"version" : "3.1.6",
"version" : "3.1.7",
"message_limit" : countMessagesOnInit
]
var dic = [
Expand Down
4 changes: 2 additions & 2 deletions Example/UseDesk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@
INFOPLIST_FILE = "UseDesk/UseDesk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.1.6;
MARKETING_VERSION = 3.1.7;
MODULE_NAME = ExampleApp;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = UseDeskExampleSDK.ru;
Expand Down Expand Up @@ -621,7 +621,7 @@
INFOPLIST_FILE = "UseDesk/UseDesk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.1.6;
MARKETING_VERSION = 3.1.7;
MODULE_NAME = ExampleApp;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = UseDeskExampleSDK.ru;
Expand Down
9 changes: 5 additions & 4 deletions UseDesk/Classes/UDMessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ class UDMessagesView: UIViewController, UITextViewDelegate, UIImagePickerControl
if textInput.text.count == 0 {
buttonSend.isEnabled = false // если сообщение отсутствует кнопка не активна
} else {
buttonSend.isEnabled = textInput.text.udRemoveFirstSpaces().count != 0 // если сообщение не пустое то кнопка активна
buttonSend.isEnabled = textInput.text.udRemoveFirstAndLastLineBreaksAndSpaces().count != 0 // если сообщение не пустое то кнопка активна
}
}
}
Expand Down Expand Up @@ -1494,11 +1494,12 @@ class UDMessagesView: UIViewController, UITextViewDelegate, UIImagePickerControl

func textViewDidChange(_ textView: UITextView) {
inputPanelUpdate()
if textView.text.udRemoveFirstSpaces().count > 0 {
if textView.text.udRemoveFirstAndLastLineBreaksAndSpaces().count > 0 {
let text = textView.text.udRemoveFirstAndLastLineBreaksAndSpaces()
if draftMessages.filter({$0.type == UD_TYPE_TEXT}).count > 0 {
draftMessages.filter({$0.type == UD_TYPE_TEXT})[0].text = textView.text
draftMessages.filter({$0.type == UD_TYPE_TEXT})[0].text = text
} else {
draftMessages.insert(UDMessage(text: textView.text), at: 0)
draftMessages.insert(UDMessage(text: text), at: 0)
}
} else {
if let draftTextMessages = draftMessages.filter({$0.type == UD_TYPE_TEXT}).first {
Expand Down
41 changes: 29 additions & 12 deletions UseDesk/Classes/UDTextMessageCellNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,8 @@ class UDTextMessageCellNode: UDMessageCellNode {
let insetSpec = ASInsetLayoutSpec(insets: messageButtonStyle.margin, child: tableButtonsNode)
tableButtonsNode.style.minWidth = ASDimensionMakeWithPoints(60000.0)
var height: CGFloat = 0 // height tableButtonsNode
let heightLine = "1".size(availableWidth: sizeMessagesManager.maxWidthBubbleMessage - messageButtonStyle.margin.left - messageButtonStyle.margin.right, attributes: [.font : messageButtonStyle.textFont, .foregroundColor : messageButtonStyle.textColor]).height
for index in 0..<message.buttons.count {
let heightTitle = message.buttons[index].title.size(availableWidth: sizeMessagesManager.maxWidthBubbleMessage - messageButtonStyle.margin.left - messageButtonStyle.margin.right - 16, attributes: [.font : messageButtonStyle.textFont, .foregroundColor : messageButtonStyle.textColor]).height
if (heightTitle / heightLine).rounded(.up) > CGFloat(messageButtonStyle.maximumLine) {
height += heightLine * CGFloat(messageButtonStyle.maximumLine)
} else {
height += heightTitle
}
height += 16
height += messageButtonStyle.spacing
height += heightNodeCellButton(for: IndexPath(row: index, section: 0))
}
height += messageButtonStyle.margin.top + messageButtonStyle.margin.bottom
tableButtonsNode.style.minHeight = ASDimensionMakeWithPoints(height)
Expand All @@ -116,6 +108,31 @@ class UDTextMessageCellNode: UDMessageCellNode {
@objc func longPressTextAction() {
delegateText?.longPressText(text: message.text)
}

func heightNodeCellButton(for indexPath: IndexPath) -> CGFloat {
let messageButtonStyle = configurationStyle.messageButtonStyle
let sizeMessagesManager = UDSizeMessagesManager(messagesView: messagesView, message: message, indexPath: indexPath, configurationStyle: configurationStyle)

var heightButton: CGFloat = 0

let widthTitle = sizeMessagesManager.maxWidthBubbleMessage - messageButtonStyle.margin.left - messageButtonStyle.margin.right - 16
let heightLine = "1".size(attributes: [.font : messageButtonStyle.textFont]).height
let heightTitle = message.buttons[indexPath.row].title.size(availableWidth: widthTitle, attributes: [.font : messageButtonStyle.textFont]).height

if (heightTitle / heightLine).rounded(.up) > CGFloat(messageButtonStyle.maximumLine) {
heightButton += heightLine * CGFloat(messageButtonStyle.maximumLine)
} else {
heightButton += heightTitle
}

heightButton += 16
heightButton = heightButton < messageButtonStyle.minHeight ? messageButtonStyle.minHeight : heightButton
if indexPath.row != 0 {
heightButton += messageButtonStyle.spacing
}

return heightButton
}
}

extension UDTextMessageCellNode: ASTableDelegate, ASTableDataSource {
Expand Down Expand Up @@ -150,9 +167,9 @@ extension UDTextMessageCellNode: ASTableDelegate, ASTableDataSource {
}

func tableNode(_ tableNode: ASTableNode, constrainedSizeForRowAt indexPath: IndexPath) -> ASSizeRange {
let messageButtonStyle = configurationStyle.messageButtonStyle
let min = CGSize(width: UIScreen.main.bounds.size.width, height: indexPath.row == 0 ? messageButtonStyle.minHeight : messageButtonStyle.minHeight + messageButtonStyle.spacing)
let max = CGSize(width: UIScreen.main.bounds.size.width, height: indexPath.row == 0 ? (messageButtonStyle.minHeight * CGFloat(messageButtonStyle.maximumLine)) : (messageButtonStyle.minHeight * CGFloat(messageButtonStyle.maximumLine)) + messageButtonStyle.spacing)
let heightButton = heightNodeCellButton(for: indexPath)
let min = CGSize(width: UIScreen.main.bounds.size.width, height: heightButton)
let max = CGSize(width: UIScreen.main.bounds.size.width, height: heightButton)
return ASSizeRange(min: min, max: max)
}
}
Expand Down
2 changes: 1 addition & 1 deletion UseDesk_SDK_Swift.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'UseDesk_SDK_Swift'
s.version = '3.1.6'
s.version = '3.1.7'
s.summary = 'A short description of UseDesk.'

s.homepage = 'https://github.com/usedesk/UseDeskSwift'
Expand Down

0 comments on commit ef8bb78

Please sign in to comment.