chore: default tabs

This commit is contained in:
Nathan Walker
2020-07-09 23:46:02 -07:00
parent 8100cf7089
commit 41f0573d8e
353 changed files with 55344 additions and 55344 deletions

View File

@@ -5,114 +5,114 @@ import { Color } from '../../color';
export * from './switch-common';
interface CheckedChangeListener {
new (owner: Switch): android.widget.CompoundButton.OnCheckedChangeListener;
new (owner: Switch): android.widget.CompoundButton.OnCheckedChangeListener;
}
let CheckedChangeListener: CheckedChangeListener;
function initializeCheckedChangeListener(): void {
if (CheckedChangeListener) {
return;
}
if (CheckedChangeListener) {
return;
}
@Interfaces([android.widget.CompoundButton.OnCheckedChangeListener])
class CheckedChangeListenerImpl extends java.lang.Object implements android.widget.CompoundButton.OnCheckedChangeListener {
constructor(private owner: Switch) {
super();
@Interfaces([android.widget.CompoundButton.OnCheckedChangeListener])
class CheckedChangeListenerImpl extends java.lang.Object implements android.widget.CompoundButton.OnCheckedChangeListener {
constructor(private owner: Switch) {
super();
return global.__native(this);
}
return global.__native(this);
}
onCheckedChanged(buttonView: android.widget.CompoundButton, isChecked: boolean): void {
const owner = this.owner;
checkedProperty.nativeValueChange(owner, isChecked);
}
}
onCheckedChanged(buttonView: android.widget.CompoundButton, isChecked: boolean): void {
const owner = this.owner;
checkedProperty.nativeValueChange(owner, isChecked);
}
}
CheckedChangeListener = CheckedChangeListenerImpl;
CheckedChangeListener = CheckedChangeListenerImpl;
}
export class Switch extends SwitchBase {
nativeViewProtected: android.widget.Switch;
public checked: boolean;
nativeViewProtected: android.widget.Switch;
public checked: boolean;
public createNativeView() {
return new android.widget.Switch(this._context);
}
public createNativeView() {
return new android.widget.Switch(this._context);
}
public initNativeView(): void {
super.initNativeView();
const nativeView = this.nativeViewProtected;
initializeCheckedChangeListener();
const listener = new CheckedChangeListener(this);
nativeView.setOnCheckedChangeListener(listener);
(<any>nativeView).listener = listener;
}
public initNativeView(): void {
super.initNativeView();
const nativeView = this.nativeViewProtected;
initializeCheckedChangeListener();
const listener = new CheckedChangeListener(this);
nativeView.setOnCheckedChangeListener(listener);
(<any>nativeView).listener = listener;
}
public disposeNativeView() {
const nativeView: any = this.nativeViewProtected;
nativeView.listener.owner = null;
super.disposeNativeView();
}
public disposeNativeView() {
const nativeView: any = this.nativeViewProtected;
nativeView.listener.owner = null;
super.disposeNativeView();
}
private setNativeBackgroundColor(value: string | number | Color) {
if (value instanceof Color) {
this.nativeViewProtected.getTrackDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
} else {
this.nativeViewProtected.getTrackDrawable().clearColorFilter();
}
}
private setNativeBackgroundColor(value: string | number | Color) {
if (value instanceof Color) {
this.nativeViewProtected.getTrackDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
} else {
this.nativeViewProtected.getTrackDrawable().clearColorFilter();
}
}
_onCheckedPropertyChanged(newValue: boolean) {
if (this.offBackgroundColor) {
if (!newValue) {
this.setNativeBackgroundColor(this.offBackgroundColor);
} else {
this.setNativeBackgroundColor(this.backgroundColor);
}
}
}
_onCheckedPropertyChanged(newValue: boolean) {
if (this.offBackgroundColor) {
if (!newValue) {
this.setNativeBackgroundColor(this.offBackgroundColor);
} else {
this.setNativeBackgroundColor(this.backgroundColor);
}
}
}
[checkedProperty.getDefault](): boolean {
return false;
}
[checkedProperty.setNative](value: boolean) {
this.nativeViewProtected.setChecked(value);
}
[checkedProperty.getDefault](): boolean {
return false;
}
[checkedProperty.setNative](value: boolean) {
this.nativeViewProtected.setChecked(value);
}
[colorProperty.getDefault](): number {
return -1;
}
[colorProperty.setNative](value: number | Color) {
if (value instanceof Color) {
this.nativeViewProtected.getThumbDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
} else {
this.nativeViewProtected.getThumbDrawable().clearColorFilter();
}
}
[colorProperty.getDefault](): number {
return -1;
}
[colorProperty.setNative](value: number | Color) {
if (value instanceof Color) {
this.nativeViewProtected.getThumbDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
} else {
this.nativeViewProtected.getThumbDrawable().clearColorFilter();
}
}
[backgroundColorProperty.getDefault](): number {
return -1;
}
[backgroundColorProperty.setNative](value: number | Color) {
if (!this.offBackgroundColor || this.checked) {
this.setNativeBackgroundColor(value);
}
}
[backgroundColorProperty.getDefault](): number {
return -1;
}
[backgroundColorProperty.setNative](value: number | Color) {
if (!this.offBackgroundColor || this.checked) {
this.setNativeBackgroundColor(value);
}
}
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
//
}
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
//
}
[offBackgroundColorProperty.getDefault](): number {
return -1;
}
[offBackgroundColorProperty.setNative](value: number | Color) {
if (!this.checked) {
this.setNativeBackgroundColor(value);
}
}
[offBackgroundColorProperty.getDefault](): number {
return -1;
}
[offBackgroundColorProperty.setNative](value: number | Color) {
if (!this.checked) {
this.setNativeBackgroundColor(value);
}
}
}

