jsbox-cview 1.5.32 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,8 +70,7 @@ export class DialogSheet extends Sheet<
70
70
  },
71
71
  });
72
72
  this._props.cview._layout = (make, view) => {
73
- make.bottom.equalTo(view.super);
74
- make.left.right.equalTo(view.super.safeArea);
73
+ make.left.right.bottom.equalTo(view.super);
75
74
  make.top.equalTo(view.prev.bottom);
76
75
  };
77
76
  this._cview = new ContentView({
@@ -0,0 +1,145 @@
1
+ import { Base } from "./base";
2
+
3
+ /**
4
+ * # OCWebView
5
+ *
6
+ * 通过OC Runtime构建的Web视图,该控件是为了解决UIWebView无法通过CloudFlare人机检测的问题
7
+ * (TIPS:推测JSBox的网页视图实际上运行在一个iframe中,所以会出现该问题)
8
+ *
9
+ * ## Argumnets
10
+ *
11
+ * props:
12
+ * - url: string
13
+ *
14
+ * layout
15
+ *
16
+ * events:
17
+ * - didStart?: (sender: any) => void;
18
+ * - didFinish?: (sender: any) => void;
19
+ * - didFail?: (sender: any, error: NSError | null) => void;
20
+ *
21
+ * events中sender的any类型实际为WKWebView OC类型
22
+ *
23
+ * ## Methods
24
+ *
25
+ * - url
26
+ * - canGoBack
27
+ * - canGoForward
28
+ * - goBack()
29
+ * - goForward()
30
+ * - stopLoading()
31
+ * - reload()
32
+ *
33
+ */
34
+ export class OCWebView extends Base<UIView, UiTypes.RuntimeOptions> {
35
+ _defineView: () => UiTypes.RuntimeOptions;
36
+ webView: any; // 实际为WKWebView OC类型
37
+ constructor({
38
+ props,
39
+ layout,
40
+ events,
41
+ }: {
42
+ props: { url: string };
43
+ events: {
44
+ didStart?: (sender: any) => void; // 此处的any实际为WKWebView OC类型
45
+ didFinish?: (sender: any) => void;
46
+ didFail?: (sender: any, error: NSError | null) => void;
47
+ };
48
+ layout: (make: MASConstraintMaker, view: UIView) => void;
49
+ }) {
50
+ super();
51
+ // ====== 创建 WebView ======
52
+ const config = $objc("WKWebViewConfiguration").invoke("new");
53
+ config.invoke(
54
+ "setWebsiteDataStore:",
55
+ $objc("WKWebsiteDataStore").invoke("defaultDataStore"),
56
+ );
57
+ const webView = $objc("WKWebView").invoke(
58
+ "alloc.initWithFrame:configuration:",
59
+ $rect(0, 0, 0, 0),
60
+ config,
61
+ );
62
+ this.webView = webView;
63
+
64
+ this._defineView = () => {
65
+ return {
66
+ type: "runtime",
67
+ props: {
68
+ id: this.id,
69
+ view: webView,
70
+ },
71
+ layout,
72
+ events: {
73
+ ready: (sender) => {
74
+ // ====== 设置 delegate ======
75
+ const navDelegate = $delegate({
76
+ type: "WKNavigationDelegate",
77
+ events: {
78
+ "webView:didStartProvisionalNavigation:": (
79
+ wv: any,
80
+ nav: any,
81
+ ) => {
82
+ events.didStart && events.didStart(wv);
83
+ },
84
+ "webView:didFinishNavigation:": (wv: any, nav: any) => {
85
+ events.didFinish && events.didFinish(wv);
86
+ },
87
+ "webView:didFailNavigation:withError:": (
88
+ wv: any,
89
+ nav: any,
90
+ e: any,
91
+ ) => {
92
+ events.didFail && events.didFail(wv, e ? e.jsValue() : null);
93
+ },
94
+ "webView:didFailProvisionalNavigation:withError:": (
95
+ wv: any,
96
+ nav: any,
97
+ e: any,
98
+ ) => {
99
+ events.didFail && events.didFail(wv, e ? e.jsValue() : null);
100
+ },
101
+ },
102
+ });
103
+
104
+ webView.invoke("setNavigationDelegate:", navDelegate);
105
+
106
+ // ===== 加载URL ======
107
+ const urlStr = props.url;
108
+ const url = $objc("NSURL").invoke("URLWithString:", urlStr);
109
+ const req = $objc("NSURLRequest").invoke("requestWithURL:", url);
110
+ webView.invoke("loadRequest:", req);
111
+ },
112
+ },
113
+ };
114
+ };
115
+ }
116
+
117
+ get url(): string {
118
+ const nsurl = this.webView.invoke("URL");
119
+ return nsurl ? nsurl.invoke("absoluteString").rawValue() : "";
120
+ }
121
+
122
+ get canGoBack(): boolean {
123
+ return this.webView.invoke("canGoBack");
124
+ }
125
+
126
+ get canGoForward(): boolean {
127
+ return this.webView.invoke("canGoForward");
128
+ }
129
+
130
+ goBack() {
131
+ if (this.canGoBack) this.webView.invoke("goBack");
132
+ }
133
+
134
+ goForward() {
135
+ if (this.canGoForward) this.webView.invoke("goForward");
136
+ }
137
+
138
+ stopLoading() {
139
+ this.webView.invoke("stopLoading");
140
+ }
141
+
142
+ reload() {
143
+ this.webView.invoke("reload");
144
+ }
145
+ }
@@ -45,8 +45,7 @@ class DialogSheet extends sheet_1.Sheet {
45
45
  },
46
46
  });
