ModalMessageViewController.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 ModalMessageViewController: CommonMessageTestVC {
  18. class TestableModalMessage: InAppMessagingModalDisplay {
  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 writableActionButton: InAppMessagingActionButton?
  26. var writableActionURL: URL?
  27. var writableMessageType: FIRInAppMessagingDisplayMessageType
  28. var writableTriggerType: FIRInAppMessagingDisplayTriggerType
  29. override var campaignInfo: InAppMessagingCampaignInfo {
  30. return writableCampaignInfo
  31. }
  32. override var title: String {
  33. return writableTitle
  34. }
  35. override var bodyText: String? {
  36. return writableBody
  37. }
  38. override var textColor: UIColor {
  39. return writableTextColor
  40. }
  41. override var imageData: InAppMessagingImageData? {
  42. return writableImageData
  43. }
  44. override var displayBackgroundColor: UIColor {
  45. return writableBackgroundColor
  46. }
  47. override var actionButton: InAppMessagingActionButton? {
  48. return writableActionButton
  49. }
  50. override var actionURL: URL? {
  51. return writableActionURL
  52. }
  53. override var type: FIRInAppMessagingDisplayMessageType {
  54. return writableMessageType
  55. }
  56. override var triggerType: FIRInAppMessagingDisplayTriggerType {
  57. return writableTriggerType
  58. }
  59. init(titleText: String,
  60. bodyText: String?,
  61. textColor: UIColor,
  62. backgroundColor: UIColor,
  63. imageData: InAppMessagingImageData?,
  64. actionButton: InAppMessagingActionButton?,
  65. actionURL: URL?) {
  66. writableTitle = titleText
  67. writableBody = bodyText
  68. writableTextColor = textColor
  69. writableImageData = imageData
  70. writableBackgroundColor = backgroundColor
  71. writableActionButton = actionButton
  72. writableActionURL = actionURL
  73. writableCampaignInfo = TestableCampaignInfo(messageID: "testID",
  74. campaignName: "testCampaign",
  75. isTestMessage: false)
  76. writableMessageType = FIRInAppMessagingDisplayMessageType.card
  77. writableTriggerType = FIRInAppMessagingDisplayTriggerType.onAnalyticsEvent
  78. super.init(messageID: "testID",
  79. campaignName: "testCampaign",
  80. renderAsTestMessage: false,
  81. messageType: .imageOnly,
  82. triggerType: .onAnalyticsEvent)
  83. }
  84. }
  85. let displayImpl = InAppMessagingDefaultDisplayImpl()
  86. @IBOutlet var verifyLabel: UILabel!
  87. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  88. with action: InAppMessagingAction) {
  89. super.messageClicked(inAppMessage, with: action)
  90. verifyLabel.text = "message clicked!"
  91. }
  92. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  93. dismissType: FIRInAppMessagingDismissType) {
  94. super.messageDismissed(inAppMessage, dismissType: dismissType)
  95. verifyLabel.text = "message dismissed!"
  96. }
  97. @IBAction func showRegular(_ sender: Any) {
  98. verifyLabel.text = "Verification Label"
  99. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  100. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  101. imageData: imageRawData!)
  102. let modalMessage = TestableModalMessage(
  103. titleText: normalMessageTitle,
  104. bodyText: normalMessageBody,
  105. textColor: UIColor.black,
  106. backgroundColor: UIColor.blue,
  107. imageData: fiamImageData,
  108. actionButton: defaultActionButton,
  109. actionURL: URL(string: "http://firebase.com")
  110. )
  111. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  112. }
  113. @IBAction func showWithoutImage(_ sender: Any) {
  114. verifyLabel.text = "Verification Label"
  115. let modalMessage = TestableModalMessage(
  116. titleText: normalMessageTitle,
  117. bodyText: normalMessageBody,
  118. textColor: UIColor.black,
  119. backgroundColor: UIColor.blue,
  120. imageData: nil,
  121. actionButton: defaultActionButton,
  122. actionURL: URL(string: "http://firebase.com")
  123. )
  124. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  125. }
  126. @IBAction func showWithoutButton(_ sender: Any) {
  127. verifyLabel.text = "Verification Label"
  128. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  129. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  130. imageData: imageRawData!)
  131. let modalMessage = TestableModalMessage(
  132. titleText: normalMessageTitle,
  133. bodyText: normalMessageBody,
  134. textColor: UIColor.black,
  135. backgroundColor: UIColor.blue,
  136. imageData: fiamImageData,
  137. actionButton: nil,
  138. actionURL: nil
  139. )
  140. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  141. }
  142. @IBAction func showWithoutImageAndButton(_ sender: Any) {
  143. verifyLabel.text = "Verification Label"
  144. let modalMessage = TestableModalMessage(
  145. titleText: normalMessageTitle,
  146. bodyText: normalMessageBody,
  147. textColor: UIColor.black,
  148. backgroundColor: UIColor.blue,
  149. imageData: nil,
  150. actionButton: nil,
  151. actionURL: nil
  152. )
  153. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  154. }
  155. @IBAction func showWithLargeBody(_ sender: Any) {
  156. verifyLabel.text = "Verification Label"
  157. let modalMessage = TestableModalMessage(
  158. titleText: normalMessageTitle,
  159. bodyText: longBodyText,
  160. textColor: UIColor.black,
  161. backgroundColor: UIColor.blue,
  162. imageData: nil,
  163. actionButton: defaultActionButton,
  164. actionURL: URL(string: "http://firebase.com")
  165. )
  166. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  167. }
  168. @IBAction func showWithLargeTitleAndBody(_ sender: Any) {
  169. verifyLabel.text = "Verification Label"
  170. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  171. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  172. imageData: imageRawData!)
  173. let modalMessage = TestableModalMessage(
  174. titleText: longTitleText,
  175. bodyText: longBodyText,
  176. textColor: UIColor.black,
  177. backgroundColor: UIColor.blue,
  178. imageData: fiamImageData,
  179. actionButton: defaultActionButton,
  180. actionURL: URL(string: "http://firebase.com")
  181. )
  182. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  183. }
  184. @IBAction func showWithLargeTitle(_ sender: Any) {
  185. verifyLabel.text = "Verification Label"
  186. let modalMessage = TestableModalMessage(
  187. titleText: longBodyText,
  188. bodyText: normalMessageBody,
  189. textColor: UIColor.black,
  190. backgroundColor: UIColor.blue,
  191. imageData: nil,
  192. actionButton: defaultActionButton,
  193. actionURL: URL(string: "http://firebase.com")
  194. )
  195. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  196. }
  197. @IBAction func showWithLargeTitleAndBodyWithoutImage(_ sender: Any) {
  198. verifyLabel.text = "Verification Label"
  199. let modalMessage = TestableModalMessage(
  200. titleText: longTitleText,
  201. bodyText: longBodyText,
  202. textColor: UIColor.black,
  203. backgroundColor: UIColor.blue,
  204. imageData: nil,
  205. actionButton: defaultActionButton,
  206. actionURL: URL(string: "http://firebase.com")
  207. )
  208. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  209. }
  210. @IBAction func showWithLargeTitleWithoutBodyWithoutImageWithoutButton(_ sender: Any) {
  211. verifyLabel.text = "Verification Label"
  212. let modalMessage = TestableModalMessage(
  213. titleText: longBodyText,
  214. bodyText: "",
  215. textColor: UIColor.black,
  216. backgroundColor: UIColor.blue,
  217. imageData: nil,
  218. actionButton: nil,
  219. actionURL: nil
  220. )
  221. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  222. }
  223. @IBAction func showWithWideImage(_ sender: Any) {
  224. verifyLabel.text = "Verification Label"
  225. let imageRawData = produceImageOfSize(size: CGSize(width: 600, height: 200))
  226. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  227. imageData: imageRawData!)
  228. let modalMessage = TestableModalMessage(
  229. titleText: normalMessageTitle,
  230. bodyText: normalMessageBody,
  231. textColor: UIColor.black,
  232. backgroundColor: UIColor.blue,
  233. imageData: fiamImageData,
  234. actionButton: defaultActionButton,
  235. actionURL: URL(string: "http://firebase.com")
  236. )
  237. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  238. }
  239. @IBAction func showWithThinImage(_ sender: Any) {
  240. verifyLabel.text = "Verification Label"
  241. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 600))
  242. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  243. imageData: imageRawData!)
  244. let modalMessage = TestableModalMessage(
  245. titleText: normalMessageTitle,
  246. bodyText: normalMessageBody,
  247. textColor: UIColor.black,
  248. backgroundColor: UIColor.blue,
  249. imageData: fiamImageData,
  250. actionButton: defaultActionButton,
  251. actionURL: URL(string: "http://firebase.com")
  252. )
  253. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  254. }
  255. override func viewDidLoad() {
  256. super.viewDidLoad()
  257. // Do any additional setup after loading the view.
  258. }
  259. override func didReceiveMemoryWarning() {
  260. super.didReceiveMemoryWarning()
  261. // Dispose of any resources that can be recreated.
  262. }
  263. }