ModalMessageViewController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. import FirebaseInAppMessaging
  18. class ModalMessageViewController: CommonMessageTestVC {
  19. let displayImpl = InAppMessagingDefaultDisplayImpl()
  20. @IBOutlet var verifyLabel: UILabel!
  21. override func messageClicked() {
  22. super.messageClicked()
  23. verifyLabel.text = "message clicked!"
  24. }
  25. override func messageDismissed(dismissType dimissType: FIRInAppMessagingDismissType) {
  26. super.messageClicked()
  27. verifyLabel.text = "message dismissed!"
  28. }
  29. @IBAction func showRegular(_ sender: Any) {
  30. verifyLabel.text = "Verification Label"
  31. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  32. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  33. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  34. renderAsTestMessage: false,
  35. titleText: normalMessageTitle,
  36. bodyText: normalMessageBody,
  37. textColor: UIColor.black,
  38. backgroundColor: UIColor.blue,
  39. imageData: fiamImageData,
  40. actionButton: defaultActionButton)
  41. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  42. }
  43. @IBAction func showWithoutImage(_ sender: Any) {
  44. verifyLabel.text = "Verification Label"
  45. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  46. renderAsTestMessage: false,
  47. titleText: normalMessageTitle,
  48. bodyText: normalMessageBody,
  49. textColor: UIColor.black,
  50. backgroundColor: UIColor.blue,
  51. imageData: nil,
  52. actionButton: defaultActionButton)
  53. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  54. }
  55. @IBAction func showWithoutButton(_ sender: Any) {
  56. verifyLabel.text = "Verification Label"
  57. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  58. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  59. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  60. renderAsTestMessage: false,
  61. titleText: normalMessageTitle,
  62. bodyText: normalMessageBody,
  63. textColor: UIColor.black,
  64. backgroundColor: UIColor.blue,
  65. imageData: fiamImageData,
  66. actionButton: nil)
  67. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  68. }
  69. @IBAction func showWithoutImageAndButton(_ sender: Any) {
  70. verifyLabel.text = "Verification Label"
  71. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  72. renderAsTestMessage: false,
  73. titleText: normalMessageTitle,
  74. bodyText: normalMessageBody,
  75. textColor: UIColor.black,
  76. backgroundColor: UIColor.blue,
  77. imageData: nil,
  78. actionButton: nil)
  79. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  80. }
  81. @IBAction func showWithLargeBody(_ sender: Any) {
  82. verifyLabel.text = "Verification Label"
  83. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  84. renderAsTestMessage: false,
  85. titleText: normalMessageTitle,
  86. bodyText: longBodyText,
  87. textColor: UIColor.black,
  88. backgroundColor: UIColor.blue,
  89. imageData: nil,
  90. actionButton: defaultActionButton)
  91. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  92. }
  93. @IBAction func showWithLargeTitleAndBody(_ sender: Any) {
  94. verifyLabel.text = "Verification Label"
  95. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  96. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  97. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  98. renderAsTestMessage: false,
  99. titleText: longBodyText,
  100. bodyText: longBodyText,
  101. textColor: UIColor.black,
  102. backgroundColor: UIColor.blue,
  103. imageData: fiamImageData,
  104. actionButton: defaultActionButton)
  105. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  106. }
  107. @IBAction func showWithLargeTitle(_ sender: Any) {
  108. verifyLabel.text = "Verification Label"
  109. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  110. renderAsTestMessage: false,
  111. titleText: longBodyText,
  112. bodyText: normalMessageBody,
  113. textColor: UIColor.black,
  114. backgroundColor: UIColor.blue,
  115. imageData: nil,
  116. actionButton: defaultActionButton)
  117. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  118. }
  119. @IBAction func showWithLargeTitleAndBodyWithoutImage(_ sender: Any) {
  120. verifyLabel.text = "Verification Label"
  121. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  122. renderAsTestMessage: false,
  123. titleText: longBodyText,
  124. bodyText: longBodyText,
  125. textColor: UIColor.black,
  126. backgroundColor: UIColor.blue,
  127. imageData: nil,
  128. actionButton: defaultActionButton)
  129. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  130. }
  131. @IBAction func showWithLargeTitleWithoutBodyWithoutImageWithoutButton(_ sender: Any) {
  132. verifyLabel.text = "Verification Label"
  133. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  134. renderAsTestMessage: false,
  135. titleText: longBodyText,
  136. bodyText: "",
  137. textColor: UIColor.black,
  138. backgroundColor: UIColor.blue,
  139. imageData: nil,
  140. actionButton: nil)
  141. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  142. }
  143. @IBAction func showWithWideImage(_ sender: Any) {
  144. verifyLabel.text = "Verification Label"
  145. let imageRawData = produceImageOfSize(size: CGSize(width: 600, height: 200))
  146. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  147. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  148. renderAsTestMessage: false,
  149. titleText: normalMessageTitle,
  150. bodyText: normalMessageBody,
  151. textColor: UIColor.black,
  152. backgroundColor: UIColor.blue,
  153. imageData: fiamImageData,
  154. actionButton: defaultActionButton)
  155. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  156. }
  157. @IBAction func showWithThinImage(_ sender: Any) {
  158. verifyLabel.text = "Verification Label"
  159. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 600))
  160. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  161. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  162. renderAsTestMessage: false,
  163. titleText: normalMessageTitle,
  164. bodyText: normalMessageBody,
  165. textColor: UIColor.black,
  166. backgroundColor: UIColor.blue,
  167. imageData: fiamImageData,
  168. actionButton: defaultActionButton)
  169. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  170. }
  171. override func viewDidLoad() {
  172. super.viewDidLoad()
  173. // Do any additional setup after loading the view.
  174. }
  175. override func didReceiveMemoryWarning() {
  176. super.didReceiveMemoryWarning()
  177. // Dispose of any resources that can be recreated.
  178. }
  179. }