View File

@@ -6,27 +6,27 @@ import { Color } from '../../color';
* Represents a switch component.
*/
export class Switch extends View {
public static checkedChangeEvent: string;
public static checkedChangeEvent: string;
/**
* Gets the native [android widget](http://developer.android.com/reference/android/widget/Switch.html) that represents the user interface for this component. Valid only when running on Android OS.
*/
android: any /* android.widget.Switch */;
/**
* Gets the native [android widget](http://developer.android.com/reference/android/widget/Switch.html) that represents the user interface for this component. Valid only when running on Android OS.
*/
android: any /* android.widget.Switch */;
/**
* Gets the native iOS [UISwitch](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISwitch_Class/) that represents the user interface for this component. Valid only when running on iOS.
*/
ios: any /* UISwitch */;
/**
* Gets the native iOS [UISwitch](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISwitch_Class/) that represents the user interface for this component. Valid only when running on iOS.
*/
ios: any /* UISwitch */;
/**
* Gets or sets if a switch is checked or not.
*/
checked: boolean;
/**
* Gets or sets if a switch is checked or not.
*/
checked: boolean;
/**
* Gets or sets the background color of the Switch when it is turned off.
*/
offBackgroundColor: Color;
/**
* Gets or sets the background color of the Switch when it is turned off.
*/
offBackgroundColor: Color;
}
/**

View File

@@ -6,105 +6,105 @@ import { layout } from '../../utils';
export * from './switch-common';
class SwitchChangeHandlerImpl extends NSObject {
private _owner: WeakRef<Switch>;
private _owner: WeakRef<Switch>;
public static initWithOwner(owner: WeakRef<Switch>): SwitchChangeHandlerImpl {
let handler = <SwitchChangeHandlerImpl>SwitchChangeHandlerImpl.new();
handler._owner = owner;
public static initWithOwner(owner: WeakRef<Switch>): SwitchChangeHandlerImpl {
let handler = <SwitchChangeHandlerImpl>SwitchChangeHandlerImpl.new();
handler._owner = owner;
return handler;
}
return handler;
}
public valueChanged(sender: UISwitch) {
let owner = this._owner.get();
if (owner) {
checkedProperty.nativeValueChange(owner, sender.on);
}
}
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] },
};
public static ObjCExposedMethods = {
valueChanged: { returns: interop.types.void, params: [UISwitch] },
};
}
const zeroSize = { width: 0, height: 0 };
export class Switch extends SwitchBase {
nativeViewProtected: UISwitch;
private _handler: NSObject;
nativeViewProtected: UISwitch;
private _handler: NSObject;
constructor() {
super();
this.width = 51;
this.height = 31;
}
constructor() {
super();
this.width = 51;
this.height = 31;
}
public createNativeView() {
return UISwitch.new();
}
public createNativeView() {
return UISwitch.new();
}
public initNativeView(): void {
super.initNativeView();
const nativeView = this.nativeViewProtected;
this._handler = SwitchChangeHandlerImpl.initWithOwner(new WeakRef(this));
nativeView.addTargetActionForControlEvents(this._handler, 'valueChanged', UIControlEvents.ValueChanged);
}
public initNativeView(): void {
super.initNativeView();
const nativeView = this.nativeViewProtected;
this._handler = SwitchChangeHandlerImpl.initWithOwner(new WeakRef(this));
nativeView.addTargetActionForControlEvents(this._handler, 'valueChanged', UIControlEvents.ValueChanged);
}
public disposeNativeView() {
this._handler = null;
super.disposeNativeView();
}
public disposeNativeView() {
this._handler = null;
super.disposeNativeView();
}
get ios(): UISwitch {
return this.nativeViewProtected;
}
get ios(): UISwitch {
return this.nativeViewProtected;
}
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
// It can't be anything different from 51x31
let nativeSize = this.nativeViewProtected.sizeThatFits(zeroSize);
this.width = nativeSize.width;
this.height = nativeSize.height;
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
// It can't be anything different from 51x31
let nativeSize = this.nativeViewProtected.sizeThatFits(zeroSize);
this.width = nativeSize.width;
this.height = nativeSize.height;
const widthAndState = Switch.resolveSizeAndState(layout.toDevicePixels(nativeSize.width), layout.toDevicePixels(51), layout.EXACTLY, 0);
const heightAndState = Switch.resolveSizeAndState(layout.toDevicePixels(nativeSize.height), layout.toDevicePixels(31), layout.EXACTLY, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}
const widthAndState = Switch.resolveSizeAndState(layout.toDevicePixels(nativeSize.width), layout.toDevicePixels(51), layout.EXACTLY, 0);
const heightAndState = Switch.resolveSizeAndState(layout.toDevicePixels(nativeSize.height), layout.toDevicePixels(31), layout.EXACTLY, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}
[checkedProperty.getDefault](): boolean {
return false;
}
[checkedProperty.setNative](value: boolean) {
this.nativeViewProtected.on = value;
}
[checkedProperty.getDefault](): boolean {
return false;
}
[checkedProperty.setNative](value: boolean) {
this.nativeViewProtected.on = value;
}
[colorProperty.getDefault](): UIColor {
return this.nativeViewProtected.thumbTintColor;
}
[colorProperty.setNative](value: UIColor | Color) {
this.nativeViewProtected.thumbTintColor = value instanceof Color ? value.ios : value;
}
[colorProperty.getDefault](): UIColor {
return this.nativeViewProtected.thumbTintColor;
}
[colorProperty.setNative](value: UIColor | Color) {
this.nativeViewProtected.thumbTintColor = value instanceof Color ? value.ios : value;
}
[backgroundColorProperty.getDefault](): UIColor {
return this.nativeViewProtected.onTintColor;
}
[backgroundColorProperty.setNative](value: UIColor | Color) {
this.nativeViewProtected.onTintColor = value instanceof Color ? value.ios : value;
}
[backgroundColorProperty.getDefault](): UIColor {
return this.nativeViewProtected.onTintColor;
}
[backgroundColorProperty.setNative](value: UIColor | Color) {
this.nativeViewProtected.onTintColor = value instanceof Color ? value.ios : value;
}
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
//
}
[backgroundInternalProperty.getDefault](): any {
return null;
}
[backgroundInternalProperty.setNative](value: any) {
//
}
[offBackgroundColorProperty.getDefault](): UIColor {
return this.nativeViewProtected.backgroundColor;
}
[offBackgroundColorProperty.setNative](value: Color | UIColor) {
const nativeValue = value instanceof Color ? value.ios : value;
[offBackgroundColorProperty.getDefault](): UIColor {
return this.nativeViewProtected.backgroundColor;
}
[offBackgroundColorProperty.setNative](value: Color | UIColor) {
const nativeValue = value instanceof Color ? value.ios : value;
this.nativeViewProtected.tintColor = nativeValue;
this.nativeViewProtected.backgroundColor = nativeValue;
this.nativeViewProtected.layer.cornerRadius = this.nativeViewProtected.frame.size.height / 2;
}
this.nativeViewProtected.tintColor = nativeValue;
this.nativeViewProtected.backgroundColor = nativeValue;
this.nativeViewProtected.layer.cornerRadius = this.nativeViewProtected.frame.size.height / 2;
}
}

View File

@@ -6,33 +6,33 @@ import { Switch as SwitchDefinition } from '.';
@CSSType('Switch')
export class SwitchBase extends View implements SwitchDefinition {
public static checkedChangeEvent = 'checkedChange';
public static checkedChangeEvent = 'checkedChange';
public checked: boolean;
public offBackgroundColor: Color;
public checked: boolean;
public offBackgroundColor: Color;
_onCheckedPropertyChanged(newValue: boolean) {
//
}
_onCheckedPropertyChanged(newValue: boolean) {
//
}
}
SwitchBase.prototype.recycleNativeView = 'auto';
function onCheckedPropertyChanged(switchBase: SwitchBase, oldValue: boolean, newValue: boolean) {
switchBase._onCheckedPropertyChanged(newValue);
switchBase._onCheckedPropertyChanged(newValue);
}
export const checkedProperty = new Property<SwitchBase, boolean>({
name: 'checked',
defaultValue: false,
valueConverter: booleanConverter,
valueChanged: onCheckedPropertyChanged,
name: 'checked',
defaultValue: false,
valueConverter: booleanConverter,
valueChanged: onCheckedPropertyChanged,
});
checkedProperty.register(SwitchBase);
export const offBackgroundColorProperty = new Property<SwitchBase, Color>({
name: 'offBackgroundColor',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
name: 'offBackgroundColor',
equalityComparer: Color.equals,
valueConverter: (v) => new Color(v),
});
offBackgroundColorProperty.register(SwitchBase);