|
1 | 1 | import { Application, Background, Button, Color, Length, View, androidDynamicElevationOffsetProperty, androidElevationProperty, backgroundInternalProperty, profile } from '@nativescript/core'; |
2 | 2 | import { createRippleDrawable, createStateListAnimator, getAttrColor, getColorStateList, handleClearFocus, isPostLollipop, isPostLollipopMR1, isPostMarshmallow } from './android/utils'; |
3 | | -import { applyMixins } from './index.common'; |
| 3 | +import { CornerFamily, applyMixins } from './index.common'; |
4 | 4 | import { cssProperty, dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty } from './cssproperties'; |
5 | 5 | import { ad } from '@nativescript/core/utils'; |
| 6 | +import { ShapeProperties } from '.'; |
6 | 7 | export * from './cssproperties'; |
7 | 8 | export { applyMixins }; |
8 | 9 |
|
| 10 | +function createCornerTreatment(cornerFamily: CornerFamily): com.google.android.material.shape.CornerTreatment { |
| 11 | + switch (cornerFamily) { |
| 12 | + case CornerFamily.CUT: |
| 13 | + return new com.google.android.material.shape.CutCornerTreatment(); |
| 14 | + default: |
| 15 | + case CornerFamily.ROUNDED: |
| 16 | + return new com.google.android.material.shape.RoundedCornerTreatment(); |
| 17 | + } |
| 18 | +} |
| 19 | + |
9 | 20 | // stub class as we don't use this on android |
10 | 21 | export class Themer { |
11 | 22 | primaryColor: string | Color; |
@@ -79,6 +90,67 @@ export class Themer { |
79 | 90 | } |
80 | 91 | return this.controlHighlightColor; |
81 | 92 | } |
| 93 | + |
| 94 | + _shapes: { |
| 95 | + [k: string]: com.google.android.material.shape.ShapeAppearanceModel; |
| 96 | + } = {}; |
| 97 | + getShape(key: string) { |
| 98 | + return this._shapes[key] || null; |
| 99 | + } |
| 100 | + createShape(key: string, options: ShapeProperties) { |
| 101 | + const builder = com.google.android.material.shape.ShapeAppearanceModel.builder(); |
| 102 | + if (options.cornerFamily) { |
| 103 | + builder.setAllCorners(createCornerTreatment(options.cornerFamily)); |
| 104 | + } |
| 105 | + if (options.cornerFamilyBottomRight) { |
| 106 | + builder.setBottomRightCorner(createCornerTreatment(options.cornerFamilyBottomRight)); |
| 107 | + } |
| 108 | + if (options.cornerFamilyBottomLeft) { |
| 109 | + builder.setBottomLeftCorner(createCornerTreatment(options.cornerFamilyBottomLeft)); |
| 110 | + } |
| 111 | + if (options.cornerFamilyTopLeft) { |
| 112 | + builder.setTopLeftCorner(createCornerTreatment(options.cornerFamilyTopLeft)); |
| 113 | + } |
| 114 | + if (options.cornerFamilyTopRight) { |
| 115 | + builder.setTopRightCorner(createCornerTreatment(options.cornerFamilyTopRight)); |
| 116 | + } |
| 117 | + if (options.cornerSize !== undefined) { |
| 118 | + if (typeof options.cornerSize === 'object') { |
| 119 | + builder.setAllCornerSizes(new com.google.android.material.shape.RelativeCornerSize(options.cornerSize.value)); |
| 120 | + } else { |
| 121 | + builder.setAllCornerSizes(options.cornerSize); |
| 122 | + } |
| 123 | + } |
| 124 | + if (options.cornerSizeBottomLeft !== undefined) { |
| 125 | + if (typeof options.cornerSizeBottomLeft === 'object') { |
| 126 | + builder.setBottomLeftCornerSize(new com.google.android.material.shape.RelativeCornerSize(options.cornerSizeBottomLeft.value)); |
| 127 | + } else { |
| 128 | + builder.setBottomLeftCornerSize(options.cornerSizeBottomLeft); |
| 129 | + } |
| 130 | + } |
| 131 | + if (options.cornerSizeBottomRight !== undefined) { |
| 132 | + if (typeof options.cornerSizeBottomRight === 'object') { |
| 133 | + builder.setBottomRightCornerSize(new com.google.android.material.shape.RelativeCornerSize(options.cornerSizeBottomRight.value)); |
| 134 | + } else { |
| 135 | + builder.setBottomRightCornerSize(options.cornerSizeBottomRight); |
| 136 | + } |
| 137 | + } |
| 138 | + if (options.cornerSizeTopRight !== undefined) { |
| 139 | + if (typeof options.cornerSizeTopRight === 'object') { |
| 140 | + builder.setTopRightCornerSize(new com.google.android.material.shape.RelativeCornerSize(options.cornerSizeTopRight.value)); |
| 141 | + } else { |
| 142 | + builder.setTopRightCornerSize(options.cornerSizeTopRight); |
| 143 | + } |
| 144 | + } |
| 145 | + if (options.cornerSizeTopLeft !== undefined) { |
| 146 | + if (typeof options.cornerSizeTopLeft === 'object') { |
| 147 | + builder.setTopLeftCornerSize(new com.google.android.material.shape.RelativeCornerSize(options.cornerSizeTopLeft.value)); |
| 148 | + } else { |
| 149 | + builder.setTopLeftCornerSize(options.cornerSizeTopLeft); |
| 150 | + } |
| 151 | + } |
| 152 | + this._shapes[key] = builder.build(); |
| 153 | + } |
82 | 154 | } |
83 | 155 |
|
84 | 156 | export const themer = new Themer(); |
|
0 commit comments