Skip to content

Commit

Permalink
fix: ios check for image label
Browse files Browse the repository at this point in the history
  • Loading branch information
vcellu committed Dec 6, 2022
1 parent a3bec42 commit 44c8cfa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions ios/DataColumn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct Representation: Codable {
let globalMax: Double?
let globalMin: Double?
let imageSize: String?
let imageSetting: String?
let imagePosition: String?
let linkUrl: String?
let urlLabel: String?
Expand Down
50 changes: 32 additions & 18 deletions ios/ImageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,40 @@ class ImageCell: UIView, ConstraintCellProtocol, SelectionsListener {
func setData(data: DataCell, representedAs rep: Representation, index: Int?) {
self.representation = rep
self.cell = data
guard let qAttrExps = data.qAttrExps else {return}
guard let qValues = qAttrExps.qValues else {return}
guard let attrIndex = index else { return }
if qValues.count > 0 {
guard let urlString = qValues[attrIndex].qText else {return}
guard let url = URL(string: urlString) else {return}
self.imagedata = nil;
if let pendingWorkItem = self.workItem {
pendingWorkItem.cancel();

guard let urlString = getUrlString(data: data, representedAs: rep, index: index) else { return }
guard let url = URL(string: urlString) else {return}
self.imagedata = nil;
if let pendingWorkItem = self.workItem {
pendingWorkItem.cancel();
}
let task = URLSession.shared.dataTask(with: url, completionHandler: { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async {
self.imagedata = data
self.setNeedsLayout()
}
let task = URLSession.shared.dataTask(with: url, completionHandler: { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async {
self.imagedata = data
self.setNeedsLayout()
}
})
self.workItem = task;
task.resume()
})
self.workItem = task;
task.resume()
}

func getUrlString(data: DataCell, representedAs rep: Representation, index: Int?) -> String? {
var urlString = ""
if(rep.imageSetting == "label") {
urlString = data.qText ?? ""
return urlString
}

guard let qAttrExps = data.qAttrExps else {return nil}
guard let qValues = qAttrExps.qValues else {return nil}
guard let attrIndex = index else { return nil }

if qValues.count > 0 {
guard let urlString = qValues[attrIndex].qText else {return nil}
return urlString
}
return nil
}

override func layoutSubviews() {
Expand Down

0 comments on commit 44c8cfa

Please sign in to comment.