11import { dynamicElevationOffsetProperty , elevationProperty , getRippleColor , rippleColorProperty , themer } from '@nativescript-community/ui-material-core' ;
2- import { Background , Color , Screen , backgroundInternalProperty , isUserInteractionEnabledProperty } from '@nativescript/core' ;
2+ import {
3+ Background ,
4+ Color ,
5+ Screen ,
6+ backgroundInternalProperty ,
7+ borderBottomLeftRadiusProperty ,
8+ borderBottomRightRadiusProperty ,
9+ borderTopLeftRadiusProperty ,
10+ borderTopRightRadiusProperty ,
11+ isUserInteractionEnabledProperty
12+ } from '@nativescript/core' ;
313import { CardViewBase } from './cardview-common' ;
414
515// use custom class to get the same behavior as android which is
@@ -21,13 +31,18 @@ class Card extends MDCCardCollectionCell {
2131
2232export class CardView extends CardViewBase {
2333 nativeViewProtected : Card ;
24-
34+ scheme : MDCContainerScheme ;
2535 public createNativeView ( ) {
2636 const view = Card . new ( ) as Card ;
2737 const colorScheme = themer . getAppColorScheme ( ) as MDCSemanticColorScheme ;
2838 if ( colorScheme ) {
2939 const scheme = MDCContainerScheme . alloc ( ) . init ( ) ;
3040 scheme . colorScheme = colorScheme ;
41+ this . scheme = scheme ;
42+ if ( this . shape ) {
43+ this . scheme . shapeScheme = this . getShapeScheme ( ) ;
44+ }
45+ console . log ( 'createNativeView' , this . scheme . shapeScheme ) ;
3146 view . applyThemeWithScheme ( scheme ) ;
3247 }
3348 view . interactable = this . isUserInteractionEnabled ;
@@ -44,7 +59,83 @@ export class CardView extends CardViewBase {
4459 getDefaultDynamicElevationOffset ( ) {
4560 return 1 ;
4661 }
62+ applyShapeScheme ( ) {
63+ if ( this . scheme ) {
64+ this . scheme . shapeScheme = this . shapeScheme ;
65+ console . log ( 'applyShapeScheme' ) ;
66+ this . nativeViewProtected . applyThemeWithScheme ( this . scheme ) ;
67+ }
68+ }
69+ [ borderBottomLeftRadiusProperty . setNative ] ( value ) {
70+ this . setBottomLeftCornerRadius ( value ) ;
71+ this . applyShapeScheme ( ) ;
72+ }
73+ [ borderBottomRightRadiusProperty . setNative ] ( value ) {
74+ this . setBottomRightCornerRadius ( value ) ;
75+ this . applyShapeScheme ( ) ;
76+ }
77+ [ borderTopLeftRadiusProperty . setNative ] ( value ) {
78+ this . setTopLeftCornerRadius ( value ) ;
79+ this . applyShapeScheme ( ) ;
80+ }
81+ [ borderTopRightRadiusProperty . setNative ] ( value ) {
82+ this . setTopRightCornerRadius ( value ) ;
83+ this . applyShapeScheme ( ) ;
84+ }
85+ shapeScheme : MDCShapeScheme ;
86+ private getShapeScheme ( ) {
87+ if ( ! this . shapeScheme ) {
88+ if ( this . shape ) {
89+ // we need to copy it as if we change border radius on this view
90+ // it will change for everyone else
91+ this . shapeScheme = MDCShapeScheme . new ( ) ;
92+ const shapeScheme = themer . getShape ( this . shape ) ;
93+ this . shapeScheme . smallComponentShape = shapeScheme . smallComponentShape . copy ( ) ;
94+ } else {
95+ this . shapeScheme = MDCShapeScheme . new ( ) ;
96+ const shapeCategory = MDCShapeCategory . new ( ) ;
97+ this . shapeScheme . smallComponentShape = shapeCategory ;
98+ }
99+ }
100+ return this . shapeScheme ;
101+ }
47102
103+ private setBottomLeftCornerRadius ( value : number ) {
104+ const shapeScheme = this . getShapeScheme ( ) ;
105+ const current = shapeScheme . smallComponentShape . bottomLeftCorner ;
106+ if ( current instanceof MDCCutCornerTreatment ) {
107+ shapeScheme . smallComponentShape . bottomLeftCorner = MDCCornerTreatment . cornerWithCut ( value ) ;
108+ } else {
109+ shapeScheme . smallComponentShape . bottomLeftCorner = MDCCornerTreatment . cornerWithRadius ( value ) ;
110+ }
111+ }
112+ private setBottomRightCornerRadius ( value : number ) {
113+ const shapeScheme = this . getShapeScheme ( ) ;
114+ const current = shapeScheme . smallComponentShape . bottomRightCorner ;
115+ if ( current instanceof MDCCutCornerTreatment ) {
116+ shapeScheme . smallComponentShape . bottomRightCorner = MDCCornerTreatment . cornerWithCut ( value ) ;
117+ } else {
118+ shapeScheme . smallComponentShape . bottomRightCorner = MDCCornerTreatment . cornerWithRadius ( value ) ;
119+ }
120+ }
121+ private setTopLeftCornerRadius ( value : number ) {
122+ const shapeScheme = this . getShapeScheme ( ) ;
123+ const current = shapeScheme . smallComponentShape . topLeftCorner ;
124+ if ( current instanceof MDCCutCornerTreatment ) {
125+ shapeScheme . smallComponentShape . topLeftCorner = MDCCornerTreatment . cornerWithCut ( value ) ;
126+ } else {
127+ shapeScheme . smallComponentShape . topLeftCorner = MDCCornerTreatment . cornerWithRadius ( value ) ;
128+ }
129+ }
130+ private setTopRightCornerRadius ( value : number ) {
131+ const shapeScheme = this . getShapeScheme ( ) ;
132+ const current = shapeScheme . smallComponentShape . topRightCorner ;
133+ if ( current instanceof MDCCutCornerTreatment ) {
134+ shapeScheme . smallComponentShape . topRightCorner = MDCCornerTreatment . cornerWithCut ( value ) ;
135+ } else {
136+ shapeScheme . smallComponentShape . topRightCorner = MDCCornerTreatment . cornerWithRadius ( value ) ;
137+ }
138+ }
48139 // trick to get the same behavior as android (don't disable all children)
49140 [ isUserInteractionEnabledProperty . setNative ] ( value : boolean ) {
50141 this . nativeViewProtected . interactable = value ;
@@ -71,9 +162,9 @@ export class CardView extends CardViewBase {
71162 if ( value . color ) {
72163 this . nativeViewProtected . backgroundColor = value . color ? value . color . ios : null ;
73164 }
74- this . nativeViewProtected . setBorderWidthForState ( value . borderLeftWidth / scale , MDCCardCellState . Normal ) ;
75- this . nativeViewProtected . setBorderColorForState ( value . borderTopColor ? value . borderTopColor . ios : null , MDCCardCellState . Normal ) ;
76- this . nativeViewProtected . cornerRadius = value . borderTopLeftRadius / scale ;
165+ // this.nativeViewProtected.setBorderWidthForState(value.borderLeftWidth / scale, MDCCardCellState.Normal);
166+ // this.nativeViewProtected.setBorderColorForState(value.borderTopColor ? value.borderTopColor.ios : null, MDCCardCellState.Normal);
167+ // this.nativeViewProtected.cornerRadius = value.borderTopLeftRadius / scale;
77168 }
78169 }
79170 [ rippleColorProperty . setNative ] ( color : Color ) {
0 commit comments