aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Auth/Source/FIRAuthWebView.m
diff options
context:
space:
mode:
authorGravatar Xiangtian Dai <xiangtian@google.com>2017-09-12 13:49:05 -0700
committerGravatar GitHub <noreply@github.com>2017-09-12 13:49:05 -0700
commitc8ea66eecfb256925e457d14b64bc08984da4387 (patch)
treea5c01d7f36c447111092ec80cbde68cfdb7fca07 /Firebase/Auth/Source/FIRAuthWebView.m
parente8cf906d21501513f53666a34d4c4eb3e95bef6e (diff)
Implements web view for presenting Auth web content on iOS 7 and 8. (#253)
Also (hopefully) fixes thread safety issues in presenting Auth web content.
Diffstat (limited to 'Firebase/Auth/Source/FIRAuthWebView.m')
-rw-r--r--Firebase/Auth/Source/FIRAuthWebView.m86
1 files changed, 86 insertions, 0 deletions
diff --git a/Firebase/Auth/Source/FIRAuthWebView.m b/Firebase/Auth/Source/FIRAuthWebView.m
new file mode 100644
index 0000000..80b90f0
--- /dev/null
+++ b/Firebase/Auth/Source/FIRAuthWebView.m
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2017 Google
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import "FIRAuthWebView.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@implementation FIRAuthWebView
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+ self.backgroundColor = [UIColor whiteColor];
+ [self initializeSubviews];
+ }
+ return self;
+}
+
+/** @fn initializeSubviews
+ @brief Initializes the subviews of this view.
+ */
+- (void)initializeSubviews {
+ UIWebView *webView = [self createWebView];
+ UIActivityIndicatorView *spinner = [self createSpinner];
+
+ // The order of the following controls z-order.
+ [self addSubview:webView];
+ [self addSubview:spinner];
+
+ [self layoutSubviews];
+ _webView = webView;
+ _spinner = spinner;
+}
+
+- (void)layoutSubviews {
+ CGFloat height = self.bounds.size.height;
+ CGFloat width = self.bounds.size.width;
+ _webView.frame = CGRectMake(0, 0, width, height);
+ _spinner.center = _webView.center;
+}
+
+/** @fn createWebView
+ @brief Creates a web view to be used by this view.
+ @return The newly created web view.
+ */
+- (UIWebView *)createWebView {
+ UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
+ // Trickery to make the web view not do weird things (like showing a black background when
+ // the prompt in the navigation bar animates changes.)
+ webView.opaque = NO;
+ webView.backgroundColor = [UIColor clearColor];
+ webView.scrollView.opaque = NO;
+ webView.scrollView.backgroundColor = [UIColor clearColor];
+ webView.scrollView.bounces = NO;
+ webView.scrollView.alwaysBounceVertical = NO;
+ webView.scrollView.alwaysBounceHorizontal = NO;
+ return webView;
+}
+
+/** @fn createSpinner
+ @brief Creates a spinner to be used by this view.
+ @return The newly created spinner.
+ */
+- (UIActivityIndicatorView *)createSpinner {
+ UIActivityIndicatorViewStyle spinnerStyle = UIActivityIndicatorViewStyleGray;
+ UIActivityIndicatorView *spinner =
+ [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:spinnerStyle];
+ return spinner;
+}
+
+@end
+
+NS_ASSUME_NONNULL_END