<commit_before>﻿import {
    SwitchBase, layout, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, checkedProperty
} from "./switch-common";

export * from "./switch-common";

class SwitchChangeHandlerImpl extends NSObject {

    private _owner: WeakRef<Switch>;

    public static initWithOwner(owner: WeakRef<Switch>): SwitchChangeHandlerImpl {
        let handler = <SwitchChangeHandlerImpl>SwitchChangeHandlerImpl.new();
        handler._owner = owner;
        return handler;
    }

    public valueChanged(sender: UISwitch) {
        let owner = this._owner.get();
        if (owner) {
            checkedProperty.nativeValueChange(owner, sender.on);
        }
    }

    public static ObjCExposedMethods = {
        'valueChanged': { returns: interop.types.void, params: [UISwitch] }
    };
}

const zeroSize = { width: 0, height: 0 };
export class Switch extends SwitchBase {
    nativeView: UISwitch;
    private _handler: NSObject;

    constructor() {
        super();
        const nativeView = UISwitch.new();
        this._handler = SwitchChangeHandlerImpl.initWithOwner(new WeakRef(this));
        nativeView.addTargetActionForControlEvents(this._handler, "valueChanged", UIControlEvents.ValueChanged);
        this.nativeView = nativeView;
    }

    get ios(): UISwitch {
        return this.nativeView;
    }
<commit_msg>switch in iOS cannot have different size than 51/31. Setting it in onMeasure is late. (#4212)<commit_after>﻿import {
    SwitchBase, layout, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, checkedProperty
} from "./switch-common";

export * from "./switch-common";

class SwitchChangeHandlerImpl extends NSObject {

    private _owner: WeakRef<Switch>;

    public static initWithOwner(owner: WeakRef<Switch>): SwitchChangeHandlerImpl {
        let handler = <SwitchChangeHandlerImpl>SwitchChangeHandlerImpl.new();
        handler._owner = owner;
        return handler;
    }

    public valueChanged(sender: UISwitch) {
        let owner = this._owner.get();
        if (owner) {
            checkedProperty.nativeValueChange(owner, sender.on);
        }
    }

    public static ObjCExposedMethods = {
        'valueChanged': { returns: interop.types.void, params: [UISwitch] }
    };
}

const zeroSize = { width: 0, height: 0 };
export class Switch extends SwitchBase {
    nativeView: UISwitch;
    private _handler: NSObject;

    constructor() {
        super();
        const nativeView = UISwitch.new();
        this._handler = SwitchChangeHandlerImpl.initWithOwner(new WeakRef(this));
        nativeView.addTargetActionForControlEvents(this._handler, "valueChanged", UIControlEvents.ValueChanged);
        this.nativeView = nativeView;
        this.width = 51;
        this.height = 31;
    }

    get ios(): UISwitch {
        return this.nativeView;
    }

{'fraction_non_alphanumeric': 0.10143406785589366, 'fraction_numerical': 0.005596362364463099, 'mean_word_length': 3.224519940915805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6332379', 'n_tokens_mistral': 814, 'n_tokens_neox': 780, 'n_words': 188}