@@ -5,46 +5,67 @@ import Yosemite
55struct InboxNoteRow : View {
66 let viewModel : InboxNoteRowViewModel
77
8+ // Tracks the scale of the view due to accessibility changes.
9+ @ScaledMetric private var scale : CGFloat = 1
10+
811 var body : some View {
912 VStack ( spacing: 0 ) {
10- VStack ( alignment: . leading,
11- spacing: Constants . verticalSpacing) {
13+ VStack ( alignment: . leading, spacing: 0 ) {
1214 // HStack with type icon and relative date.
13- // TODO: 5954 - type icon and relative date
15+ HStack {
16+ Circle ( )
17+ . frame ( width: scale * Constants. typeIconDimension, height: scale * Constants. typeIconDimension, alignment: . center)
18+ . foregroundColor ( Color ( Constants . typeIconCircleColor) )
19+ . overlay (
20+ viewModel. typeIcon
21+ . resizable ( )
22+ . scaledToFit ( )
23+ . padding ( scale * Constants. typeIconPadding)
24+ )
25+ Text ( viewModel. date)
26+ . font ( . subheadline)
27+ . foregroundColor ( Color ( Constants . dateTextColor) )
28+ Spacer ( )
29+ }
1430
15- // Title.
16- Text ( viewModel. title)
17- . bodyStyle ( )
18- . fixedSize ( horizontal: false , vertical: true )
31+ Spacer ( )
32+ . frame ( height: 8 )
1933
20- // Content.
21- AttributedText ( viewModel. attributedContent)
22- . attributedTextLinkColor ( Color ( . accent) )
34+ VStack ( alignment: . leading, spacing: Constants . verticalSpacing) {
35+ // Title.
36+ Text ( viewModel. title)
37+ . bodyStyle ( )
38+ . fixedSize ( horizontal: false , vertical: true )
2339
24- // HStack with actions and dismiss action.
25- HStack ( spacing: Constants . spacingBetweenActions) {
26- ForEach ( viewModel. actions) { action in
27- if let url = action. url {
28- Button ( action. title) {
29- // TODO: 5955 - handle action
30- print ( " Handling action with URL: \( url) " )
40+ // Content.
41+ AttributedText ( viewModel. attributedContent)
42+ . attributedTextLinkColor ( Color ( . accent) )
43+
44+ // HStack with actions and dismiss action.
45+ HStack ( spacing: Constants . spacingBetweenActions) {
46+ ForEach ( viewModel. actions) { action in
47+ if let url = action. url {
48+ Button ( action. title) {
49+ // TODO: 5955 - handle action
50+ print ( " Handling action with URL: \( url) " )
51+ }
52+ . foregroundColor ( Color ( . accent) )
53+ . font ( . body)
54+ . buttonStyle ( PlainButtonStyle ( ) )
55+ } else {
56+ Text ( action. title)
3157 }
32- . foregroundColor ( Color ( . accent) )
33- . font ( . body)
34- . buttonStyle ( PlainButtonStyle ( ) )
35- } else {
36- Text ( action. title)
3758 }
38- }
39- Button ( Localization . dismiss) {
40- // TODO: 5955 - handle dismiss action
41- print ( " Handling dismiss action " )
42- }
43- . foregroundColor ( Color ( . withColorStudio( . gray, shade: . shade30) ) )
44- . font ( . body)
45- . buttonStyle ( PlainButtonStyle ( ) )
59+ Button ( Localization . dismiss) {
60+ // TODO: 5955 - handle dismiss action
61+ print ( " Handling dismiss action " )
62+ }
63+ . foregroundColor ( Color ( . withColorStudio( . gray, shade: . shade30) ) )
64+ . font ( . body)
65+ . buttonStyle ( PlainButtonStyle ( ) )
4666
47- Spacer ( )
67+ Spacer ( )
68+ }
4869 }
4970 }
5071 . padding ( Constants . defaultPadding)
@@ -69,15 +90,21 @@ private extension InboxNoteRow {
6990 static let verticalSpacing : CGFloat = 14
7091 static let defaultPadding : CGFloat = 16
7192 static let dividerHeight : CGFloat = 1
93+ static let dateTextColor : UIColor = . withColorStudio( . gray, shade: . shade30)
94+ static let typeIconDimension : CGFloat = 29
95+ static let typeIconPadding : CGFloat = 5
96+ static let typeIconCircleColor : UIColor = . init( light: . withColorStudio( . gray, shade: . shade0) , dark: . withColorStudio( . gray, shade: . shade70) )
7297 }
7398}
7499
75100struct InboxNoteRow_Previews : PreviewProvider {
76101 static var previews : some View {
102+ // Monday, February 14, 2022 1:04:42 PM
103+ let today = Date ( timeIntervalSince1970: 1644843882 )
77104 let note = InboxNote ( siteID: 2 ,
78105 id: 6 ,
79106 name: " " ,
80- type: " " ,
107+ type: " marketing " ,
81108 status: " " ,
82109 actions: [ . init( id: 2 , name: " " , label: " Let your customers know about Apple Pay " , status: " " , url: " https://wordpress.org " ) ,
83110 . init( id: 6 , name: " " , label: " No URL " , status: " " , url: " " ) ] ,
@@ -91,13 +118,33 @@ struct InboxNoteRow_Previews: PreviewProvider {
91118 isRemoved: false ,
92119 isRead: false ,
93120 dateCreated: . init( ) )
94- let viewModel = InboxNoteRowViewModel ( note: note)
121+ let shortNote = InboxNote ( siteID: 2 ,
122+ id: 6 ,
123+ name: " " ,
124+ type: " " ,
125+ status: " " ,
126+ actions: [ . init( id: 2 , name: " " , label: " Learn Apple Pay " , status: " " , url: " https://wordpress.org " ) ,
127+ . init( id: 6 , name: " " , label: " No URL " , status: " " , url: " " ) ] ,
128+ title: " Boost sales this holiday season with Apple Pay! " ,
129+ content: " Increase your conversion rate. " ,
130+ isRemoved: false ,
131+ isRead: false ,
132+ dateCreated: today)
95133 Group {
96- InboxNoteRow ( viewModel: viewModel)
134+ List {
135+ InboxNoteRow ( viewModel: . init( note: note. copy ( type: " marketing " , dateCreated: today) , today: today) )
136+ InboxNoteRow ( viewModel: . init( note: shortNote. copy ( type: " error " ) . copy ( dateCreated: today. addingTimeInterval ( - 6 * 60 ) ) , today: today) )
137+ InboxNoteRow ( viewModel: . init( note: shortNote. copy ( type: " warning " ) . copy ( dateCreated: today. addingTimeInterval ( - 6 * 3600 ) ) , today: today) )
138+ InboxNoteRow ( viewModel: . init( note: shortNote. copy ( type: " update " ) . copy ( dateCreated: today. addingTimeInterval ( - 6 * 86400 ) ) , today: today) )
139+ InboxNoteRow ( viewModel: . init( note: shortNote. copy ( type: " info " ) . copy ( dateCreated: today. addingTimeInterval ( - 14 * 86400 ) ) , today: today) )
140+ InboxNoteRow ( viewModel: . init( note: shortNote. copy ( type: " survey " ) . copy ( dateCreated: today. addingTimeInterval ( - 1.5 * 86400 ) ) , today: today) )
141+ }
97142 . preferredColorScheme ( . dark)
98- InboxNoteRow ( viewModel: viewModel)
143+ . environment ( \. sizeCategory, . extraSmall)
144+ . previewLayout ( . sizeThatFits)
145+ InboxNoteRow ( viewModel: . init( note: note. copy ( dateCreated: today. addingTimeInterval ( - 86400 * 2 ) ) , today: today) )
99146 . preferredColorScheme ( . light)
100- InboxNoteRow ( viewModel: viewModel )
147+ InboxNoteRow ( viewModel: . init ( note : note . copy ( dateCreated : today . addingTimeInterval ( - 6 * 60 ) ) , today : today ) )
101148 . preferredColorScheme ( . light)
102149 . environment ( \. sizeCategory, . extraExtraExtraLarge)
103150 }
0 commit comments