BannerMessageViewController.swift 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import UIKit
  17. class BannerMessageViewController: CommonMessageTestVC {
  18. class TestableBannerMessage: InAppMessagingBannerDisplay {
  19. var writableCampaignInfo: InAppMessagingCampaignInfo
  20. var writableTitle: String
  21. var writableBody: String?
  22. var writableTextColor: UIColor
  23. var writableImageData: InAppMessagingImageData?
  24. var writableBackgroundColor: UIColor
  25. var writableActionURL: URL?
  26. var writableMessageType: FIRInAppMessagingDisplayMessageType
  27. var writableTriggerType: FIRInAppMessagingDisplayTriggerType
  28. override var campaignInfo: InAppMessagingCampaignInfo {
  29. return writableCampaignInfo
  30. }
  31. override var title: String {
  32. return writableTitle
  33. }
  34. override var bodyText: String? {
  35. return writableBody
  36. }
  37. override var textColor: UIColor {
  38. return writableTextColor
  39. }
  40. override var imageData: InAppMessagingImageData? {
  41. return writableImageData
  42. }
  43. override var displayBackgroundColor: UIColor {
  44. return writableBackgroundColor
  45. }
  46. override var actionURL: URL? {
  47. return writableActionURL
  48. }
  49. override var type: FIRInAppMessagingDisplayMessageType {
  50. return writableMessageType
  51. }
  52. override var triggerType: FIRInAppMessagingDisplayTriggerType {
  53. return writableTriggerType
  54. }
  55. init(titleText: String,
  56. bodyText: String?,
  57. textColor: UIColor,
  58. backgroundColor: UIColor,
  59. imageData: InAppMessagingImageData?,
  60. actionURL: URL?) {
  61. writableTitle = titleText
  62. writableBody = bodyText
  63. writableTextColor = textColor
  64. writableImageData = imageData
  65. writableBackgroundColor = backgroundColor
  66. writableActionURL = actionURL
  67. writableCampaignInfo = TestableCampaignInfo(messageID: "testID",
  68. campaignName: "testCampaign",
  69. isTestMessage: false)
  70. writableMessageType = FIRInAppMessagingDisplayMessageType.banner
  71. writableTriggerType = FIRInAppMessagingDisplayTriggerType.onAnalyticsEvent
  72. super.init(messageID: "testID",
  73. campaignName: "testCampaign",
  74. renderAsTestMessage: false,
  75. messageType: .imageOnly,
  76. triggerType: .onAnalyticsEvent)
  77. }
  78. }
  79. let displayImpl = InAppMessagingDefaultDisplayImpl()
  80. @IBOutlet var verifyLabel: UILabel!
  81. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  82. with action: InAppMessagingAction) {
  83. super.messageClicked(inAppMessage, with: action)
  84. verifyLabel.text = "message clicked!"
  85. }
  86. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  87. dismissType: FIRInAppMessagingDismissType) {
  88. super.messageDismissed(inAppMessage, dismissType: dismissType)
  89. verifyLabel.text = "message dismissed!"
  90. }
  91. @IBAction func showRegularBannerTapped(_ sender: Any) {
  92. verifyLabel.text = "Verification Label"
  93. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  94. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  95. imageData: imageRawData!)
  96. let bannerMessage = TestableBannerMessage(
  97. titleText: normalMessageTitle,
  98. bodyText: normalMessageBody,
  99. textColor: UIColor.black,
  100. backgroundColor: UIColor.blue,
  101. imageData: fiamImageData,
  102. actionURL: URL(string: "http://firebase.com")
  103. )
  104. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  105. }
  106. @IBAction func showBannerViewWithoutImageTapped(_ sender: Any) {
  107. verifyLabel.text = "Verification Label"
  108. let bannerMessage = TestableBannerMessage(
  109. titleText: normalMessageTitle,
  110. bodyText: normalMessageBody,
  111. textColor: UIColor.black,
  112. backgroundColor: UIColor.blue,
  113. imageData: nil,
  114. actionURL: URL(string: "http://firebase.com")
  115. )
  116. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  117. }
  118. @IBAction func showBannerViewWithWideImageTapped(_ sender: Any) {
  119. verifyLabel.text = "Verification Label"
  120. let imageRawData = produceImageOfSize(size: CGSize(width: 800, height: 200))
  121. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  122. imageData: imageRawData!)
  123. let bannerMessage = TestableBannerMessage(
  124. titleText: normalMessageTitle,
  125. bodyText: normalMessageBody,
  126. textColor: UIColor.black,
  127. backgroundColor: UIColor.blue,
  128. imageData: fiamImageData,
  129. actionURL: URL(string: "http://firebase.com")
  130. )
  131. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  132. }
  133. @IBAction func showBannerViewWithNarrowImageTapped(_ sender: Any) {
  134. verifyLabel.text = "Verification Label"
  135. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 800))
  136. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  137. imageData: imageRawData!)
  138. let bannerMessage = TestableBannerMessage(
  139. titleText: normalMessageTitle,
  140. bodyText: normalMessageBody,
  141. textColor: UIColor.black,
  142. backgroundColor: UIColor.blue,
  143. imageData: fiamImageData,
  144. actionURL: URL(string: "http://firebase.com")
  145. )
  146. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  147. }
  148. @IBAction func showBannerViewWithLargeBodyTextTapped(_ sender: Any) {
  149. verifyLabel.text = "Verification Label"
  150. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  151. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  152. imageData: imageRawData!)
  153. let bannerMessage = TestableBannerMessage(
  154. titleText: normalMessageTitle,
  155. bodyText: longBodyText,
  156. textColor: UIColor.black,
  157. backgroundColor: UIColor.blue,
  158. imageData: fiamImageData,
  159. actionURL: URL(string: "http://firebase.com")
  160. )
  161. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  162. }
  163. @IBAction func showBannerViewWithLongTitleTextTapped(_ sender: Any) {
  164. verifyLabel.text = "Verification Label"
  165. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  166. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  167. imageData: imageRawData!)
  168. let modalMessage = TestableBannerMessage(
  169. titleText: longTitleText,
  170. bodyText: normalMessageBody,
  171. textColor: UIColor.black,
  172. backgroundColor: UIColor.blue,
  173. imageData: fiamImageData,
  174. actionURL: URL(string: "http://firebase.com")
  175. )
  176. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  177. }
  178. }