Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iOS): Open CAPBridgeViewController for subclassing #3973

Merged
merged 18 commits into from
Dec 23, 2020
Merged

Conversation

ikeith
Copy link
Contributor

@ikeith ikeith commented Dec 21, 2020

This branch refactors CAPBridgeViewController to make it available for subclassing. This is necessary for many embedded uses and allows it address several outstanding issues.

In addition, this branch unifies much of the path handling to ensure that the config is the one true source for where the web app is located. It also eliminates some of the side effects of the previous implementation like isNewBinary() modifying UserDefaults such that it would return different results on subsequent invocations.

@ikeith ikeith changed the title View controller feat(iOS):Open CAPBridgeViewController for subclassing Dec 21, 2020
@ikeith ikeith marked this pull request as ready for review December 21, 2020 20:57
@ikeith ikeith added this to the 3.0.0 milestone Dec 21, 2020
Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead of having the webViewClass thing have an open method where the WebView is created so they can override that instead?
That way if their custom WKWebView subclass has a custom init they can use it, with current implementation it's not possible.

@ikeith ikeith requested a review from jcesarmobile December 22, 2020 16:36
@imhoffd imhoffd changed the title feat(iOS):Open CAPBridgeViewController for subclassing feat(iOS): Open CAPBridgeViewController for subclassing Dec 23, 2020
@imhoffd imhoffd merged commit a601705 into main Dec 23, 2020
@imhoffd imhoffd deleted the view-controller branch December 23, 2020 19:52
@tossaro
Copy link

tossaro commented Jun 27, 2024

hello everyone, first of all thanks for opening CAPBridgeViewController so we can create subclasses, but I am facing blockers when adding hooks to web view lifecycle like didFinish, didFail etc, due to existing loadView is final function that have:
let delegateHandler = WebViewDelegationHandler()
I have created a subclass of WebViewDelegationHandler then use at capacitorDidLoad(), but it makes the bridge not work.
So could you please make loadView not final function? or maybe any additional open function that refer to delegation like instanceDescriptor function. thank you

existing capacitor 6.1.0 file CAPBridgeViewController:
override public final func loadView() { // load the configuration and set the logging flag let configDescriptor = instanceDescriptor() let configuration = InstanceConfiguration(with: configDescriptor, isDebug: CapacitorBridge.isDevEnvironment) CAPLog.enableLogging = configuration.loggingEnabled logWarnings(for: configDescriptor) setStatusBarDefaults() setScreenOrientationDefaults() // get the web view let assetHandler = WebViewAssetHandler(router: router()) assetHandler.setAssetPath(configuration.appLocation.path) assetHandler.setServerUrl(configuration.serverURL) let delegationHandler = WebViewDelegationHandler() prepareWebView(with: configuration, assetHandler: assetHandler, delegationHandler: delegationHandler) view = webView // create the bridge capacitorBridge = CapacitorBridge(with: configuration, delegate: self, cordovaConfiguration: configDescriptor.cordovaConfiguration, assetHandler: assetHandler, delegationHandler: delegationHandler) capacitorDidLoad() if configDescriptor.instanceType == .fixed { updateBinaryVersion() } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants