You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5 KiB

6 years ago
  1. /*
  2. * Copyright 2017 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 "FIRAuthWebView.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. @implementation FIRAuthWebView
  19. - (instancetype)initWithFrame:(CGRect)frame {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. self.backgroundColor = [UIColor whiteColor];
  23. [self initializeSubviews];
  24. }
  25. return self;
  26. }
  27. /** @fn initializeSubviews
  28. @brief Initializes the subviews of this view.
  29. */
  30. - (void)initializeSubviews {
  31. UIWebView *webView = [self createWebView];
  32. UIActivityIndicatorView *spinner = [self createSpinner];
  33. // The order of the following controls z-order.
  34. [self addSubview:webView];
  35. [self addSubview:spinner];
  36. [self layoutSubviews];
  37. _webView = webView;
  38. _spinner = spinner;
  39. }
  40. - (void)layoutSubviews {
  41. CGFloat height = self.bounds.size.height;
  42. CGFloat width = self.bounds.size.width;
  43. _webView.frame = CGRectMake(0, 0, width, height);
  44. _spinner.center = _webView.center;
  45. }
  46. /** @fn createWebView
  47. @brief Creates a web view to be used by this view.
  48. @return The newly created web view.
  49. */
  50. - (UIWebView *)createWebView {
  51. UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
  52. // Trickery to make the web view not do weird things (like showing a black background when
  53. // the prompt in the navigation bar animates changes.)
  54. webView.opaque = NO;
  55. webView.backgroundColor = [UIColor clearColor];
  56. webView.scrollView.opaque = NO;
  57. webView.scrollView.backgroundColor = [UIColor clearColor];
  58. webView.scrollView.bounces = NO;
  59. webView.scrollView.alwaysBounceVertical = NO;
  60. webView.scrollView.alwaysBounceHorizontal = NO;
  61. return webView;
  62. }
  63. /** @fn createSpinner
  64. @brief Creates a spinner to be used by this view.
  65. @return The newly created spinner.
  66. */
  67. - (UIActivityIndicatorView *)createSpinner {
  68. UIActivityIndicatorViewStyle spinnerStyle = UIActivityIndicatorViewStyleGray;
  69. UIActivityIndicatorView *spinner =
  70. [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:spinnerStyle];
  71. return spinner;
  72. }
  73. @end
  74. NS_ASSUME_NONNULL_END