47
47
  this._props.cview._layout = (make, view) => {
48
- make.bottom.equalTo(view.super);
49
- make.left.right.equalTo(view.super.safeArea);
48
+ make.left.right.bottom.equalTo(view.super);
50
49
  make.top.equalTo(view.prev.bottom);
51
50
  };
52
51
  this._cview = new single_views_1.ContentView({
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OCWebView = void 0;
4
+ const base_1 = require("./base");
5
+ /**
6
+ * # OCWebView
7
+ *
8
+ * 通过OC Runtime构建的Web视图,该控件是为了解决UIWebView无法通过CloudFlare人机检测的问题
9
+ * (TIPS:推测JSBox的网页视图实际上运行在一个iframe中,所以会出现该问题)
10
+ *
11
+ * ## Argumnets
12
+ *
13
+ * props:
14
+ * - url: string
15
+ *
16
+ * layout
17
+ *
18
+ * events:
19
+ * - didStart?: (sender: any) => void;
20
+ * - didFinish?: (sender: any) => void;
21
+ * - didFail?: (sender: any, error: NSError | null) => void;
22
+ *
23
+ * events中sender的any类型实际为WKWebView OC类型
24
+ *
25
+ * ## Methods
26
+ *
27
+ * - url
28
+ * - canGoBack
29
+ * - canGoForward
30
+ * - goBack()
31
+ * - goForward()
32
+ * - stopLoading()
33
+ * - reload()
34
+ *
35
+ */
36
+ class OCWebView extends base_1.Base {
37
+ constructor({ props, layout, events, }) {
38
+ super();
39
+ // ====== 创建 WebView ======
40
+ const config = $objc("WKWebViewConfiguration").invoke("new");
41
+ config.invoke("setWebsiteDataStore:", $objc("WKWebsiteDataStore").invoke("defaultDataStore"));
42
+ const webView = $objc("WKWebView").invoke("alloc.initWithFrame:configuration:", $rect(0, 0, 0, 0), config);
43
+ this.webView = webView;
44
+ this._defineView = () => {
45
+ return {
46
+ type: "runtime",
47
+ props: {
48
+ id: this.id,
49
+ view: webView,
50
+ },
51
+ layout,
52
+ events: {
53
+ ready: (sender) => {
54
+ // ====== 设置 delegate ======
55
+ const navDelegate = $delegate({
56
+ type: "WKNavigationDelegate",
57
+ events: {
58
+ "webView:didStartProvisionalNavigation:": (wv, nav) => {
59
+ events.didStart && events.didStart(wv);
60
+ },
61
+ "webView:didFinishNavigation:": (wv, nav) => {
62
+ events.didFinish && events.didFinish(wv);
63
+ },
64
+ "webView:didFailNavigation:withError:": (wv, nav, e) => {
65
+ events.didFail && events.didFail(wv, e ? e.jsValue() : null);
66
+ },
67
+ "webView:didFailProvisionalNavigation:withError:": (wv, nav, e) => {
68
+ events.didFail && events.didFail(wv, e ? e.jsValue() : null);
69
+ },
70
+ },
71
+ });
72
+ webView.invoke("setNavigationDelegate:", navDelegate);
73
+ // ===== 加载URL ======
74
+ const urlStr = props.url;
75
+ const url = $objc("NSURL").invoke("URLWithString:", urlStr);
76
+ const req = $objc("NSURLRequest").invoke("requestWithURL:", url);
77
+ webView.invoke("loadRequest:", req);
78
+ },
79
+ },
80
+ };
81
+ };
82
+ }
83
+ get url() {
84
+ const nsurl = this.webView.invoke("URL");
85
+ return nsurl ? nsurl.invoke("absoluteString").rawValue() : "";
86
+ }
87
+ get canGoBack() {
88
+ return this.webView.invoke("canGoBack");
89
+ }
90
+ get canGoForward() {
91
+ return this.webView.invoke("canGoForward");
92
+ }
93
+ goBack() {
94
+ if (this.canGoBack)
95
+ this.webView.invoke("goBack");
96
+ }
97
+ goForward() {
98
+ if (this.canGoForward)
99
+ this.webView.invoke("goForward");
100
+ }
101
+ stopLoading() {
102
+ this.webView.invoke("stopLoading");
103
+ }
104
+ reload() {
105
+ this.webView.invoke("reload");
106
+ }
107
+ }
108
+ exports.OCWebView = OCWebView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsbox-cview",
3
- "version": "1.5.32",
3
+ "version": "1.6.0",
4
4
  "description": "为 JSBox 设计的微型框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "license": "MIT",
19
19
  "devDependencies": {
20
20
  "@types/node": "^20.11.17",
21
- "browserify": "^17.0.0",
21
+ "browserify": "^17.0.1",
22
22
  "jsbox-types": "^1.0.46"
23
23
  }
24
24
  }