jsbox-cview 1.6.5 → 1.6.7
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.
- package/README.md +4 -0
- package/dist/components/alert/input-alert.d.ts +22 -0
- package/dist/components/alert/input-alert.js +1 -2
- package/dist/components/alert/login-alert.d.ts +21 -0
- package/dist/components/alert/login-alert.js +1 -2
- package/dist/components/alert/plain-alert.d.ts +15 -0
- package/dist/components/alert/plain-alert.js +1 -2
- package/dist/components/alert/uialert.d.ts +29 -0
- package/{components/base.ts → dist/components/base.d.ts} +9 -28
- package/dist/components/custom-navigation-bar.d.ts +117 -0
- package/dist/components/custom-navigation-bar.js +7 -1
- package/dist/components/dialogs/dialog-sheet.d.ts +46 -0
- package/dist/components/dialogs/dialog-sheet.js +3 -1
- package/dist/components/dialogs/form-dialog.d.ts +15 -0
- package/dist/components/dialogs/form-dialog.js +1 -2
- package/dist/components/dialogs/list-dialog.d.ts +23 -0
- package/dist/components/dialogs/list-dialog.js +2 -3
- package/dist/components/dialogs/text-dialog.d.ts +13 -0
- package/dist/components/dialogs/text-dialog.js +1 -2
- package/dist/components/dynamic-contextmenu-view.d.ts +40 -0
- package/dist/components/dynamic-contextmenu-view.js +5 -1
- package/dist/components/dynamic-itemsize-matrix.d.ts +79 -0
- package/dist/components/dynamic-itemsize-matrix.js +18 -15
- package/dist/components/dynamic-itemsize-section-matrix.d.ts +115 -0
- package/dist/components/dynamic-itemsize-section-matrix.js +293 -0
- package/dist/components/dynamic-preference-listview.d.ts +63 -0
- package/dist/components/dynamic-preference-listview.js +25 -16
- package/dist/components/dynamic-rowheight-list.d.ts +38 -0
- package/dist/components/dynamic-rowheight-list.js +10 -3
- package/dist/components/enhanced-imageview.d.ts +41 -0
- package/dist/components/enhanced-imageview.js +1 -1
- package/dist/components/flowlayout.d.ts +63 -0
- package/dist/components/flowlayout.js +10 -13
- package/dist/components/image-pager.d.ts +49 -0
- package/dist/components/image-pager.js +6 -1
- package/dist/components/oc-webview.d.ts +64 -0
- package/dist/components/oc-webview.js +13 -5
- package/dist/components/page-control.d.ts +45 -0
- package/dist/components/page-control.js +2 -13
- package/dist/components/pageviewer-titlebar.d.ts +48 -0
- package/dist/components/pageviewer-titlebar.js +7 -13
- package/dist/components/pageviewer.d.ts +41 -0
- package/dist/components/pageviewer.js +4 -1
- package/dist/components/refresh-button.d.ts +25 -0
- package/dist/components/refresh-button.js +3 -4
- package/dist/components/rotating-view.d.ts +45 -0
- package/dist/components/rotating-view.js +10 -2
- package/dist/components/searchbar.d.ts +118 -0
- package/dist/components/searchbar.js +8 -1
- package/dist/components/sheet.d.ts +42 -0
- package/dist/components/single-views.d.ts +289 -0
- package/dist/components/single-views.js +11 -4
- package/dist/components/spinners/loading-dual-ring.d.ts +18 -0
- package/dist/components/spinners/loading-wedges.d.ts +15 -0
- package/dist/components/spinners/spinner-androidstyle.d.ts +30 -0
- package/dist/components/spinners/spinner-androidstyle.js +7 -1
- package/dist/components/static-preference-listview.d.ts +389 -0
- package/dist/components/static-preference-listview.js +13 -10
- package/dist/components/symbol-button.d.ts +39 -0
- package/dist/components/symbol-button.js +8 -1
- package/dist/components/tabbar.d.ts +140 -0
- package/dist/components/tabbar.js +8 -1
- package/dist/controller/base-controller.d.ts +125 -0
- package/dist/controller/base-controller.js +11 -11
- package/dist/controller/controller-router.d.ts +48 -0
- package/dist/controller/pageviewer-controller.d.ts +38 -0
- package/dist/controller/pageviewer-controller.js +4 -1
- package/dist/controller/presented-page-controller.d.ts +41 -0
- package/dist/controller/presented-page-controller.js +7 -9
- package/dist/controller/splitview-controller.d.ts +90 -0
- package/dist/controller/splitview-controller.js +27 -11
- package/dist/controller/tabbar-controller.d.ts +49 -0
- package/dist/controller/tabbar-controller.js +12 -15
- package/{index.ts → dist/index.d.ts} +2 -0
- package/dist/index.js +2 -0
- package/dist/utils/colors.d.ts +7 -0
- package/dist/utils/cvid.d.ts +11 -0
- package/dist/utils/l10n.d.ts +1 -0
- package/dist/utils/l10n.js +1 -2
- package/dist/utils/path.d.ts +8 -0
- package/dist/utils/path.js +8 -9
- package/dist/utils/rect.d.ts +38 -0
- package/dist/utils/rect.js +8 -9
- package/dist/utils/uitools.d.ts +75 -0
- package/dist/utils/uitools.js +6 -6
- package/package.json +20 -5
- package/.prettierignore +0 -6
- package/.prettierrc +0 -3
- package/components/alert/input-alert.ts +0 -64
- package/components/alert/login-alert.ts +0 -66
- package/components/alert/plain-alert.ts +0 -39
- package/components/alert/uialert.ts +0 -107
- package/components/custom-navigation-bar.ts +0 -579
- package/components/dialogs/dialog-sheet.ts +0 -111
- package/components/dialogs/form-dialog.ts +0 -63
- package/components/dialogs/list-dialog.ts +0 -119
- package/components/dialogs/text-dialog.ts +0 -44
- package/components/dynamic-contextmenu-view.ts +0 -115
- package/components/dynamic-itemsize-matrix.ts +0 -206
- package/components/dynamic-preference-listview.ts +0 -684
- package/components/dynamic-rowheight-list.ts +0 -77
- package/components/enhanced-imageview.ts +0 -132
- package/components/flowlayout.ts +0 -248
- package/components/image-pager.ts +0 -180
- package/components/oc-webview.ts +0 -177
- package/components/page-control.ts +0 -93
- package/components/pageviewer-titlebar.ts +0 -166
- package/components/pageviewer.ts +0 -125
- package/components/refresh-button.ts +0 -83
- package/components/rotating-view.ts +0 -133
- package/components/searchbar.ts +0 -398
- package/components/sheet.ts +0 -104
- package/components/single-views.ts +0 -956
- package/components/spinners/loading-dual-ring.ts +0 -97
- package/components/spinners/loading-wedges.ts +0 -106
- package/components/spinners/spinner-androidstyle.ts +0 -269
- package/components/static-preference-listview.ts +0 -1282
- package/components/symbol-button.ts +0 -108
- package/components/tabbar.ts +0 -453
- package/controller/base-controller.ts +0 -214
- package/controller/controller-router.ts +0 -73
- package/controller/pageviewer-controller.ts +0 -93
- package/controller/presented-page-controller.ts +0 -76
- package/controller/splitview-controller.ts +0 -359
- package/controller/tabbar-controller.ts +0 -131
- package/dist/test/custom-navigation-bar.js +0 -40
- package/dist/test/dialog-sheet.js +0 -40
- package/dist/test/dynamic-contextmenu-view.js +0 -66
- package/dist/test/dynamic-itemsize-matrix.js +0 -74
- package/dist/test/dynamic-preference-listview.js +0 -150
- package/dist/test/flowlayout.js +0 -76
- package/dist/test/form-dialog.js +0 -51
- package/dist/test/oc-webview.js +0 -195
- package/dist/test/pageviewer-controller.js +0 -20
- package/dist/test/pageviewer-titlebar.js +0 -18
- package/dist/test/pageviewer.js +0 -32
- package/dist/test/refresh-button.js +0 -26
- package/dist/test/searchbar.js +0 -36
- package/dist/test/splitview-controller.js +0 -41
- package/dist/test/static-preference-listview.js +0 -143
- package/dist/test/tabbar-controller.js +0 -48
- package/test/custom-navigation-bar.ts +0 -40
- package/test/dialog-sheet.ts +0 -40
- package/test/dynamic-contextmenu-view.ts +0 -67
- package/test/dynamic-itemsize-matrix.ts +0 -74
- package/test/dynamic-preference-listview.ts +0 -151
- package/test/flowlayout.ts +0 -79
- package/test/form-dialog.ts +0 -48
- package/test/oc-webview.ts +0 -197
- package/test/pageviewer-controller.ts +0 -21
- package/test/pageviewer-titlebar.ts +0 -18
- package/test/pageviewer.ts +0 -31
- package/test/refresh-button.ts +0 -26
- package/test/searchbar.ts +0 -38
- package/test/splitview-controller.ts +0 -42
- package/test/static-preference-listview.ts +0 -142
- package/test/tabbar-controller.ts +0 -49
- package/tsconfig.json +0 -122
- package/utils/colors.ts +0 -17
- package/utils/cvid.ts +0 -32
- package/utils/l10n.ts +0 -42
- package/utils/path.ts +0 -97
- package/utils/rect.ts +0 -90
- package/utils/uitools.ts +0 -122
package/components/oc-webview.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
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
|
-
* - evaluateJavaScript(script)
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
export class OCWebView extends Base<UIView, UiTypes.RuntimeOptions> {
|
|
36
|
-
_defineView: () => UiTypes.RuntimeOptions;
|
|
37
|
-
webView: any; // 实际为WKWebView OC类型
|
|
38
|
-
private _originUrl: string;
|
|
39
|
-
constructor({
|
|
40
|
-
props,
|
|
41
|
-
layout,
|
|
42
|
-
events,
|
|
43
|
-
}: {
|
|
44
|
-
props: { url: string };
|
|
45
|
-
events: {
|
|
46
|
-
didStart?: (sender: any) => void; // 此处的any实际为WKWebView OC类型
|
|
47
|
-
didFinish?: (sender: any) => void;
|
|
48
|
-
didFail?: (sender: any, error: NSError | null) => void;
|
|
49
|
-
};
|
|
50
|
-
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
51
|
-
}) {
|
|
52
|
-
super();
|
|
53
|
-
// ====== 创建 WebView ======
|
|
54
|
-
const config = $objc("WKWebViewConfiguration").invoke("new");
|
|
55
|
-
config.invoke("setWebsiteDataStore:", $objc("WKWebsiteDataStore").invoke("defaultDataStore"));
|
|
56
|
-
const webView = $objc("WKWebView").invoke("alloc.initWithFrame:configuration:", $rect(0, 0, 0, 0), config);
|
|
57
|
-
this.webView = webView;
|
|
58
|
-
this._originUrl = props.url;
|
|
59
|
-
|
|
60
|
-
this._defineView = () => {
|
|
61
|
-
return {
|
|
62
|
-
type: "runtime",
|
|
63
|
-
props: {
|
|
64
|
-
id: this.id,
|
|
65
|
-
view: webView,
|
|
66
|
-
},
|
|
67
|
-
layout,
|
|
68
|
-
events: {
|
|
69
|
-
ready: (sender) => {
|
|
70
|
-
// ====== 设置 delegate ======
|
|
71
|
-
const navDelegate = $delegate({
|
|
72
|
-
type: "WKNavigationDelegate",
|
|
73
|
-
events: {
|
|
74
|
-
"webView:didStartProvisionalNavigation:": (wv: any, nav: any) => {
|
|
75
|
-
events.didStart && events.didStart(wv);
|
|
76
|
-
},
|
|
77
|
-
"webView:didFinishNavigation:": (wv: any, nav: any) => {
|
|
78
|
-
events.didFinish && events.didFinish(wv);
|
|
79
|
-
},
|
|
80
|
-
"webView:didFailNavigation:withError:": (wv: any, nav: any, e: any) => {
|
|
81
|
-
events.didFail && events.didFail(wv, e ? e.jsValue() : null);
|
|
82
|
-
},
|
|
83
|
-
"webView:didFailProvisionalNavigation:withError:": (wv: any, nav: any, e: any) => {
|
|
84
|
-
events.didFail && events.didFail(wv, e ? e.jsValue() : null);
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
webView.invoke("setNavigationDelegate:", navDelegate);
|
|
90
|
-
|
|
91
|
-
// ===== 加载URL ======
|
|
92
|
-
const urlStr = props.url;
|
|
93
|
-
const url = $objc("NSURL").invoke("URLWithString:", urlStr);
|
|
94
|
-
const req = $objc("NSURLRequest").invoke("requestWithURL:", url);
|
|
95
|
-
webView.invoke("loadRequest:", req);
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
get url(): string {
|
|
103
|
-
const nsurl = this.webView.invoke("URL");
|
|
104
|
-
return nsurl ? nsurl.invoke("absoluteString").rawValue() : "";
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
set url(urlStr: string) {
|
|
108
|
-
const url = $objc("NSURL").invoke("URLWithString:", urlStr);
|
|
109
|
-
const req = $objc("NSURLRequest").invoke("requestWithURL:", url);
|
|
110
|
-
this.webView.invoke("loadRequest:", req);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get title(): string {
|
|
114
|
-
const title = this.webView.invoke("title");
|
|
115
|
-
return title ? title.rawValue() : "";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get canGoBack(): boolean {
|
|
119
|
-
return this.webView.invoke("canGoBack");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get canGoForward(): boolean {
|
|
123
|
-
return this.webView.invoke("canGoForward");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
goBack() {
|
|
127
|
-
if (this.canGoBack) this.webView.invoke("goBack");
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
goForward() {
|
|
131
|
-
if (this.canGoForward) this.webView.invoke("goForward");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
stopLoading() {
|
|
135
|
-
this.webView.invoke("stopLoading");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
reload() {
|
|
139
|
-
this.webView.invoke("reload");
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
reloadFromOrigin() {
|
|
143
|
-
this.url = this._originUrl;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
exec<T = any>(script: string): Promise<T> {
|
|
147
|
-
return new Promise((resolve, reject) => {
|
|
148
|
-
this.webView.invoke(
|
|
149
|
-
"evaluateJavaScript:completionHandler:",
|
|
150
|
-
script,
|
|
151
|
-
$block("void, id, NSError *", (result: any, error: any) => {
|
|
152
|
-
const jsError = error ? error.jsValue() : null;
|
|
153
|
-
if (jsError) {
|
|
154
|
-
reject(jsError);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (!result) {
|
|
158
|
-
resolve(result);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (typeof result.jsValue === "function") {
|
|
162
|
-
resolve(result.jsValue());
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
resolve(result);
|
|
166
|
-
}),
|
|
167
|
-
);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
eval({ script, handler }: { script: string; handler: (result: any, error?: NSError) => void }) {
|
|
172
|
-
this.exec(script).then(
|
|
173
|
-
(result) => handler(result),
|
|
174
|
-
(error) => handler(undefined, error),
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Runtime } from "./single-views";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* 基于 Runtime 构建 PageControl
|
|
6
|
-
*
|
|
7
|
-
* 请注意本视图如果没有足够的横向宽度,会显示不全
|
|
8
|
-
*
|
|
9
|
-
* @property currentPage: number
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export class PageControl extends Runtime {
|
|
13
|
-
private _numberOfPages: number;
|
|
14
|
-
private _currentPage: number;
|
|
15
|
-
private _pageIndicatorTintColor?: UIColor;
|
|
16
|
-
private _currentPageIndicatorTintColor?: UIColor;
|
|
17
|
-
private _changed?: (sender: PageControl, currentPage: number) => void;
|
|
18
|
-
private _pageControl: any;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @param props 属性
|
|
23
|
-
* - numberOfPages: 页面数量
|
|
24
|
-
* - currentPage: 当前页面
|
|
25
|
-
* - pageIndicatorTintColor?: 页面指示器颜色
|
|
26
|
-
* - currentPageIndicatorTintColor?: 当前页面指示器颜色
|
|
27
|
-
* @param layout 布局
|
|
28
|
-
* @param events 事件
|
|
29
|
-
* - changed: (sender: PageControl, currentPage: number) => void
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
constructor({
|
|
33
|
-
props,
|
|
34
|
-
layout,
|
|
35
|
-
events = {},
|
|
36
|
-
}: {
|
|
37
|
-
props: {
|
|
38
|
-
numberOfPages?: number;
|
|
39
|
-
currentPage?: number;
|
|
40
|
-
pageIndicatorTintColor?: UIColor;
|
|
41
|
-
currentPageIndicatorTintColor?: UIColor;
|
|
42
|
-
};
|
|
43
|
-
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
44
|
-
events?: {
|
|
45
|
-
changed?: (sender: PageControl, currentPage: number) => void;
|
|
46
|
-
};
|
|
47
|
-
}) {
|
|
48
|
-
const {
|
|
49
|
-
numberOfPages = 3,
|
|
50
|
-
currentPage = 0,
|
|
51
|
-
pageIndicatorTintColor,
|
|
52
|
-
currentPageIndicatorTintColor,
|
|
53
|
-
...restProps
|
|
54
|
-
} = props;
|
|
55
|
-
const { changed, ...restEvents } = events;
|
|
56
|
-
super({ props: restProps, layout, events: restEvents });
|
|
57
|
-
this._numberOfPages = numberOfPages;
|
|
58
|
-
this._currentPage = currentPage;
|
|
59
|
-
this._pageIndicatorTintColor = pageIndicatorTintColor;
|
|
60
|
-
this._currentPageIndicatorTintColor = currentPageIndicatorTintColor;
|
|
61
|
-
this._changed = changed;
|
|
62
|
-
this._pageControl = this._createPageControl();
|
|
63
|
-
if (this._props) this._props.view = this._pageControl;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
_createPageControl() {
|
|
67
|
-
const pageControl = $objc("UIPageControl").$new();
|
|
68
|
-
pageControl.$setNumberOfPages(this._numberOfPages);
|
|
69
|
-
pageControl.$setCurrentPage(this._currentPage);
|
|
70
|
-
if (this._pageIndicatorTintColor) pageControl.$setPageIndicatorTintColor(this._pageIndicatorTintColor.ocValue());
|
|
71
|
-
if (this._currentPageIndicatorTintColor)
|
|
72
|
-
pageControl.$setCurrentPageIndicatorTintColor(this._currentPageIndicatorTintColor.ocValue());
|
|
73
|
-
|
|
74
|
-
pageControl.$addEventHandler({
|
|
75
|
-
events: $UIEvent.valueChanged,
|
|
76
|
-
handler: $block("void", () => {
|
|
77
|
-
const currentPage = pageControl.$currentPage();
|
|
78
|
-
this._currentPage = currentPage;
|
|
79
|
-
if (this._changed) this._changed(this, currentPage);
|
|
80
|
-
}),
|
|
81
|
-
});
|
|
82
|
-
return pageControl;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get currentPage() {
|
|
86
|
-
return this._currentPage;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
set currentPage(num) {
|
|
90
|
-
this._currentPage = num;
|
|
91
|
-
if (this._pageControl) this._pageControl.$setCurrentPage(num);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { Base } from "./base";
|
|
2
|
-
import { ContentView, Label, Stack } from "./single-views";
|
|
3
|
-
|
|
4
|
-
function weightedAverageColors(c0: UIColor, c1: UIColor, w: number) {
|
|
5
|
-
const red = c0.components.red * w + c1.components.red * (1 - w);
|
|
6
|
-
const green = c0.components.green * w + c1.components.green * (1 - w);
|
|
7
|
-
const blue = c0.components.blue * w + c1.components.blue * (1 - w);
|
|
8
|
-
return $rgb(red, green, blue);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface PageViewerTitleBarProps {
|
|
12
|
-
items: string[];
|
|
13
|
-
index?: number;
|
|
14
|
-
selectedItemColor?: UIColor;
|
|
15
|
-
defaultItemColor?: UIColor;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface PageViewerTitleBarEvents extends UiTypes.BaseViewEvents {
|
|
19
|
-
changed?: (cview: PageViewerTitleBar, index: number) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* [PageViewer](./pageviewer.ts)配套的标题栏
|
|
24
|
-
* @property index: number
|
|
25
|
-
*/
|
|
26
|
-
export class PageViewerTitleBar extends Base<UIView, UiTypes.ViewOptions> {
|
|
27
|
-
private _props: Required<PageViewerTitleBarProps>;
|
|
28
|
-
private _floatedIndex: number;
|
|
29
|
-
private _lineStartLocationPercentage: number;
|
|
30
|
-
labels: Label[];
|
|
31
|
-
stack: Stack;
|
|
32
|
-
placeholderView: ContentView;
|
|
33
|
-
line: ContentView;
|
|
34
|
-
|
|
35
|
-
_defineView: () => UiTypes.ViewOptions;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* @param props 属性
|
|
40
|
-
* - items: string[]
|
|
41
|
-
* - index: number
|
|
42
|
-
* - selectedItemColor
|
|
43
|
-
* - defaultItemColor
|
|
44
|
-
* @param layout 布局
|
|
45
|
-
* @param events 事件
|
|
46
|
-
* - changed: (cview, index) => void 在点击变更 index 的时候回调
|
|
47
|
-
*/
|
|
48
|
-
constructor({
|
|
49
|
-
props,
|
|
50
|
-
layout,
|
|
51
|
-
events = {},
|
|
52
|
-
}: {
|
|
53
|
-
props: PageViewerTitleBarProps;
|
|
54
|
-
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
55
|
-
events: PageViewerTitleBarEvents;
|
|
56
|
-
}) {
|
|
57
|
-
super();
|
|
58
|
-
this._props = {
|
|
59
|
-
index: 0,
|
|
60
|
-
selectedItemColor: $color("systemLink"),
|
|
61
|
-
defaultItemColor: $color("secondaryText"),
|
|
62
|
-
...props,
|
|
63
|
-
};
|
|
64
|
-
const { changed, ...restEvents } = events;
|
|
65
|
-
this._floatedIndex = this._props.index;
|
|
66
|
-
this._lineStartLocationPercentage = this._floatedIndex / this._props.items.length;
|
|
67
|
-
this.labels = this._props.items.map((n, i) => {
|
|
68
|
-
return new Label({
|
|
69
|
-
props: {
|
|
70
|
-
text: n,
|
|
71
|
-
font: $font("bold", 17),
|
|
72
|
-
textColor: i === this.index ? this._props.selectedItemColor : this._props.defaultItemColor,
|
|
73
|
-
align: $align.center,
|
|
74
|
-
userInteractionEnabled: true,
|
|
75
|
-
},
|
|
76
|
-
events: {
|
|
77
|
-
tapped: (sender) => {
|
|
78
|
-
this.index = i;
|
|
79
|
-
if (changed) changed(this, i);
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
this.stack = new Stack({
|
|
85
|
-
props: {
|
|
86
|
-
axis: $stackViewAxis.horizontal,
|
|
87
|
-
distribution: $stackViewDistribution.fillEqually,
|
|
88
|
-
stack: {
|
|
89
|
-
views: this.labels.map((n) => n.definition),
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
layout: $layout.fill,
|
|
93
|
-
});
|
|
94
|
-
this.placeholderView = new ContentView({
|
|
95
|
-
props: {
|
|
96
|
-
bgcolor: $color("clear"),
|
|
97
|
-
},
|
|
98
|
-
layout: (make, view) => {
|
|
99
|
-
make.left.bottom.inset(0);
|
|
100
|
-
make.width.equalTo(view.super).multipliedBy(this._floatedIndex / this._props.items.length);
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
this.line = new ContentView({
|
|
104
|
-
props: {
|
|
105
|
-
bgcolor: this._props.selectedItemColor,
|
|
106
|
-
},
|
|
107
|
-
layout: (make, view) => {
|
|
108
|
-
make.height.equalTo(4);
|
|
109
|
-
make.width.equalTo(view.super).dividedBy(this._props.items.length);
|
|
110
|
-
make.bottom.inset(0);
|
|
111
|
-
make.left.equalTo(view.prev.right);
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
this._defineView = () => {
|
|
115
|
-
return {
|
|
116
|
-
type: "view",
|
|
117
|
-
props: {
|
|
118
|
-
id: this.id,
|
|
119
|
-
},
|
|
120
|
-
layout,
|
|
121
|
-
events: restEvents,
|
|
122
|
-
views: [this.stack.definition, this.placeholderView.definition, this.line.definition],
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
get lineStartLocationPercentage() {
|
|
128
|
-
return this._lineStartLocationPercentage;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
set lineStartLocationPercentage(percent) {
|
|
132
|
-
this._lineStartLocationPercentage = percent;
|
|
133
|
-
this.placeholderView.view.remakeLayout((make, view) => {
|
|
134
|
-
make.left.bottom.inset(0);
|
|
135
|
-
make.width.equalTo(view.super).multipliedBy(percent);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
get floatedIndex() {
|
|
140
|
-
return this._floatedIndex;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
set floatedIndex(floatedIndex) {
|
|
144
|
-
this._floatedIndex = floatedIndex;
|
|
145
|
-
this.lineStartLocationPercentage = floatedIndex / this._props.items.length;
|
|
146
|
-
this.labels.forEach((n, i) => {
|
|
147
|
-
if (Math.abs(floatedIndex - i) < 1) {
|
|
148
|
-
n.view.textColor = weightedAverageColors(
|
|
149
|
-
this._props.selectedItemColor,
|
|
150
|
-
this._props.defaultItemColor,
|
|
151
|
-
floatedIndex - i > 0 ? 1 - (floatedIndex - i) : 1 - (i - floatedIndex),
|
|
152
|
-
);
|
|
153
|
-
} else {
|
|
154
|
-
n.view.textColor = this._props.defaultItemColor;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get index() {
|
|
160
|
-
return this._props.index;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
set index(index) {
|
|
164
|
-
this._props.index = index;
|
|
165
|
-
}
|
|
166
|
-
}
|
package/components/pageviewer.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { Base } from "./base";
|
|
2
|
-
import { ContentView, Scroll } from "./single-views";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 与JSBox内置的Gallery功能类似,但是效果更好,可以伴随翻页实现联动效果
|
|
6
|
-
* 参见[pageviewer-titlebar.ts](./pageviewer-titlebar.ts)
|
|
7
|
-
*
|
|
8
|
-
* @property page: number 当前页码(无动画效果)
|
|
9
|
-
* @method scrollToPage(page: number) 滚动到某一页(带有动画效果)
|
|
10
|
-
*/
|
|
11
|
-
export class PageViewer extends Base<UIView, UiTypes.ViewOptions> {
|
|
12
|
-
private _props: {
|
|
13
|
-
page: number;
|
|
14
|
-
cviews: Base<any, any>[];
|
|
15
|
-
};
|
|
16
|
-
private _events: {
|
|
17
|
-
changed?: (cview: PageViewer, page: number) => void;
|
|
18
|
-
floatPageChanged?: (cview: PageViewer, floatPage: number) => void;
|
|
19
|
-
};
|
|
20
|
-
private _pageWidth: number;
|
|
21
|
-
private _floatPage: number;
|
|
22
|
-
scroll: Scroll;
|
|
23
|
-
_defineView: () => UiTypes.ViewOptions;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param props 属性
|
|
28
|
-
* - page: number
|
|
29
|
-
* - cviews: Base<any, any>[]
|
|
30
|
-
* @param layout 布局
|
|
31
|
-
* @param events 事件
|
|
32
|
-
* - changed: (cview, page) => void 页面改变时回调
|
|
33
|
-
* - floatPageChanged: (cview, floatPage) => void 滚动时回调(用于绑定其他联合滚动的控件)
|
|
34
|
-
*/
|
|
35
|
-
constructor({
|
|
36
|
-
props,
|
|
37
|
-
layout,
|
|
38
|
-
events = {},
|
|
39
|
-
}: {
|
|
40
|
-
props: {
|
|
41
|
-
page?: number;
|
|
42
|
-
cviews: Base<any, any>[];
|
|
43
|
-
};
|
|
44
|
-
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
45
|
-
events: {
|
|
46
|
-
changed?: (cview: PageViewer, page: number) => void;
|
|
47
|
-
floatPageChanged?: (cview: PageViewer, floatPage: number) => void;
|
|
48
|
-
};
|
|
49
|
-
}) {
|
|
50
|
-
super();
|
|
51
|
-
this._props = {
|
|
52
|
-
page: 0,
|
|
53
|
-
...props,
|
|
54
|
-
};
|
|
55
|
-
this._events = events;
|
|
56
|
-
this._pageWidth = 0;
|
|
57
|
-
this._floatPage = this._props.page;
|
|
58
|
-
const contentViews = this._props.cviews.map((n) => {
|
|
59
|
-
return new ContentView({
|
|
60
|
-
views: [n.definition],
|
|
61
|
-
layout: (make, view) => {
|
|
62
|
-
make.height.width.equalTo(view.super);
|
|
63
|
-
make.left.equalTo(view.prev ? view.prev.right : view.super);
|
|
64
|
-
make.top.equalTo(view.super);
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
this.scroll = new Scroll({
|
|
69
|
-
props: {
|
|
70
|
-
alwaysBounceVertical: false,
|
|
71
|
-
alwaysBounceHorizontal: true,
|
|
72
|
-
showsHorizontalIndicator: false,
|
|
73
|
-
pagingEnabled: true,
|
|
74
|
-
},
|
|
75
|
-
events: {
|
|
76
|
-
layoutSubviews: (sender) => {
|
|
77
|
-
this._pageWidth = sender.frame.width;
|
|
78
|
-
if (this._pageWidth) sender.contentSize = $size(this._pageWidth * this._props.cviews.length, 0);
|
|
79
|
-
},
|
|
80
|
-
willEndDragging: (sender, velocity, target) => {
|
|
81
|
-
const oldPage = this.page;
|
|
82
|
-
this._props.page = Math.round(target.x / this._pageWidth);
|
|
83
|
-
if (oldPage !== this.page && this._events.changed) this._events.changed(this, this.page);
|
|
84
|
-
},
|
|
85
|
-
didScroll: (sender) => {
|
|
86
|
-
const rawPage = sender.contentOffset.x / this._pageWidth;
|
|
87
|
-
this._floatPage = Math.min(Math.max(0, rawPage), this._props.cviews.length - 1);
|
|
88
|
-
if (this._events.floatPageChanged) this._events.floatPageChanged(this, this._floatPage);
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
layout: $layout.fill,
|
|
92
|
-
views: [...contentViews.map((n) => n.definition)],
|
|
93
|
-
});
|
|
94
|
-
this._defineView = () => {
|
|
95
|
-
return {
|
|
96
|
-
type: "view",
|
|
97
|
-
props: { id: this.id },
|
|
98
|
-
layout,
|
|
99
|
-
views: [this.scroll.definition],
|
|
100
|
-
events: {
|
|
101
|
-
layoutSubviews: (sender) => {
|
|
102
|
-
sender.relayout();
|
|
103
|
-
this.page = this.page;
|
|
104
|
-
$delay(0.2, () => (this.page = this.page));
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get page() {
|
|
112
|
-
return this._props.page;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
set page(page) {
|
|
116
|
-
this._props.page = page;
|
|
117
|
-
if (this.scroll.view.contentOffset.x !== page * this._pageWidth)
|
|
118
|
-
this.scroll.view.contentOffset = $point(page * this._pageWidth, 0);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
scrollToPage(page: number) {
|
|
122
|
-
this.scroll.view.scrollToOffset($point(page * this._pageWidth, 0));
|
|
123
|
-
this._props.page = page;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Base } from "./base";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 创建一个刷新按钮,平时显示一个刷新的symbol,刷新时显示一个loading的symbol
|
|
5
|
-
* props:
|
|
6
|
-
* - tintColor
|
|
7
|
-
* - enabled
|
|
8
|
-
* - hidden
|
|
9
|
-
* events:
|
|
10
|
-
* - tapped
|
|
11
|
-
*/
|
|
12
|
-
export class RefreshButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
|
|
13
|
-
_defineView: () => UiTypes.ButtonOptions;
|
|
14
|
-
_loading: boolean = false;
|
|
15
|
-
constructor({
|
|
16
|
-
props,
|
|
17
|
-
layout,
|
|
18
|
-
events = {},
|
|
19
|
-
}: {
|
|
20
|
-
props?: {
|
|
21
|
-
tintColor?: UIColor;
|
|
22
|
-
enabled?: boolean;
|
|
23
|
-
hidden?: boolean;
|
|
24
|
-
};
|
|
25
|
-
layout?: (make: MASConstraintMaker, view: UIButtonView) => void;
|
|
26
|
-
events?: UiTypes.BaseViewEvents<UIButtonView>;
|
|
27
|
-
}) {
|
|
28
|
-
super();
|
|
29
|
-
this._layout = layout;
|
|
30
|
-
this._defineView = () => {
|
|
31
|
-
return {
|
|
32
|
-
type: "button",
|
|
33
|
-
props: {
|
|
34
|
-
id: this.id,
|
|
35
|
-
bgcolor: $color("clear"),
|
|
36
|
-
enabled: props?.enabled ?? true,
|
|
37
|
-
hidden: props?.hidden ?? false,
|
|
38
|
-
},
|
|
39
|
-
layout: this._layout,
|
|
40
|
-
events,
|
|
41
|
-
views: [
|
|
42
|
-
{
|
|
43
|
-
type: "image",
|
|
44
|
-
props: {
|
|
45
|
-
id: this.id + "_image",
|
|
46
|
-
symbol: "arrow.clockwise",
|
|
47
|
-
tintColor: props?.tintColor ?? $color("primaryText"),
|
|
48
|
-
contentMode: 1,
|
|
49
|
-
hidden: this._loading,
|
|
50
|
-
},
|
|
51
|
-
layout: (make, view) => {
|
|
52
|
-
make.edges.insets($insets(12.5, 12.5, 12.5, 12.5));
|
|
53
|
-
make.center.equalTo(view.super);
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: "spinner",
|
|
58
|
-
props: {
|
|
59
|
-
id: this.id + "_spinner",
|
|
60
|
-
loading: this._loading,
|
|
61
|
-
hidden: !this._loading,
|
|
62
|
-
},
|
|
63
|
-
layout: (make, view) => {
|
|
64
|
-
make.center.equalTo(view.super);
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get loading() {
|
|
73
|
-
return this._loading;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
set loading(value: boolean) {
|
|
77
|
-
this._loading = value;
|
|
78
|
-
$(this.id + "_image").hidden = value;
|
|
79
|
-
$(this.id + "_spinner").hidden = !value;
|
|
80
|
-
($(this.id + "_spinner") as UISpinnerView).loading = value;
|
|
81
|
-
this.view.enabled = !value;
|
|
82
|
-
}
|
|
83
|
-
}
|