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

@@ -2,19 +2,19 @@
import stateChanged = require("ui/core/control-state-change");
class TapHandlerImpl extends NSObject {
static new(): TapHandlerImpl {
return <TapHandlerImpl>super.new();
}
private _owner: WeakRef<Button>;
private _owner: Button;
public initWithOwner(owner: Button): TapHandlerImpl {
this._owner = owner;
return this;
public static initWithOwner(owner: WeakRef<Button>): TapHandlerImpl {
let handler = <TapHandlerImpl>TapHandlerImpl.new();
handler._owner = owner;
return handler;
}
public tap(args) {
this._owner._emit(common.Button.tapEvent);
let owner = this._owner.get();
if (owner) {
owner._emit(common.Button.tapEvent);
}
}
public static ObjCExposedMethods = {
@@ -33,7 +33,7 @@ export class Button extends common.Button {
super();
this._ios = UIButton.buttonWithType(UIButtonType.UIButtonTypeSystem);
this._tapHandler = TapHandlerImpl.new().initWithOwner(this);
this._tapHandler = TapHandlerImpl.initWithOwner(new WeakRef(this));
this._ios.addTargetActionForControlEvents(this._tapHandler, "tap", UIControlEvents.UIControlEventTouchUpInside);
this._stateChangedHandler = new stateChanged.ControlStateChangeListener(this._ios, (s: string) => {