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:
hshristov
2015-10-22 10:26:59 +03:00
parent 9c0ac9e471
commit f72d79e65a
22 changed files with 863 additions and 791 deletions

View File

@@ -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] }
};
}
}