|
1 | 1 | <script lang="ts"> |
2 | 2 | import { lang } from '~/helpers/locale'; |
3 | | - import { PKPass, PKPassData, PKPassField, PKPassStructure, PKPassTransitType } from '~/models/PKPass'; |
| 3 | + import { PKPass, PKPassData, PKPassField, PKPassStructure, PKPassStyle, PKPassTransitType, PKPassType } from '~/models/PKPass'; |
4 | 4 | import { getFieldTextAlignment, getTransitIcon } from '~/utils/pkpass'; |
5 | 5 | import { colors } from '~/variables'; |
6 | 6 | import { Item } from '~/components/list/MainList.svelte'; |
| 7 | + import { Color } from '@nativescript/core'; |
7 | 8 |
|
8 | 9 | const FIELD_LINE_HEIGHT = 15; |
9 | 10 |
|
|
43 | 44 |
|
44 | 45 | function updatePkPass(pkpass: PKPass) { |
45 | 46 | passData = pkpass?.passData; |
46 | | - foregroundColor = passData?.foregroundColor || colorOnBackground; |
47 | | - labelColor = passData.labelColor || colorOnBackground; |
48 | 47 | backgroundColor = passData?.backgroundColor || colorSurface; |
| 48 | + foregroundColor = passData?.foregroundColor || (new Color(backgroundColor).getBrightness() < 145 ? 'white' : 'black'); |
| 49 | + labelColor = passData.labelColor || (new Color(backgroundColor).getBrightness() < 145 ? 'white' : 'black'); |
49 | 50 | // Apple PKPass image specifications - prefer @2x for quality |
50 | 51 | logoImage = pkpass?.images?.logo2x || pkpass?.images?.logo; // Max 160x50 points |
51 | 52 | iconImage = pkpass?.images?.icon2x || pkpass?.images?.icon; // 29x29 points |
|
79 | 80 | // Get formatted field label |
80 | 81 | function getFieldLabel(field: any): string { |
81 | 82 | if (!field) return null; |
82 | | - const label = field.label || field.key; |
83 | | - return pkpass.getLocalizedValue(label, lang).toUpperCase() + '\n'; |
| 83 | + return pkpass.getLocalizedFieldLabel(field, lang).toUpperCase() + '\n'; |
84 | 84 | } |
85 | 85 |
|
86 | 86 | function getLocalizedText(text: string): string { |
|
90 | 90 |
|
91 | 91 | <!-- Credit card sized layout with scalable content --> |
92 | 92 | <gridlayout {backgroundColor} borderRadius={12 * scaleFactor} {...$$restProps}> |
| 93 | + {#if stripImage && pkpass?.passType === PKPassType.ESpass} |
| 94 | + <image noRatioEnforce={true} opacity={0.3} rowSpan={4} src={stripImage} stretch="aspectFill" width="100%" /> |
| 95 | + {/if} |
93 | 96 | <!-- Strip or thumbnail banner at top if available --> |
94 | | - <image colSpan={3} height={60 * scaleFactor} row={0} src={stripImage || thumbnailImage} stretch="aspectFill" visibility={stripImage || thumbnailImage ? 'visible' : 'collapse'} /> |
| 97 | + {#if pkpass?.passType === PKPassType.PKPass} |
| 98 | + <image colSpan={3} height={60 * scaleFactor} row={0} src={stripImage || thumbnailImage} stretch="aspectFill" visibility={stripImage || thumbnailImage ? 'visible' : 'collapse'} /> |
| 99 | + {/if} |
95 | 100 |
|
96 | 101 | <!-- Content container with proper padding --> |
97 | | - <gridlayout padding={12 * scaleFactor} rows="auto,*,auto,auto"> |
| 102 | + <gridlayout padding={12 * scaleFactor} rows={`auto,${pkpass?.getPassStyle() === PKPassStyle.BoardingPass ? '*' : 'auto'},auto,auto`}> |
98 | 103 | <!-- Top row: Logo/Icon + Name (limited width) + Important right-side data --> |
99 | 104 | <gridlayout columns="auto,*,auto" marginBottom={5 * scaleFactor} row={0}> |
100 | 105 | <!-- Left: Logo (max 80px scaled) or Icon (20px scaled) + Name --> |
|
0 commit comments