FIRIAMRenderingWindowHelper.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <TargetConditionals.h>
  17. #if TARGET_OS_IOS
  18. #import "FirebaseInAppMessaging/Sources/DefaultUI/Banner/FIRIAMBannerViewUIWindow.h"
  19. #import "FirebaseInAppMessaging/Sources/DefaultUI/FIRIAMRenderingWindowHelper.h"
  20. #import "FirebaseInAppMessaging/Sources/Private/Util/UIApplication+FIRForegroundWindowScene.h"
  21. @implementation FIRIAMRenderingWindowHelper
  22. + (UIWindow *)windowForBlockingView {
  23. static UIWindow *UIWindowForModal;
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. if (@available(iOS 13.0, tvOS 13.0, *)) {
  27. UIWindowForModal = [[self class] iOS13PlusWindow];
  28. } else {
  29. UIWindowForModal = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  30. }
  31. UIWindowForModal.windowLevel = UIWindowLevelNormal;
  32. });
  33. return UIWindowForModal;
  34. }
  35. + (UIWindow *)windowForNonBlockingView {
  36. static UIWindow *UIWindowForBanner;
  37. static dispatch_once_t onceToken;
  38. dispatch_once(&onceToken, ^{
  39. if (@available(iOS 13.0, tvOS 13.0, *)) {
  40. UIWindowForBanner = [[self class] iOS13PlusBannerWindow];
  41. } else {
  42. UIWindowForBanner =
  43. [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  44. }
  45. UIWindowForBanner.windowLevel = UIWindowLevelNormal;
  46. });
  47. return UIWindowForBanner;
  48. }
  49. + (UIWindow *)iOS13PlusWindow API_AVAILABLE(ios(13.0)) {
  50. UIWindowScene *foregroundedScene = [[UIApplication sharedApplication] fir_foregroundWindowScene];
  51. if (foregroundedScene.delegate) {
  52. return [[UIWindow alloc] initWithWindowScene:foregroundedScene];
  53. } else {
  54. return [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  55. }
  56. }
  57. + (FIRIAMBannerViewUIWindow *)iOS13PlusBannerWindow API_AVAILABLE(ios(13.0)) {
  58. UIWindowScene *foregroundedScene = [[UIApplication sharedApplication] fir_foregroundWindowScene];
  59. if (foregroundedScene.delegate) {
  60. return [[FIRIAMBannerViewUIWindow alloc] initWithWindowScene:foregroundedScene];
  61. } else {
  62. return [[FIRIAMBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  63. }
  64. }
  65. @end
  66. #endif // TARGET_OS_IOS