import { View , PercentLength } from '@nativescript/core' ; import { ViewModelBase } from '../layouts/myview-base' ; export class ViewModelWithPercentage extends ViewModelBase { constructor ( ) { super ( ) ; } public onWidthHeight ( args ) { let view = args . object ; if ( ! PercentLength . equals ( view . marginLeft , { value : 0.5 , unit : '%' } ) ) { super . setWidthHeight ( view , '50%' , '50%' ) ; } else { super . setWidthHeight ( view , '75%' , '75%' ) ; } } public onMargins ( args ) { let view = args . object ; if ( ! PercentLength . equals ( view . marginLeft , { value : 0.1 , unit : '%' } ) ) { super . setMargins ( view , '10%' , '10%' , '10%' , '10%' ) ; } else { super . setMargins ( view , 0 , 0 , 0 , 0 ) ; } } public onMinWidthMinHeight ( args ) { let view = args . object ; if ( ! PercentLength . equals ( view . marginLeft , 105 ) ) { super . setMinWidthHeight ( view , 105 , 55 ) ; } else { super . setMinWidthHeight ( view , 0 , 0 ) ; } } public onAllProperties ( args ) { let child ; let layout = args . object . parent ; child = < View > layout . getViewById ( 'widthHeight' ) ; if ( ! PercentLength . equals ( ( < any > child ) . width , { value : 0.5 , unit : '%' } ) ) { super . setWidthHeight ( child , '50%' , '50%' ) ; } else { super . setWidthHeight ( child , '75%' , '75%' ) ; } child = < View > layout . getViewById ( 'minWidthMinHeight' ) ; if ( child . minWidth !== 105 ) { super . setMinWidthHeight ( child , 105 , 55 ) ; } else { super . setMinWidthHeight ( child , 0 , 0 ) ; } child = layout . getViewById ( 'margins' ) ; if ( ! PercentLength . equals ( child . marginLeft , { value : 0.1 , unit : '%' } ) ) { super . setMargins ( child , '10%' , '10%' , '10%' , '10%' ) ; } else { super . setMargins ( child , 0 , 0 , 0 , 0 ) ; } child = layout . getViewById ( 'alignments' ) ; super . setAllPositioningProperties ( child ) ; super . toggleVisibility ( child ) ; if ( layout . paddingLeft !== 5 ) { super . setPaddings ( layout , 5 , 5 , 5 , 5 ) ; } else { super . setPaddings ( layout , 0 , 0 , 0 , 0 ) ; } } }