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:
@@ -13,19 +13,20 @@ function onCheckedPropertyChanged(data: dependencyObservable.PropertyChangeData)
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
class SwitchChangeHandlerImpl extends NSObject {
|
||||
static new(): SwitchChangeHandlerImpl {
|
||||
return <SwitchChangeHandlerImpl>super.new();
|
||||
}
|
||||
|
||||
private _owner: Switch;
|
||||
private _owner: WeakRef<Switch>;
|
||||
|
||||
public initWithOwner(owner: Switch): SwitchChangeHandlerImpl {
|
||||
this._owner = owner;
|
||||
return this;
|
||||
public static initWithOwner(owner: WeakRef<Switch>): SwitchChangeHandlerImpl {
|
||||
let handler = <SwitchChangeHandlerImpl>SwitchChangeHandlerImpl.new();
|
||||
handler._owner = owner;
|
||||
return handler;
|
||||
}
|
||||
|
||||
public valueChanged(sender: UISwitch) {
|
||||
this._owner._onPropertyChangedFromNative(common.Switch.checkedProperty, sender.on);
|
||||
let owner = this._owner.get();
|
||||
if (owner) {
|
||||
owner._onPropertyChangedFromNative(common.Switch.checkedProperty, sender.on);
|
||||
}
|
||||
}
|
||||
|
||||
public static ObjCExposedMethods = {
|
||||
@@ -41,7 +42,7 @@ export class Switch extends common.Switch {
|
||||
super();
|
||||
this._ios = new UISwitch();
|
||||
|
||||
this._handler = SwitchChangeHandlerImpl.new().initWithOwner(this);
|
||||
this._handler = SwitchChangeHandlerImpl.initWithOwner(new WeakRef(this));
|
||||
this._ios.addTargetActionForControlEvents(this._handler, "valueChanged", UIControlEvents.UIControlEventValueChanged);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user