RCTModalHostViewController.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import "RCTModalHostViewController.h"
  8. #import "RCTLog.h"
  9. #import "RCTModalHostView.h"
  10. @implementation RCTModalHostViewController {
  11. CGRect _lastViewFrame;
  12. #if !TARGET_OS_TV
  13. UIStatusBarStyle _preferredStatusBarStyle;
  14. BOOL _preferredStatusBarHidden;
  15. #endif
  16. }
  17. - (instancetype)init
  18. {
  19. if (!(self = [super init])) {
  20. return nil;
  21. }
  22. #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
  23. __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
  24. if (@available(iOS 13.0, *)) {
  25. self.modalInPresentation = YES;
  26. }
  27. #endif
  28. #if !TARGET_OS_TV
  29. _preferredStatusBarStyle = [RCTSharedApplication() statusBarStyle];
  30. _preferredStatusBarHidden = [RCTSharedApplication() isStatusBarHidden];
  31. #endif
  32. return self;
  33. }
  34. - (void)viewDidLayoutSubviews
  35. {
  36. [super viewDidLayoutSubviews];
  37. if (self.boundsDidChangeBlock && !CGRectEqualToRect(_lastViewFrame, self.view.frame)) {
  38. self.boundsDidChangeBlock(self.view.bounds);
  39. _lastViewFrame = self.view.frame;
  40. }
  41. }
  42. #if !TARGET_OS_TV
  43. - (UIStatusBarStyle)preferredStatusBarStyle
  44. {
  45. return _preferredStatusBarStyle;
  46. }
  47. - (BOOL)prefersStatusBarHidden
  48. {
  49. return _preferredStatusBarHidden;
  50. }
  51. #if RCT_DEV
  52. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  53. {
  54. UIInterfaceOrientationMask appSupportedOrientationsMask =
  55. [RCTSharedApplication() supportedInterfaceOrientationsForWindow:[RCTSharedApplication() keyWindow]];
  56. if (!(_supportedInterfaceOrientations & appSupportedOrientationsMask)) {
  57. RCTLogError(
  58. @"Modal was presented with 0x%x orientations mask but the application only supports 0x%x."
  59. @"Add more interface orientations to your app's Info.plist to fix this."
  60. @"NOTE: This will crash in non-dev mode.",
  61. (unsigned)_supportedInterfaceOrientations,
  62. (unsigned)appSupportedOrientationsMask);
  63. return UIInterfaceOrientationMaskAll;
  64. }
  65. return _supportedInterfaceOrientations;
  66. }
  67. #endif // RCT_DEV
  68. #endif // !TARGET_OS_TV
  69. @end