Я пытаюсь создать делегат события прокрутки для ListView на iOS, основываясь на следующем примере кода: https://github.com/NativeScript/NativeScript/issues/2521#issuecomment-306447460
(реализация Android работает как чемпион. IOS рушится эпическим способом)
При выполнении функции new
выдается фатальная ошибка.
Делегирование
class ScrollingUITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
private _originalDelegate: UITableViewDelegate;
static ObjCProtocols = [UITableViewDelegate];
static new():ScrollingUITableViewDelegateImpl {
return <ScrollingUITableViewDelegateImpl>super.new();
}
static initWithOrigDelegate(original: UITableViewDelegate): ScrollingUITableViewDelegateImpl {
const delegate = <ScrollingUITableViewDelegateImpl>ScrollingUITableViewDelegateImpl.new();
delegate._originalDelegate = original;
return delegate;
}
/* OriginalDelegate items */
public tableViewWillDisplayCellForRowAtIndexPath(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath) {
return this._originalDelegate.tableViewWillDisplayCellForRowAtIndexPath(tableView, cell, indexPath)
}
public tableViewWillSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath {
return this._originalDelegate.tableViewWillSelectRowAtIndexPath(tableView, indexPath);
}
public tableViewDidSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath {
tableView.deselectRowAtIndexPathAnimated(indexPath, true);
return indexPath;
}
public tableViewHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number {
return this._originalDelegate.tableViewHeightForRowAtIndexPath(tableView, indexPath);
}
/* Scroll Delegate items */
public scrollViewWillBeginDragging(scrollView:UIScrollView) {
console.log('willbegindragging');
}
public scrollViewDidScroll(scrollView:UIScrollView) {
console.log('didscroll');
}
}
Error
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1 0x100aa373c
NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool, bool)
2 0x100ac92e4 NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
3 0x1013cb088 ffi_closure_SYSV_inner
4 0x1013cc1b4 .Ldo_closure
5 0x1b211ea60 <redacted>
6 0x1b211f144 <redacted>
7 0x1b20860e8 <redacted>
8 0x1b2086da8 <redacted>
9 0x1b20880a8 <redacted>
10 0x1b206a298 <redacted>
11 0x1b2b7ff44 <redacted>
12 0x18a13da34 <redacted>
13 0x18a1429c4 <redacted>
14 0x18a0a19d4 <redacted>
15 0x18a0d02f4 <redacted>
16 0x1b26f736c <redacted>
17 0x185aea408 <redacted>
18 0x185ae9d08 <redacted>
19 0x185ae4cfc <redacted>
20 0x185ae45b8 CFRunLoopRunSpecific
21 0x187d58584 GSEventRunModal
22 0x1b26dcbc8 UIApplicationMain
23 0x1013cc044 ffi_call_SYSV
24 0x1013ca7a4 ffi_call_int
25 0x1013ca26c ffi_call
26 0x100a81630 NativeScript::FFICall::call(JSC::ExecState*)
27 0x10107ce14 JSC::LLInt::setUpCall(JSC::ExecState*, JSC::Instruction*, JSC::CodeSpecializationKind, JSC::JSValue, JSC::LLIntCallLinkInfo*)
28 0x101085a24 llint_entry
29 0x101085a34 llint_entry
30 0x101085a34 llint_entry
31 0x10107eee0 vmEntryToJavaScript
JavaScript stack trace:
1 new@file:///app/components/scroll-list-view/scroll-list-view.js:10:25
2 new@file:///app/components/scroll-list-view/scroll-list-view.js:10:25
3 initWithOrigDelegate@file:///app/components/scroll-list-view/scroll-list-view.js:13:59
4 initNativeView@file:///app/components/scroll-list-view/scroll-list-view.js:46:76
5 setNativeView@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:548:32
6 _setupUI@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:527:27
7 @file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:534:27
8 eachChildView@file:///app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js:125:34
9 eachChild@file:///app/tns_modules/tns-core-modules/ui/core/view/view-common.js:868:27
10 _setupUI@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:533:23
11 @file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:534:27
12 eachChildView@file:///app/tns_modules/tns-core-mo<\M-b\M^@\M-&>
JavaScript error:
file:///app/components/scroll-list-view/scroll-list-view.js:10:25: JS ERROR Error: This value is not a native object.
*** JavaScript call stack:
(
0 UIApplicationMain@[native code]
1 start@file:///app/tns_modules/tns-core-modules/application/application.js:272:26
2 run@file:///app/tns_modules/tns-core-modules/application/application.js:300:10
3 anonymous@file:///app/app.js:20:16
4 evaluate@[native code]
5 moduleEvaluation@:1:11
6 @:7:48
7 promiseReactionJob@:1:11
)
*** Terminating app due to uncaught exception****
'NativeScript encountered a fatal error: Error: This value is not a native object.
at
1 new@file:///app/components/scroll-list-view/scroll-list-view.js:10:25
2 new@file:///app/components/scroll-list-view/scroll-list-view.js:10:25
3 initWithOrigDelegate@file:///app/components/scroll-list-view/scroll-list-view.js:13:59
4 initNativeView@file:///app/components/scroll-list-view/scroll-list-view.js:46:76
5 setNativeView@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:548:32
6 _setupUI@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:527:27
7 @file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:534:27
8 eachChildView@file:///app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js:125:34
9 eachChild@file:///app/tns_modules/tns-core-modules/ui/core/view/view-common.js:868:27
10 _setupUI@file:///app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:533:23
11 <\M-b\M^@\M-&>
UPDATE
Новый код
var ScrollingUITableViewDelegateImpl = (NSObject as any).extend({
_originalDelegate: null,
/* OriginalDelegate items */
tableViewWillDisplayCellForRowAtIndexPath(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath) {
if (this._originalDelegate)
return this._originalDelegate.tableViewWillDisplayCellForRowAtIndexPath(tableView, cell, indexPath)
return null;
},
tableViewWillSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath {
if (this._originalDelegate)
return this._originalDelegate.tableViewWillSelectRowAtIndexPath(tableView, indexPath);
return null;
},
tableViewDidSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath {
tableView.deselectRowAtIndexPathAnimated(indexPath, true);
return indexPath;
},
tableViewHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number {
if (this._originalDelegate)
return this._originalDelegate.tableViewHeightForRowAtIndexPath(tableView, indexPath);
return null;
},
/* Scroll Delegate items */
scrollViewWillBeginDragging(scrollView:ScrollListView) {
if (this._originalDelegate) {
const owner:ListView = (this._originalDelegate['_owner'] as WeakRef<ListView>).get();
owner.notify({eventName: ScrollListViewBase.ScrollEvent, object: owner});
}
else { console.log('no delegate'); }
},
scrollViewDidScroll(scrollView:ScrollListView) {
if (this._originalDelegate) {
const owner:ListView = (this._originalDelegate['_owner'] as WeakRef<ListView>).get();
owner.notify({eventName: ScrollListViewBase.ScrollStateChangedEvent, object: owner});
}
else { console.log('no delegate'); }
}
}, {
name: 'ScrollingUITableViewDelegateImpl',
protocols: [UITableViewDelegate],
});
Обновленный код запускается, но я сталкиваюсь с новой ошибкой:
JavaScript error:
file:///app/tns_modules/tns-core-modules/ui/core/view/view-common.js:794:21: JS ERROR TypeError: child.layout is not a function. (In 'child.layout(childLeft, childTop, childRight, childBottom, setFram(
0 UIApplicationMain@[native code]
1 start@file:///app/tns_modules/tns-core-modules/application/application.js:272:26
2 run@file:///app/tns_modules/tns-core-modules/application/application.js:300:10
3 anonymous@file:///app/app.js:20:16
4 evaluate@[native code]
5 moduleEvaluation@:1:11
6 @:7:48
7 promiseReactionJob@:1:11
)