ModalMessageViewController.swift 11 KB

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