Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1224 from edx/saeed/LEARNER-6732
Browse files Browse the repository at this point in the history
Handle Dynamic Type Text Change For Authenticated Web Content
  • Loading branch information
saeedbashir authored Dec 27, 2018
2 parents a9bea7d + 37d43c9 commit 3f83855
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions Source/AuthenticatedWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HeaderViewInsets : ContentInsetsSource {
private protocol WebContentController {
var view : UIView {get}
var scrollView : UIScrollView {get}
var isLoading: Bool {get}

var alwaysRequiresOAuthUpdate : Bool { get}

Expand Down Expand Up @@ -81,6 +82,10 @@ private class WKWebViewContentController : WebContentController {
var initialContentState : AuthenticatedWebViewController.State {
return AuthenticatedWebViewController.State.LoadingContent
}

var isLoading: Bool {
return webView.isLoading
}
}

private let OAuthExchangePath = "/oauth2/login/"
Expand Down Expand Up @@ -133,6 +138,7 @@ public class AuthenticatedWebViewController: UIViewController, WKNavigationDeleg

automaticallyAdjustsScrollViewInsets = false
webController.view.accessibilityIdentifier = "AuthenticatedWebViewController:authenticated-web-view"
addObservers()
}

required public init?(coder aDecoder: NSCoder) {
Expand All @@ -143,26 +149,39 @@ public class AuthenticatedWebViewController: UIViewController, WKNavigationDeleg
// Prevent crash due to stale back pointer, since WKWebView's UIScrollView apparently doesn't
// use weak for its delegate
webController.scrollView.delegate = nil
NotificationCenter.default.removeObserver(self)
}

override public func viewDidLoad() {

self.state = webController.initialContentState
self.view.addSubview(webController.view)
super.viewDidLoad()

state = webController.initialContentState
view.addSubview(webController.view)
webController.view.snp.makeConstraints { make in
make.edges.equalTo(safeEdges)
}
self.loadController.setupInController(controller: self, contentView: webController.view)
loadController.setupInController(controller: self, contentView: webController.view)
webController.view.backgroundColor = OEXStyles.shared().standardBackgroundColor()
webController.scrollView.backgroundColor = OEXStyles.shared().standardBackgroundColor()
insetsController.setupInController(owner: self, scrollView: webController.scrollView)

self.insetsController.setupInController(owner: self, scrollView: webController.scrollView)


if let request = self.contentRequest {
if let request = contentRequest {
loadRequest(request: request)
}
}

private func addObservers() {
NotificationCenter.default.oex_addObserver(observer: self, name: NOTIFICATION_DYNAMIC_TEXT_TYPE_UPDATE) { (_, observer, _) in
observer.reload()
}
}

public func reload() {
guard let request = contentRequest, !webController.isLoading else { return }

state = .LoadingContent
loadRequest(request: request)
}

private func resetState() {
loadController.state = .Initial
Expand Down Expand Up @@ -332,4 +351,3 @@ public class AuthenticatedWebViewController: UIViewController, WKNavigationDeleg
}
}
}

0 comments on commit 3f83855

Please sign in to comment.