1
1
import { 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' ;
3
13
import { CardViewBase } from './cardview-common' ;
4
14
5
15
// use custom class to get the same behavior as android which is
@@ -21,13 +31,18 @@ class Card extends MDCCardCollectionCell {
21
31
22
32
export class CardView extends CardViewBase {
23
33
nativeViewProtected : Card ;
24
-
34
+ scheme : MDCContainerScheme ;
25
35
public createNativeView ( ) {
26
36
const view = Card . new ( ) as Card ;
27
37
const colorScheme = themer . getAppColorScheme ( ) as MDCSemanticColorScheme ;
28
38
if ( colorScheme ) {
29
39
const scheme = MDCContainerScheme . alloc ( ) . init ( ) ;
30
40
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 ) ;
31
46
view . applyThemeWithScheme ( scheme ) ;
32
47
}
33
48
view . interactable = this . isUserInteractionEnabled ;
@@ -44,7 +59,83 @@ export class CardView extends CardViewBase {
44
59
getDefaultDynamicElevationOffset ( ) {
45
60
return 1 ;
46
61
}
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
+ }
47
102
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
+ }
48
139
// trick to get the same behavior as android (don't disable all children)
49
140
[ isUserInteractionEnabledProperty . setNative ] ( value : boolean ) {
50
141
this . nativeViewProtected . interactable = value ;
@@ -71,9 +162,9 @@ export class CardView extends CardViewBase {
71
162
if ( value . color ) {
72
163
this . nativeViewProtected . backgroundColor = value . color ? value . color . ios : null ;
73
164
}
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;
77
168
}
78
169
}
79
170
[ rippleColorProperty . setNative ] ( color : Color ) {
0 commit comments