diff --git a/apps/toolbox/src/app.css b/apps/toolbox/src/app.css index 47446618d..cec187db5 100644 --- a/apps/toolbox/src/app.css +++ b/apps/toolbox/src/app.css @@ -5,17 +5,79 @@ The following CSS rule changes the font size of all UI components that have the btn class name. */ -.btn { +.btn-view-demo { font-size: 18; - /* box-shadow: -5 -5 10 10 navy; */ - box-shadow: -5 -5 rgba(0,0,0,0.5); - background-color: #add8e6; - color: navy; - /* TODO: adding border radius breaks shadow */ - /* border-radius: 10; */ + background-color: #65ADF1; + border-radius: 5; + font-size: 17; + padding: 15; + font-weight: bold; } .bold{ + font-weight: bold; +} + +.controls Label { + font-size: 20; + font-weight: bold; + color: #333; + margin-top: 10; +} + +.controls Button { + padding: 10 15; + margin: 5; + font-size: 17; + font-weight: bold; + color: #65ADF1; + border-radius: 5; + border-width: 1; + border-color: #65ADF1; +} + +.box-shadow-demo .demo-component { + font-size: 20; + font-weight: bold; + color: #555; + border-color: #555; + margin: 10; + padding: 20 25; + text-transform: uppercase; +} + +.box-shadow-demo .box-shadow-prop-controls { + padding: 10; + color: #333; + font-size: 17; +} + +.box-shadow-demo .box-shadow-prop-controls TextField{ + margin-left: 10; + padding: 5; + border-bottom-width: 1; + border-color: #65ADF1; +} + +.box-shadow-demo .controls .description { + font-size: 15; + font-weight: normal; + color: #333; + margin-bottom: 10; +} + +.box-shadow-demo .controls Button[selectedAttr=true] { + background-color: #65ADF1; + color: #fff; +} + +.box-shadow-prop-controls .btn-apply { + background-color: #65ADF1; + color: #fff; + padding: 10 15; + border-radius: 4; + margin-left: 10; + font-size: 17; font-weight: bold; } diff --git a/apps/toolbox/src/box-shadow.ts b/apps/toolbox/src/box-shadow.ts new file mode 100644 index 000000000..c45824314 --- /dev/null +++ b/apps/toolbox/src/box-shadow.ts @@ -0,0 +1,177 @@ +import { Observable } from '@nativescript/core'; +import { EventData, Page } from '@nativescript/core'; + +export function navigatingTo(args: EventData) { + const page = args.object; + page.bindingContext = new BoxShadowModel(); +} + +export class BoxShadowModel extends Observable { + private _selectedComponentType: string; + private _selectedBackgroundType: string; + private _selectedBorderType: string; + private _selectedAnimation: string; + private _boxShadow: string; + + background: string; + borderWidth: number; + borderRadius: number; + appliedBoxShadow: string; + + constructor() { + super(); + } + + get selectedComponentType(): string { + return this._selectedComponentType; + } + + set selectedComponentType(value: string) { + if (this._selectedComponentType !== value) { + this._selectedComponentType = value; + this.notifyPropertyChange('selectedComponentType', value); + } + } + + get selectedBackgroundType(): string { + return this._selectedBackgroundType; + } + + set selectedBackgroundType(value: string) { + if (this._selectedBackgroundType !== value) { + this._selectedBackgroundType = value; + this.notifyPropertyChange('selectedBackgroundType', value); + switch (value) { + case 'solid': + this.background = '#65ADF1'; + break; + case 'gradient': + this.background = 'linear-gradient(to top, #65ADF1, white)'; + break; + case 'transparent': + this.background = 'transparent'; + break; + default: + break; + } + this.notifyPropertyChange('background', this.background); + } + } + + get selectedBorderType(): string { + return this._selectedBorderType; + } + + set selectedBorderType(value: string) { + this._selectedBorderType = value; + this.notifyPropertyChange('selectedBorderType', value); + switch (value) { + case 'solid': + this.borderWidth = this.borderWidth ? 0 : 2; + break; + case 'rounded': + this.borderRadius = this.borderRadius ? 0 : 10; + break; + case 'none': + this.borderRadius = 0; + this.borderWidth = 0; + break; + default: + break; + } + this.notifyPropertyChange('borderRadius', this.borderRadius); + this.notifyPropertyChange('borderWidth', this.borderWidth); + } + + selectComponentType(args): void { + this.selectedComponentType = args.object.componentType; + } + + selectBackgroundType(args): void { + this.selectedBackgroundType = args.object.backgroundType; + } + + selectBorderType(args): void { + this.selectedBorderType = args.object.borderType; + } + + selectAnimationType(args): void { + this._selectedAnimation = args.object.animationType; + } + + applyBoxShadow(): void { + if (!this._boxShadow) { + this._boxShadow = ''; + } + this.appliedBoxShadow = this._boxShadow; + this.notifyPropertyChange('appliedBoxShadow', this.appliedBoxShadow); + + // TODO: this is a workaround to apply shadow immediately, + // since the box-shadow logic is currently inside background.ts + this.notifyPropertyChange('background', ''); + this.notifyPropertyChange('background', this.background); + } + + textChange(args): void { + this._boxShadow = args.object.text; + } + + toggleAnimation(args) { + const view = args.object; + const animationDuration = 500; + if (this._selectedAnimation === 'width') { + const originalWidth = args.object.getActualSize().width; + view + .animate({ + width: originalWidth / 2, + duration: animationDuration, + }) + .then(() => + view.animate({ + width: originalWidth, + duration: animationDuration, + }) + ) + .catch((err) => { + console.error('animation error', err); + }); + } else if (this._selectedAnimation === 'height') { + const originalHeight = args.object.getActualSize().height; + view + .animate({ + height: originalHeight / 2, + duration: animationDuration, + }) + .then(() => + view.animate({ + height: originalHeight, + duration: animationDuration, + }) + ) + .catch((err) => { + console.error('animation error', err); + }); + } else { + view + .animate({ + opacity: this._selectedAnimation === 'opacity' ? 0 : 1, + scale: this._selectedAnimation === 'scale' ? { x: 0.5, y: 0.6 } : { x: 1, y: 1 }, + rotate: this._selectedAnimation === 'rotate' ? 180 : 0, + translate: this._selectedAnimation === 'translate' ? { x: 100, y: 100 } : { x: 0, y: 0 }, + duration: 500, + }) + .then(() => + view.animate({ + opacity: 1, + scale: { x: 1, y: 1 }, + rotate: 0, + translate: { x: 0, y: 0 }, + duration: 500, + }) + ) + .catch((err) => { + console.error('animation error', err); + }); + } + } +} diff --git a/apps/toolbox/src/box-shadow.xml b/apps/toolbox/src/box-shadow.xml new file mode 100644 index 000000000..19bf5963d --- /dev/null +++ b/apps/toolbox/src/box-shadow.xml @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/toolbox/src/main-page.xml b/apps/toolbox/src/main-page.xml index 71af63541..580accecb 100644 --- a/apps/toolbox/src/main-page.xml +++ b/apps/toolbox/src/main-page.xml @@ -1,86 +1,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + +