Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 65dc0c3

Browse files
committed
chore: handle potentiel null
1 parent 0be9e2c commit 65dc0c3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/webview-ext.ios.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { autoInjectJSBridgeProperty, NavigationType, scrollBounceProperty, WebVi
88

99
export * from "./webview-ext-common";
1010

11+
const messageHandlerName = "nsBridge";
12+
1113
export class WebViewExt extends WebViewExtBase {
12-
public get ios() {
13-
return this.nativeViewProtected as WKWebView;
14-
}
14+
public ios: WKWebView;
1515

1616
public static supportXLocalScheme = typeof CustomUrlSchemeHandler !== "undefined";
1717

@@ -38,7 +38,7 @@ export class WebViewExt extends WebViewExtBase {
3838

3939
const messageHandler = WKScriptMessageHandlerNotaImpl.initWithOwner(new WeakRef(this));
4040
const wkUController = (this.wkUserContentController = WKUserContentController.new());
41-
wkUController.addScriptMessageHandlerName(messageHandler, "nsBridge");
41+
wkUController.addScriptMessageHandlerName(messageHandler, messageHandlerName);
4242
configuration.userContentController = wkUController;
4343
configuration.preferences.setValueForKey(true, "allowFileAccessFromFileURLs");
4444
configuration.setValueForKey(true, "allowUniversalAccessFromFileURLs");
@@ -66,7 +66,7 @@ export class WebViewExt extends WebViewExtBase {
6666
}
6767

6868
public disposeNativeView() {
69-
this.wkWebViewConfiguration.userContentController.removeScriptMessageHandlerForName("nsBridge");
69+
this.wkWebViewConfiguration?.userContentController?.removeScriptMessageHandlerForName(messageHandlerName);
7070
this.wkWebViewConfiguration = null!;
7171
this.wkNavigationDelegate = null!;
7272
this.wkCustomUrlSchemeHandler = null!;

0 commit comments

Comments
 (0)