BannerMessageViewController.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. }
  73. }
  74. let displayImpl = InAppMessagingDefaultDisplayImpl()
  75. @IBOutlet var verifyLabel: UILabel!
  76. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  77. with action: InAppMessagingAction) {
  78. super.messageClicked(inAppMessage, with: action)
  79. verifyLabel.text = "message clicked!"
  80. }
  81. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  82. dismissType: FIRInAppMessagingDismissType) {
  83. super.messageDismissed(inAppMessage, dismissType: dismissType)
  84. verifyLabel.text = "message dismissed!"
  85. }
  86. @IBAction func showRegularBannerTapped(_ sender: Any) {
  87. verifyLabel.text = "Verification Label"
  88. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  89. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  90. imageData: imageRawData!)
  91. let bannerMessage = TestableBannerMessage(
  92. titleText: normalMessageTitle,
  93. bodyText: normalMessageBody,
  94. textColor: UIColor.black,
  95. backgroundColor: UIColor.blue,
  96. imageData: fiamImageData,
  97. actionURL: URL(string: "http://firebase.com")
  98. )
  99. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  100. }
  101. @IBAction func showBannerViewWithoutImageTapped(_ sender: Any) {
  102. verifyLabel.text = "Verification Label"
  103. let bannerMessage = TestableBannerMessage(
  104. titleText: normalMessageTitle,
  105. bodyText: normalMessageBody,
  106. textColor: UIColor.black,
  107. backgroundColor: UIColor.blue,
  108. imageData: nil,
  109. actionURL: URL(string: "http://firebase.com")
  110. )
  111. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  112. }
  113. @IBAction func showBannerViewWithWideImageTapped(_ sender: Any) {
  114. verifyLabel.text = "Verification Label"
  115. let imageRawData = produceImageOfSize(size: CGSize(width: 800, height: 200))
  116. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  117. imageData: imageRawData!)
  118. let bannerMessage = TestableBannerMessage(
  119. titleText: normalMessageTitle,
  120. bodyText: normalMessageBody,
  121. textColor: UIColor.black,
  122. backgroundColor: UIColor.blue,
  123. imageData: fiamImageData,
  124. actionURL: URL(string: "http://firebase.com")
  125. )
  126. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  127. }
  128. @IBAction func showBannerViewWithNarrowImageTapped(_ sender: Any) {
  129. verifyLabel.text = "Verification Label"
  130. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 800))
  131. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  132. imageData: imageRawData!)
  133. let bannerMessage = TestableBannerMessage(
  134. titleText: normalMessageTitle,
  135. bodyText: normalMessageBody,
  136. textColor: UIColor.black,
  137. backgroundColor: UIColor.blue,
  138. imageData: fiamImageData,
  139. actionURL: URL(string: "http://firebase.com")
  140. )
  141. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  142. }
  143. @IBAction func showBannerViewWithLargeBodyTextTapped(_ sender: Any) {
  144. verifyLabel.text = "Verification Label"
  145. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  146. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  147. imageData: imageRawData!)
  148. let bannerMessage = TestableBannerMessage(
  149. titleText: normalMessageTitle,
  150. bodyText: longBodyText,
  151. textColor: UIColor.black,
  152. backgroundColor: UIColor.blue,
  153. imageData: fiamImageData,
  154. actionURL: URL(string: "http://firebase.com")
  155. )
  156. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  157. }
  158. @IBAction func showBannerViewWithLongTitleTextTapped(_ sender: Any) {
  159. verifyLabel.text = "Verification Label"
  160. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  161. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  162. imageData: imageRawData!)
  163. let modalMessage = TestableBannerMessage(
  164. titleText: longTitleText,
  165. bodyText: normalMessageBody,
  166. textColor: UIColor.black,
  167. backgroundColor: UIColor.blue,
  168. imageData: fiamImageData,
  169. actionURL: URL(string: "http://firebase.com")
  170. )
  171. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  172. }
  173. }