BannerMessageViewController.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 BannerMessageViewController: CommonMessageTestVC {
  18. func testBannerMessage(titleText: String,
  19. bodyText: String?,
  20. textColor: UIColor,
  21. backgroundColor: UIColor,
  22. imageData: InAppMessagingImageData?,
  23. actionURL: URL?) -> InAppMessagingBannerDisplay {
  24. return InAppMessagingBannerDisplay(
  25. campaignName: "campaignName",
  26. titleText: titleText,
  27. bodyText: bodyText,
  28. textColor: textColor,
  29. backgroundColor: backgroundColor,
  30. imageData: imageData,
  31. actionURL: actionURL,
  32. appData: nil
  33. )
  34. }
  35. let displayImpl = InAppMessagingDefaultDisplayImpl()
  36. @IBOutlet var verifyLabel: UILabel!
  37. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  38. with action: InAppMessagingAction) {
  39. super.messageClicked(inAppMessage, with: action)
  40. verifyLabel.text = "message clicked!"
  41. }
  42. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  43. dismissType: InAppMessagingDismissType) {
  44. super.messageDismissed(inAppMessage, dismissType: dismissType)
  45. verifyLabel.text = "message dismissed!"
  46. }
  47. @IBAction func showRegularBannerTapped(_ sender: Any) {
  48. verifyLabel.text = "Verification Label"
  49. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  50. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  51. imageData: imageRawData!)
  52. let bannerMessage = testBannerMessage(
  53. titleText: normalMessageTitle,
  54. bodyText: normalMessageBody,
  55. textColor: UIColor.black,
  56. backgroundColor: UIColor.blue,
  57. imageData: fiamImageData,
  58. actionURL: URL(string: "http://firebase.com")
  59. )
  60. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  61. }
  62. @IBAction func showBannerViewWithoutImageTapped(_ sender: Any) {
  63. verifyLabel.text = "Verification Label"
  64. let bannerMessage = testBannerMessage(
  65. titleText: normalMessageTitle,
  66. bodyText: normalMessageBody,
  67. textColor: UIColor.black,
  68. backgroundColor: UIColor.blue,
  69. imageData: nil,
  70. actionURL: URL(string: "http://firebase.com")
  71. )
  72. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  73. }
  74. @IBAction func showBannerViewWithWideImageTapped(_ sender: Any) {
  75. verifyLabel.text = "Verification Label"
  76. let imageRawData = produceImageOfSize(size: CGSize(width: 800, height: 200))
  77. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  78. imageData: imageRawData!)
  79. let bannerMessage = testBannerMessage(
  80. titleText: normalMessageTitle,
  81. bodyText: normalMessageBody,
  82. textColor: UIColor.black,
  83. backgroundColor: UIColor.blue,
  84. imageData: fiamImageData,
  85. actionURL: URL(string: "http://firebase.com")
  86. )
  87. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  88. }
  89. @IBAction func showBannerViewWithNarrowImageTapped(_ sender: Any) {
  90. verifyLabel.text = "Verification Label"
  91. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 800))
  92. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  93. imageData: imageRawData!)
  94. let bannerMessage = testBannerMessage(
  95. titleText: normalMessageTitle,
  96. bodyText: normalMessageBody,
  97. textColor: UIColor.black,
  98. backgroundColor: UIColor.blue,
  99. imageData: fiamImageData,
  100. actionURL: URL(string: "http://firebase.com")
  101. )
  102. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  103. }
  104. @IBAction func showBannerViewWithLargeBodyTextTapped(_ sender: Any) {
  105. verifyLabel.text = "Verification Label"
  106. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  107. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  108. imageData: imageRawData!)
  109. let bannerMessage = testBannerMessage(
  110. titleText: normalMessageTitle,
  111. bodyText: longBodyText,
  112. textColor: UIColor.black,
  113. backgroundColor: UIColor.blue,
  114. imageData: fiamImageData,
  115. actionURL: URL(string: "http://firebase.com")
  116. )
  117. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  118. }
  119. @IBAction func showBannerViewWithLongTitleTextTapped(_ sender: Any) {
  120. verifyLabel.text = "Verification Label"
  121. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  122. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  123. imageData: imageRawData!)
  124. let modalMessage = testBannerMessage(
  125. titleText: longTitleText,
  126. bodyText: normalMessageBody,
  127. textColor: UIColor.black,
  128. backgroundColor: UIColor.blue,
  129. imageData: fiamImageData,
  130. actionURL: URL(string: "http://firebase.com")
  131. )
  132. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  133. }
  134. }