Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CTNotificationContent.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/CleverTap/CTNotificationContent.git", :tag => s.version.to_s }
s.requires_arc = true
s.platform = :ios, '10.0'
s.ios.dependency 'SDWebImage', '~> 5.11'
s.weak_frameworks = 'UserNotifications', 'UIKit'
s.source_files = 'CTNotificationContent/**/*.{h,m,swift}'
s.resources = 'CTNotificationContent/**/*.{png,xib}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import UserNotificationsUI

if templateType == TemplateConstants.kTemplateBasic {
var basicImageDetails: (url: String, description: String?) = ("", nil)
var basicGifDetails: (url: String, description: String?) = ("", nil)
if let url = jsonContent.pt_big_img, !url.isEmpty {
basicImageDetails = (url: url, description: jsonContent.pt_big_img_alt_text)
}else if isFromProductDisplay{
Expand All @@ -109,15 +110,29 @@ import UserNotificationsUI
basicImageDetails = (url: url, description: jsonContent.pt_img3_alt_text)
}
}
if let gifURL = jsonContent.pt_gif, !gifURL.isEmpty {
basicGifDetails = (url: gifURL, description: jsonContent.pt_big_img_alt_text)
}

CTUtiltiy.checkImageUrlValid(imageUrl: basicImageDetails.url) { [weak self] (imageData) in
DispatchQueue.main.async {
if imageData != nil {
let itemComponents = CaptionedImageViewComponents(caption: self!.templateCaption, subcaption: self!.templateSubcaption, imageUrl: basicImageDetails.url, actionUrl: actionUrl, bgColor: self!.bgColor, captionColor: self!.captionColor, subcaptionColor: self!.subcaptionColor, bgColorDark: self!.bgColorDark, captionColorDark: self!.captionColorDark, subcaptionColorDark: self!.subcaptionColorDark, imageDescription: basicImageDetails.description ?? CTAccessibility.kDefaultImageDescription)
let itemView = CTCaptionedImageView(components: itemComponents)
CTUtiltiy.checkImageUrlValid(imageUrl: basicGifDetails.url) { [weak self] (gifData) in
if gifData == nil {
CTUtiltiy.checkImageUrlValid(imageUrl: basicImageDetails.url) { [weak self] (imageData) in
DispatchQueue.main.async {
if imageData != nil {
let itemComponents = CaptionedImageViewComponents(caption: self!.templateCaption, subcaption: self!.templateSubcaption, imageUrl: basicImageDetails.url, actionUrl: actionUrl, bgColor: self!.bgColor, captionColor: self!.captionColor, subcaptionColor: self!.subcaptionColor, bgColorDark: self!.bgColorDark, captionColorDark: self!.captionColorDark, subcaptionColorDark: self!.subcaptionColorDark, imageDescription: basicImageDetails.description ?? CTAccessibility.kDefaultImageDescription)
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: true)
self?.itemViews.append(itemView)
}
self?.setUpConstraints()
}
}
} else {
DispatchQueue.main.async {
let itemComponents = CaptionedImageViewComponents(caption: self!.templateCaption, subcaption: self!.templateSubcaption, imageUrl: basicGifDetails.url, actionUrl: actionUrl, bgColor: self!.bgColor, captionColor: self!.captionColor, subcaptionColor: self!.subcaptionColor, bgColorDark: self!.bgColorDark, captionColorDark: self!.captionColorDark, subcaptionColorDark: self!.subcaptionColorDark, imageDescription: basicGifDetails.description ?? CTAccessibility.kDefaultImageDescription)
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: true)
self?.itemViews.append(itemView)
self?.setUpConstraints()
}
self?.setUpConstraints()
}
}
} else if templateType == TemplateConstants.kTemplateAutoCarousel || templateType == TemplateConstants.kTemplateManualCarousel {
Expand All @@ -141,7 +156,7 @@ import UserNotificationsUI
DispatchQueue.main.async {
if imageData != nil {
let itemComponents = CaptionedImageViewComponents(caption: self!.templateCaption, subcaption: self!.templateSubcaption, imageUrl: imageDetails.url, actionUrl: actionUrl, bgColor: self!.bgColor, captionColor: self!.captionColor, subcaptionColor: self!.subcaptionColor, bgColorDark: self!.bgColorDark, captionColorDark: self!.captionColorDark, subcaptionColorDark: self!.subcaptionColorDark, imageDescription: imageDetails.description ?? "\(CTAccessibility.kDefaultImageDescription) \(imageIndex)")
let itemView = CTCaptionedImageView(components: itemComponents)
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
self?.itemViews.append(itemView)
imageIndex = imageIndex + 1
}
Expand Down Expand Up @@ -277,7 +292,7 @@ import UserNotificationsUI

func createDefaultAlertView() {
let itemComponents = CaptionedImageViewComponents(caption: templateCaption, subcaption: templateSubcaption, imageUrl: "", actionUrl: deeplinkURL, bgColor: bgColor, captionColor: captionColor, subcaptionColor: subcaptionColor, bgColorDark: bgColorDark, captionColorDark: captionColorDark, subcaptionColorDark: subcaptionColorDark, imageDescription: "")
let itemView = CTCaptionedImageView(components: itemComponents)
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
itemViews.append(itemView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ struct CarouselProperties: Decodable {
let pt_img1_alt_text: String?
let pt_img2_alt_text: String?
let pt_img3_alt_text: String?
let pt_gif: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fileprivate enum Constants {
}

let itemComponents = CaptionedImageViewComponents(caption: title, subcaption: subTiltle, imageUrl: item.imageUrl, actionUrl: action, bgColor: ConstantKeys.kDefaultColor, captionColor: ConstantKeys.kHexBlackColor, subcaptionColor: ConstantKeys.kHexLightGrayColor, bgColorDark: ConstantKeys.kDefaultColorDark, captionColorDark: ConstantKeys.kHexWhiteColor, subcaptionColorDark: ConstantKeys.kHexDarkGrayColor, imageDescription: item.imgAltText ?? "\(CTAccessibility.kDefaultImageDescription) \(imageIndex)")
let itemView = CTCaptionedImageView(components: itemComponents)
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
self?.itemViews.append(itemView)
imageIndex = imageIndex + 1

Expand Down Expand Up @@ -130,7 +130,7 @@ fileprivate enum Constants {

func createDefaultAlertView() {
let itemComponents = CaptionedImageViewComponents(caption: templateCaption, subcaption: templateSubcaption, imageUrl: "", actionUrl: deeplinkURL, bgColor: ConstantKeys.kDefaultColor, captionColor: ConstantKeys.kHexBlackColor, subcaptionColor: ConstantKeys.kHexLightGrayColor, imageDescription: "")
let itemView = CTCaptionedImageView(components: itemComponents)
let itemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
itemViews.append(itemView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import SDWebImage

@objc public class CTRatingsViewController: BaseCTNotificationContentViewController, UIGestureRecognizerDelegate {

Expand All @@ -26,6 +27,8 @@ import UIKit

var jsonContent: RatingProperties? = nil
var templateBigImage:String = ""
var templateBigGif:String = ""
var bigImageAltText:String? = nil
var templateDl1:String = ""
var imageViewBottomContraint:CGFloat = 0

Expand All @@ -47,8 +50,8 @@ import UIKit
subTitleLabel.translatesAutoresizingMaskIntoConstraints = false
return subTitleLabel
}()
private var bigImageView: UIImageView = {
let bigImageView = UIImageView()
private var bigImageView: SDAnimatedImageView = {
let bigImageView = SDAnimatedImageView()
bigImageView.contentMode = .scaleAspectFill
bigImageView.layer.masksToBounds = true
bigImageView.isAccessibilityElement = true
Expand Down Expand Up @@ -339,28 +342,27 @@ import UIKit
if let bigImage = jsonContent.pt_big_img, !bigImage.isEmpty{
templateBigImage = bigImage
}
if let bigGif = jsonContent.pt_gif, !bigGif.isEmpty{
templateBigGif = bigGif
}
if let bigImageAlt = jsonContent.pt_big_img_alt_text, !bigImageAlt.isEmpty{
bigImageAltText = bigImageAlt
}

self.titleLabel.setHTMLText(templateCaption)
self.subTitleLabel.setHTMLText(templateSubcaption)

if let bigImg = jsonContent.pt_big_img{
CTUtiltiy.checkImageUrlValid(imageUrl: bigImg) { [weak self] (imageData) in
DispatchQueue.main.async {
if imageData != nil {
self?.bigImageView.image = imageData
self?.bigImageView.accessibilityLabel = jsonContent.pt_big_img_alt_text ?? CTAccessibility.kDefaultImageDescription
self?.updateUI()
}else{
//handle when image url is invalid
self?.templateBigImage = ""
self?.updateUI()
}
if let gif = jsonContent.pt_gif, !gif.isEmpty, let url = URL(string: gif) {
self.bigImageView.sd_setImage(with: url, completed: { [weak self] (image, _, _, _) in
if image != nil {
self?.bigImageView.accessibilityLabel = jsonContent.pt_big_img_alt_text ?? CTAccessibility.kDefaultImageDescription
self?.updateUI()
} else {
self?.showImageView()
}
}
}else{
//handle when image is not provided
templateBigImage = ""
self.updateUI()
})
} else {
self.showImageView()
}

if let bg = jsonContent.pt_bg,!bgColor.isEmpty{
Expand Down Expand Up @@ -389,13 +391,13 @@ import UIKit

func updateUI(){
checkForiOS12()
if templateBigImage == "" && templateDl1 == ""{
if templateBigImage == "" && templateDl1 == "" && templateBigGif == "" {
viewWithoutImageandRating()
}else if templateBigImage == ""{
} else if templateBigImage == "" && templateBigGif == "" {
viewWithoutImage()
}else if templateDl1 == ""{
} else if templateDl1 == "" {
viewWithoutRating()
}else{
} else {
viewWithImageandRating()
}
}
Expand Down Expand Up @@ -495,4 +497,28 @@ import UIKit
@objc public override func getDeeplinkUrl() -> String! {
return deeplinkURL
}

func showImageView() {
if templateBigImage != "" {
CTUtiltiy.checkImageUrlValid(imageUrl: templateBigImage) { [weak self] (imageData) in
DispatchQueue.main.async {
if imageData != nil {
self?.bigImageView.image = imageData
self?.bigImageView.accessibilityLabel = self?.bigImageAltText ?? CTAccessibility.kDefaultImageDescription
self?.updateUI()
}else{
//handle when image url is invalid
self?.templateBigImage = ""
self?.templateBigGif = ""
self?.updateUI()
}
}
}
} else {
//handle when image is not provided
templateBigImage = ""
templateBigGif = ""
self.updateUI()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ struct RatingProperties: Decodable {
let pt_title_clr_dark: String?
let pt_msg_clr_dark: String?
let pt_big_img_alt_text: String?
let pt_gif: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ import AVFoundation
DispatchQueue.main.async {
if imageData != nil {
let itemComponents = CaptionedImageViewComponents(caption: self!.caption, subcaption: self!.subCaption, imageUrl: self!.mediaURL, actionUrl: self!.deeplinkURL, bgColor: ConstantKeys.kDefaultColor, captionColor: ConstantKeys.kHexBlackColor, subcaptionColor: ConstantKeys.kHexLightGrayColor, bgColorDark: ConstantKeys.kDefaultColorDark, captionColorDark: ConstantKeys.kHexWhiteColor, subcaptionColorDark: ConstantKeys.kHexDarkGrayColor, imageDescription: self!.mediaDescription)
self?.currentItemView = CTCaptionedImageView(components: itemComponents)
self?.currentItemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
} else {
let itemComponents = CaptionedImageViewComponents(caption: self!.caption, subcaption: self!.subCaption, imageUrl: "", actionUrl: self!.deeplinkURL, bgColor: ConstantKeys.kDefaultColor, captionColor: ConstantKeys.kHexBlackColor, subcaptionColor: ConstantKeys.kHexLightGrayColor, imageDescription: "")
self?.currentItemView = CTCaptionedImageView(components: itemComponents)
self?.currentItemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)
self?.createFrameWithoutImage()
}
self?.setUpConstraints()
}
}

let itemComponents = CaptionedImageViewComponents(caption: caption, subcaption: subCaption, imageUrl: mediaURL, actionUrl: deeplinkURL, bgColor: ConstantKeys.kDefaultColor, captionColor: ConstantKeys.kHexBlackColor, subcaptionColor: ConstantKeys.kHexLightGrayColor, imageDescription: mediaDescription)
currentItemView = CTCaptionedImageView(components: itemComponents)
currentItemView = CTCaptionedImageView(components: itemComponents, isGifSupported: false)

}

Expand Down
Loading