mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
iOS owner pattern changed to use WeakRef in order to prevent memory leaks.
Optimized list-view-tests. Added time per test.
This commit is contained in:
@@ -86,7 +86,7 @@ export class SegmentedBar extends common.SegmentedBar {
|
||||
super();
|
||||
this._ios = UISegmentedControl.new();
|
||||
|
||||
this._selectionHandler = SelectionHandlerImpl.new().initWithOwner(this);
|
||||
this._selectionHandler = SelectionHandlerImpl.initWithOwner(new WeakRef(this));
|
||||
this._ios.addTargetActionForControlEvents(this._selectionHandler, "selected", UIControlEvents.UIControlEventValueChanged);
|
||||
}
|
||||
|
||||
@@ -96,22 +96,23 @@ export class SegmentedBar extends common.SegmentedBar {
|
||||
}
|
||||
|
||||
class SelectionHandlerImpl extends NSObject {
|
||||
static new(): SelectionHandlerImpl {
|
||||
return <SelectionHandlerImpl>super.new();
|
||||
}
|
||||
|
||||
private _owner: SegmentedBar;
|
||||
private _owner: WeakRef<SegmentedBar>;
|
||||
|
||||
public initWithOwner(owner: SegmentedBar): SelectionHandlerImpl {
|
||||
this._owner = owner;
|
||||
return this;
|
||||
public static initWithOwner(owner: WeakRef<SegmentedBar>): SelectionHandlerImpl {
|
||||
let handler = <SelectionHandlerImpl>SelectionHandlerImpl.new();
|
||||
handler._owner = owner;
|
||||
return handler;
|
||||
}
|
||||
|
||||
public selected(sender: UISegmentedControl) {
|
||||
this._owner.selectedIndex = sender.selectedSegmentIndex;
|
||||
let owner = this._owner.get();
|
||||
if (owner) {
|
||||
owner.selectedIndex = sender.selectedSegmentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public static ObjCExposedMethods = {
|
||||
"selected": { returns: interop.types.void, params: [UISegmentedControl] }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user