ModalMessageViewController.swift 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. func testModalMessage(titleText: String,
  19. bodyText: String?,
  20. textColor: UIColor,
  21. backgroundColor: UIColor,
  22. imageData: InAppMessagingImageData?,
  23. actionButton: InAppMessagingActionButton?,
  24. actionURL: URL?) -> InAppMessagingModalDisplay {
  25. return InAppMessagingModalDisplay(
  26. campaignName: "campaignName",
  27. titleText: titleText,
  28. bodyText: bodyText,
  29. textColor: textColor,
  30. backgroundColor: backgroundColor,
  31. imageData: imageData,
  32. actionButton: actionButton,
  33. actionURL: actionURL,
  34. appData: nil
  35. )
  36. }
  37. let displayImpl = InAppMessagingDefaultDisplayImpl()
  38. @IBOutlet var verifyLabel: UILabel!
  39. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  40. with action: InAppMessagingAction) {
  41. super.messageClicked(inAppMessage, with: action)
  42. verifyLabel.text = "message clicked!"
  43. }
  44. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  45. dismissType: FIRInAppMessagingDismissType) {
  46. super.messageDismissed(inAppMessage, dismissType: dismissType)
  47. verifyLabel.text = "message dismissed!"
  48. }
  49. @IBAction func showRegular(_ sender: Any) {
  50. verifyLabel.text = "Verification Label"
  51. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  52. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  53. imageData: imageRawData!)
  54. let modalMessage = testModalMessage(
  55. titleText: normalMessageTitle,
  56. bodyText: normalMessageBody,
  57. textColor: UIColor.black,
  58. backgroundColor: UIColor.blue,
  59. imageData: fiamImageData,
  60. actionButton: defaultActionButton,
  61. actionURL: URL(string: "http://firebase.com")
  62. )
  63. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  64. }
  65. @IBAction func showWithoutImage(_ sender: Any) {
  66. verifyLabel.text = "Verification Label"
  67. let modalMessage = testModalMessage(
  68. titleText: normalMessageTitle,
  69. bodyText: normalMessageBody,
  70. textColor: UIColor.black,
  71. backgroundColor: UIColor.blue,
  72. imageData: nil,
  73. actionButton: defaultActionButton,
  74. actionURL: URL(string: "http://firebase.com")
  75. )
  76. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  77. }
  78. @IBAction func showWithoutButton(_ sender: Any) {
  79. verifyLabel.text = "Verification Label"
  80. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  81. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  82. imageData: imageRawData!)
  83. let modalMessage = testModalMessage(
  84. titleText: normalMessageTitle,
  85. bodyText: normalMessageBody,
  86. textColor: UIColor.black,
  87. backgroundColor: UIColor.blue,
  88. imageData: fiamImageData,
  89. actionButton: nil,
  90. actionURL: nil
  91. )
  92. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  93. }
  94. @IBAction func showWithoutImageAndButton(_ sender: Any) {
  95. verifyLabel.text = "Verification Label"
  96. let modalMessage = testModalMessage(
  97. titleText: normalMessageTitle,
  98. bodyText: normalMessageBody,
  99. textColor: UIColor.black,
  100. backgroundColor: UIColor.blue,
  101. imageData: nil,
  102. actionButton: nil,
  103. actionURL: nil
  104. )
  105. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  106. }
  107. @IBAction func showWithLargeBody(_ sender: Any) {
  108. verifyLabel.text = "Verification Label"
  109. let modalMessage = testModalMessage(
  110. titleText: normalMessageTitle,
  111. bodyText: longBodyText,
  112. textColor: UIColor.black,
  113. backgroundColor: UIColor.blue,
  114. imageData: nil,
  115. actionButton: defaultActionButton,
  116. actionURL: URL(string: "http://firebase.com")
  117. )
  118. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  119. }
  120. @IBAction func showWithLargeTitleAndBody(_ sender: Any) {
  121. verifyLabel.text = "Verification Label"
  122. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  123. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  124. imageData: imageRawData!)
  125. let modalMessage = testModalMessage(
  126. titleText: longTitleText,
  127. bodyText: longBodyText,
  128. textColor: UIColor.black,
  129. backgroundColor: UIColor.blue,
  130. imageData: fiamImageData,
  131. actionButton: defaultActionButton,
  132. actionURL: URL(string: "http://firebase.com")
  133. )
  134. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  135. }
  136. @IBAction func showWithLargeTitle(_ sender: Any) {
  137. verifyLabel.text = "Verification Label"
  138. let modalMessage = testModalMessage(
  139. titleText: longBodyText,
  140. bodyText: normalMessageBody,
  141. textColor: UIColor.black,
  142. backgroundColor: UIColor.blue,
  143. imageData: nil,
  144. actionButton: defaultActionButton,
  145. actionURL: URL(string: "http://firebase.com")
  146. )
  147. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  148. }
  149. @IBAction func showWithLargeTitleAndBodyWithoutImage(_ sender: Any) {
  150. verifyLabel.text = "Verification Label"
  151. let modalMessage = testModalMessage(
  152. titleText: longTitleText,
  153. bodyText: longBodyText,
  154. textColor: UIColor.black,
  155. backgroundColor: UIColor.blue,
  156. imageData: nil,
  157. actionButton: defaultActionButton,
  158. actionURL: URL(string: "http://firebase.com")
  159. )
  160. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  161. }
  162. @IBAction func showWithLargeTitleWithoutBodyWithoutImageWithoutButton(_ sender: Any) {
  163. verifyLabel.text = "Verification Label"
  164. let modalMessage = testModalMessage(
  165. titleText: longBodyText,
  166. bodyText: "",
  167. textColor: UIColor.black,
  168. backgroundColor: UIColor.blue,
  169. imageData: nil,
  170. actionButton: nil,
  171. actionURL: nil
  172. )
  173. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  174. }
  175. @IBAction func showWithWideImage(_ sender: Any) {
  176. verifyLabel.text = "Verification Label"
  177. let imageRawData = produceImageOfSize(size: CGSize(width: 600, height: 200))
  178. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  179. imageData: imageRawData!)
  180. let modalMessage = testModalMessage(
  181. titleText: normalMessageTitle,
  182. bodyText: normalMessageBody,
  183. textColor: UIColor.black,
  184. backgroundColor: UIColor.blue,
  185. imageData: fiamImageData,
  186. actionButton: defaultActionButton,
  187. actionURL: URL(string: "http://firebase.com")
  188. )
  189. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  190. }
  191. @IBAction func showWithThinImage(_ sender: Any) {
  192. verifyLabel.text = "Verification Label"
  193. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 600))
  194. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  195. imageData: imageRawData!)
  196. let modalMessage = testModalMessage(
  197. titleText: normalMessageTitle,
  198. bodyText: normalMessageBody,
  199. textColor: UIColor.black,
  200. backgroundColor: UIColor.blue,
  201. imageData: fiamImageData,
  202. actionButton: defaultActionButton,
  203. actionURL: URL(string: "http://firebase.com")
  204. )
  205. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  206. }
  207. override func viewDidLoad() {
  208. super.viewDidLoad()
  209. // Do any additional setup after loading the view.
  210. }
  211. override func didReceiveMemoryWarning() {
  212. super.didReceiveMemoryWarning()
  213. // Dispose of any resources that can be recreated.
  214. }
  215. }