on master help sign in
Extract Grid with bottom bar into reusable withBottomBar layout function
commit8f3a00e44da9aa468b95422626297eb24cde4cd6 authoriko <mail@iko.soy> dateFri 17 Apr 2026, 18:53 (6 months ago) parent9eb5982
3 files changed+44−41
client/Styles.fs+16 client/ViewConversations.fs+20−27 client/ViewEditProfile.fs+8−14
client/Styles.fs+16
@@ -5,7 +5,12 @@ module Styles =
55 open Avalonia
66 open Avalonia.Controls
77 open Avalonia.Controls.Presenters
8+ open Avalonia.Media
89 open Avalonia.Styling
10+ open Fabulous
11+ open Fabulous.Avalonia
12+
13+ open type Fabulous.Avalonia.View
914
1015 let style (selector: Selector -> Selector) (setters: Setter list) =
1116 let s = Style(selector)
@@ -15,6 +20,17 @@ module Styles =
1520
1621 s :> IStyle
1722
23+ let withBottomBar (bar: WidgetBuilder<'msg, 'a>) (content: WidgetBuilder<'msg, 'b>) =
24+ Grid([], [ Dimension.Star; Dimension.Auto ]) {
25+ AnyView(content).gridRow (0)
26+
27+ Border(AnyView(bar))
28+ .borderThickness(Avalonia.Thickness(0., 4., 0., 0.))
29+ .borderBrush(SolidColorBrush(Colors.Black))
30+ .background(Constants.accentColor)
31+ .gridRow (1)
32+ }
33+
1834 let noListBoxPadding () =
1935 [ style
2036 _.OfType<ListBoxItem>()
client/ViewConversations.fs+20−27
@@ -16,16 +16,15 @@ module ViewConversations =
1616 let viewConversations model =
1717 let contacts = model.Contacts.Values |> Seq.toList
1818
19− (Grid([], [ Dimension.Star; Dimension.Auto ]) {
20−
19+ let content =
2120 if contacts.IsEmpty then
22− TextBlock("No contacts yet. Tap + to add one.")
23− .centerText()
24− .foreground(SolidColorBrush(Colors.Gray))
25− .gridRow (1)
26−
27− if not contacts.IsEmpty then
28− ListBox(
21+ AnyView(
22+ TextBlock("No contacts yet. Tap + to add one.")
23+ .centerText()
24+ .foreground(SolidColorBrush(Colors.Gray))
25+ )
26+ else
27+ AnyView(ListBox(
2928 contacts,
3029 fun c ->
3130 let name = contactName model.Contacts c.Pubkey
@@ -74,21 +73,15 @@ module ViewConversations =
7473 .onTapped (fun _ -> SetPage(Chat(c.Pubkey, "")))
7574 )
7675 .styles(noListBoxPadding ())
77− .background(Colors.White)
78− .gridRow (0)
79−
80− Border(
81− (Grid([ Dimension.Auto; Dimension.Star; Dimension.Auto ], []) {
82− (smallImageButton None (SetPage Settings)).gridColumn (0)
83− (textField "" Search).margin(0.).margin(8.).gridColumn (1)
84− (smallTextButton "+" (SetPage(AddContact("", "")))).gridColumn (2)
85− })
86− .margin(20.)
87− .horizontalAlignment (HorizontalAlignment.Stretch)
88− )
89− .borderThickness(Avalonia.Thickness(0., 4., 0., 0.))
90− .borderBrush(SolidColorBrush(Colors.Black))
91− .background(Constants.accentColor)
92− .gridRow (1)
93− })
94− .margin (0.)
76+ .background(Colors.White))
77+
78+ let bar =
79+ (Grid([ Dimension.Auto; Dimension.Star; Dimension.Auto ], []) {
80+ (smallImageButton None (SetPage Settings)).gridColumn (0)
81+ (textField "" Search).margin(0.).margin(8.).gridColumn (1)
82+ (smallTextButton "+" (SetPage(AddContact("", "")))).gridColumn (2)
83+ })
84+ .margin(20.)
85+ .horizontalAlignment (HorizontalAlignment.Stretch)
86+
87+ withBottomBar bar content
client/ViewEditProfile.fs+8−14
@@ -10,9 +10,10 @@ module ViewEditProfile =
1010 open AppTypes
1111 open Buttons
1212 open TextFields
13+ open Styles
1314
1415 let viewEditProfile model displayName bio (photo: byte[] option) =
15− (Grid([], [ Dimension.Star; Dimension.Auto ]) {
16+ let content =
1617 ScrollViewer(
1718 (VStack(16.) {
1819 viewErrorBanner model.Error
@@ -30,18 +31,11 @@ module ViewEditProfile =
3031 })
3132 .margin (20.)
3233 )
33− .gridRow (0)
3434
35− Border(
35+ let bar =
36+ HStack(8.) {
37+ (button Secondary "back" (SetPage Settings)).margin (8.)
38+ (button Secondary "save" DoSaveProfile).margin (8.)
39+ }
3640
37− (HStack(8.) {
38− (button Secondary "back" (SetPage Settings)).margin (8.)
39−
40− (button Secondary "save" DoSaveProfile).margin (8.)
41− })
42− .background (Constants.accentColor)
43− )
44− .borderThickness(Avalonia.Thickness(0., 4., 0., 0.))
45− .borderBrush(SolidColorBrush(Colors.Black))
46− .gridRow (1)
47− })
41+ withBottomBar bar content