ModalMessageViewController.swift 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. }
  79. }
  80. let displayImpl = InAppMessagingDefaultDisplayImpl()
  81. @IBOutlet var verifyLabel: UILabel!
  82. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  83. with action: InAppMessagingAction) {
  84. super.messageClicked(inAppMessage, with: action)
  85. verifyLabel.text = "message clicked!"
  86. }
  87. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  88. dismissType: FIRInAppMessagingDismissType) {
  89. super.messageDismissed(inAppMessage, dismissType: dismissType)
  90. verifyLabel.text = "message dismissed!"
  91. }
  92. @IBAction func showRegular(_ sender: Any) {
  93. verifyLabel.text = "Verification Label"
  94. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  95. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  96. imageData: imageRawData!)
  97. let modalMessage = TestableModalMessage(
  98. titleText: normalMessageTitle,
  99. bodyText: normalMessageBody,
  100. textColor: UIColor.black,
  101. backgroundColor: UIColor.blue,
  102. imageData: fiamImageData,
  103. actionButton: defaultActionButton,
  104. actionURL: URL(string: "http://firebase.com")
  105. )
  106. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  107. }
  108. @IBAction func showWithoutImage(_ sender: Any) {
  109. verifyLabel.text = "Verification Label"
  110. let modalMessage = TestableModalMessage(
  111. titleText: normalMessageTitle,
  112. bodyText: normalMessageBody,
  113. textColor: UIColor.black,
  114. backgroundColor: UIColor.blue,
  115. imageData: nil,
  116. actionButton: defaultActionButton,
  117. actionURL: URL(string: "http://firebase.com")
  118. )
  119. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  120. }
  121. @IBAction func showWithoutButton(_ sender: Any) {
  122. verifyLabel.text = "Verification Label"
  123. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  124. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  125. imageData: imageRawData!)
  126. let modalMessage = TestableModalMessage(
  127. titleText: normalMessageTitle,
  128. bodyText: normalMessageBody,
  129. textColor: UIColor.black,
  130. backgroundColor: UIColor.blue,
  131. imageData: fiamImageData,
  132. actionButton: nil,
  133. actionURL: nil
  134. )
  135. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  136. }
  137. @IBAction func showWithoutImageAndButton(_ sender: Any) {
  138. verifyLabel.text = "Verification Label"
  139. let modalMessage = TestableModalMessage(
  140. titleText: normalMessageTitle,
  141. bodyText: normalMessageBody,
  142. textColor: UIColor.black,
  143. backgroundColor: UIColor.blue,
  144. imageData: nil,
  145. actionButton: nil,
  146. actionURL: nil
  147. )
  148. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  149. }
  150. @IBAction func showWithLargeBody(_ sender: Any) {
  151. verifyLabel.text = "Verification Label"
  152. let modalMessage = TestableModalMessage(
  153. titleText: normalMessageTitle,
  154. bodyText: longBodyText,
  155. textColor: UIColor.black,
  156. backgroundColor: UIColor.blue,
  157. imageData: nil,
  158. actionButton: defaultActionButton,
  159. actionURL: URL(string: "http://firebase.com")
  160. )
  161. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  162. }
  163. @IBAction func showWithLargeTitleAndBody(_ 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 = TestableModalMessage(
  169. titleText: longTitleText,
  170. bodyText: longBodyText,
  171. textColor: UIColor.black,
  172. backgroundColor: UIColor.blue,
  173. imageData: fiamImageData,
  174. actionButton: defaultActionButton,
  175. actionURL: URL(string: "http://firebase.com")
  176. )
  177. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  178. }
  179. @IBAction func showWithLargeTitle(_ sender: Any) {
  180. verifyLabel.text = "Verification Label"
  181. let modalMessage = TestableModalMessage(
  182. titleText: longBodyText,
  183. bodyText: normalMessageBody,
  184. textColor: UIColor.black,
  185. backgroundColor: UIColor.blue,
  186. imageData: nil,
  187. actionButton: defaultActionButton,
  188. actionURL: URL(string: "http://firebase.com")
  189. )
  190. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  191. }
  192. @IBAction func showWithLargeTitleAndBodyWithoutImage(_ sender: Any) {
  193. verifyLabel.text = "Verification Label"
  194. let modalMessage = TestableModalMessage(
  195. titleText: longTitleText,
  196. bodyText: longBodyText,
  197. textColor: UIColor.black,
  198. backgroundColor: UIColor.blue,
  199. imageData: nil,
  200. actionButton: defaultActionButton,
  201. actionURL: URL(string: "http://firebase.com")
  202. )
  203. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  204. }
  205. @IBAction func showWithLargeTitleWithoutBodyWithoutImageWithoutButton(_ sender: Any) {
  206. verifyLabel.text = "Verification Label"
  207. let modalMessage = TestableModalMessage(
  208. titleText: longBodyText,
  209. bodyText: "",
  210. textColor: UIColor.black,
  211. backgroundColor: UIColor.blue,
  212. imageData: nil,
  213. actionButton: nil,
  214. actionURL: nil
  215. )
  216. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  217. }
  218. @IBAction func showWithWideImage(_ sender: Any) {
  219. verifyLabel.text = "Verification Label"
  220. let imageRawData = produceImageOfSize(size: CGSize(width: 600, height: 200))
  221. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  222. imageData: imageRawData!)
  223. let modalMessage = TestableModalMessage(
  224. titleText: normalMessageTitle,
  225. bodyText: normalMessageBody,
  226. textColor: UIColor.black,
  227. backgroundColor: UIColor.blue,
  228. imageData: fiamImageData,
  229. actionButton: defaultActionButton,
  230. actionURL: URL(string: "http://firebase.com")
  231. )
  232. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  233. }
  234. @IBAction func showWithThinImage(_ sender: Any) {
  235. verifyLabel.text = "Verification Label"
  236. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 600))
  237. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  238. imageData: imageRawData!)
  239. let modalMessage = TestableModalMessage(
  240. titleText: normalMessageTitle,
  241. bodyText: normalMessageBody,
  242. textColor: UIColor.black,
  243. backgroundColor: UIColor.blue,
  244. imageData: fiamImageData,
  245. actionButton: defaultActionButton,
  246. actionURL: URL(string: "http://firebase.com")
  247. )
  248. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  249. }
  250. override func viewDidLoad() {
  251. super.viewDidLoad()
  252. // Do any additional setup after loading the view.
  253. }
  254. override func didReceiveMemoryWarning() {
  255. super.didReceiveMemoryWarning()
  256. // Dispose of any resources that can be recreated.
  257. }
  258. }