From 8239b0f02fcd249385b6db2cb6378d469319b44a Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 3 Apr 2023 17:49:28 +0330 Subject: [PATCH] Frontend.Maui: add BalancesPage Add BalancesPage. Fixed and simplified layout of BalancesPage. Fix layout of currency balances on balances page in Maui. Fix circle chart rendering in Maui. Use Launcher from Maui.Essentials on Maui instead of one from Xamarin.Essentials. Made click event handlers work for Gtk. Had to wrap footer label in a Frame for this. LogoImg had wrong size and it had to be resized based on the layout size. The reason is that Aspect for Image is not working in Maui/Gtk and should be fixed later (see [1]). Also added #nowarn 44 and #nowarn 1182 in BalancesPage, CircleChartView, and FrontendHelpers because of the following warnings: ``` BalancesPage.xaml.fs(503, 13): [FS1182] The value 'tapper' is unused BalancesPage.xaml.fs(443, 13): [FS1182] The value 'currentChartView' is unused BalancesPage.xaml.fs(443, 30): [FS1182] The value 'otherChartView' is unused BalancesPage.xaml.fs(439, 41): [FS1182] The value 'totalOtherFiatAmountFrame' is unused BalancesPage.xaml.fs(437, 13): [FS1182] The value 'switchingToReadOnly' is unused CircleChartView.fs(181, 35): [FS0044] This construct is deprecated. The StackLayout expansion options are deprecated; please use a Grid instead. BalancesPage.xaml.fs(53, 19): [FS1182] The value 'currencyImages' is unused CircleChartView.fs(180, 37): [FS0044] This construct is deprecated. The StackLayout expansion options are deprecated; please use a Grid instead. FrontendHelpers.fs(425, 60): [FS0044] This construct is deprecated. The StackLayout expansion options are deprecated; please use a Grid instead. ``` Co-authored-by: Parham [1] https://github.com/jsuarezruiz/maui-linux/issues/69 --- .gitignore | 1 + scripts/make.fsx | 2 +- .../GWallet.Frontend.Maui.fsproj | 83 ++++++++++++++ src/GWallet.Frontend.XF/BalancesPage.xaml.fs | 60 +++++++++-- .../Controls/CircleChartView.fs | 102 ++++++++++++------ src/GWallet.Frontend.XF/FrontendHelpers.fs | 78 +++++++++++--- src/GWallet.Frontend.XF/LoadingPage.xaml.fs | 13 --- 7 files changed, 270 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index ea122132a..cff268905 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,4 @@ fabric.properties src/GWallet.Frontend.Maui/WelcomePage.xaml src/GWallet.Frontend.Maui/WelcomePage2.xaml src/GWallet.Frontend.Maui/LoadingPage.xaml +src/GWallet.Frontend.Maui/BalancesPage.xaml diff --git a/scripts/make.fsx b/scripts/make.fsx index 2021850d1..887508103 100644 --- a/scripts/make.fsx +++ b/scripts/make.fsx @@ -260,7 +260,7 @@ let BuildSolutionOrProject // TODO: we have to change this function to be the other way around (i.e. copy from Maui to XF) once we // have a finished version of Maui and we consider XF as legacy. let CopyXamlFiles() = - let files = [| "WelcomePage.xaml"; "WelcomePage2.xaml"; "LoadingPage.xaml" |] + let files = [| "WelcomePage.xaml"; "WelcomePage2.xaml"; "LoadingPage.xaml"; "BalancesPage.xaml" |] for file in files do let sourcePath = Path.Combine("src", "GWallet.Frontend.XF", file) let destPath = Path.Combine("src", "GWallet.Frontend.Maui", file) diff --git a/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj b/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj index d63f18626..1288e22ed 100644 --- a/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj +++ b/src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj @@ -65,11 +65,94 @@ + + img\btc_grey_60x60.png + + + img\btc_red_60x60.png + + + img\btc_red_120x120.png + + + img\btc_grey_120x120.png + + + img\dai_grey_60x60.png + + + img\dai_grey_120x120.png + + + img\dai_red_60x60.png + + + img\dai_red_120x120.png + + + img\sai_grey_60x60.png + + + img\sai_grey_120x120.png + + + img\sai_red_60x60.png + + + img\sai_red_120x120.png + + + img\etc_grey_60x60.png + + + img\etc_grey_120x120.png + + + img\etc_red_60x60.png + + + img\etc_red_120x120.png + + + img\eth_grey_60x60.png + + + img\eth_grey_120x120.png + + + img\eth_red_60x60.png + + + img\eth_red_120x120.png + + + img\ltc_grey_60x60.png + + + img\ltc_grey_120x120.png + + + img\ltc_red_60x60.png + + + img\ltc_red_120x120.png + + + img\logo_512x512.png + + + + + + + + BalancesPage.xaml + LoadingPage.xaml diff --git a/src/GWallet.Frontend.XF/BalancesPage.xaml.fs b/src/GWallet.Frontend.XF/BalancesPage.xaml.fs index d81ebc4e4..0c7aa03ac 100644 --- a/src/GWallet.Frontend.XF/BalancesPage.xaml.fs +++ b/src/GWallet.Frontend.XF/BalancesPage.xaml.fs @@ -1,16 +1,36 @@ -namespace GWallet.Frontend.XF +#if XAMARIN +namespace GWallet.Frontend.XF +#else +namespace GWallet.Frontend.Maui +// We have unused variables because they are in the #XAMARIN sections. +// this should be removed once we fully integrate this code. +#nowarn "1182" +#endif open System open System.Linq open System.Threading open System.Threading.Tasks +#if !XAMARIN +open Microsoft.Maui +open Microsoft.Maui.Controls +open Microsoft.Maui.Controls.Xaml +open Microsoft.Maui.ApplicationModel +open Microsoft.Maui.Networking +#else open Xamarin.Forms open Xamarin.Forms.Xaml open Xamarin.Essentials +#endif + open Fsdk +#if XAMARIN open GWallet.Frontend.XF.Controls +#else +open GWallet.Frontend.Maui.Controls +#endif open GWallet.Backend open GWallet.Backend.FSharpUtil.UwpHacks @@ -217,7 +237,12 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, let activeCurrencyClassId,inactiveCurrencyClassId = FrontendHelpers.GetActiveAndInactiveCurrencyClassIds readOnly - let contentLayoutChildrenList = (contentLayout.Children |> List.ofSeq) + let contentLayoutChildrenList = +#if XAMARIN + (contentLayout.Children |> List.ofSeq) +#else + contentLayout.Children |> Seq.choose (function :? View as view -> Some view | _ -> None) |> List.ofSeq +#endif let activeCryptoBalances = FindCryptoBalances activeCurrencyClassId contentLayout @@ -247,19 +272,23 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, balances |> Seq.iteri (fun balanceIndex balanceState -> let balanceSet = balanceState.BalanceSet let tapGestureRecognizer = TapGestureRecognizer() +#if XAMARIN tapGestureRecognizer.Tapped.Subscribe(fun _ -> let receivePage () = ReceivePage(balanceSet.Account, readOnly, balanceState.UsdRate, self, balanceSet.Widgets) :> Page FrontendHelpers.SwitchToNewPage self receivePage true ) |> ignore +#endif let frame = balanceSet.Widgets.Frame frame.GestureRecognizers.Add tapGestureRecognizer contentLayout.Children.Add frame - +#if XAMARIN Grid.SetRow(frame, balanceIndex) +#else + contentLayout.SetRow(frame, balanceIndex) +#endif ) - contentLayout.BatchCommit() member __.UpdateGlobalFiatBalanceSum (fiatBalancesList: List>) totalFiatAmountLabel = @@ -370,7 +399,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, //Avoid cases when user changes timezone in device settings TimeSpan.Zero - Device.StartTimer(timerInterval + timerStartDelay, fun _ -> + FrontendHelpers.StartTimer(timerInterval + timerStartDelay, fun _ -> if not cancellationToken.IsCancellationRequested then async { try @@ -418,6 +447,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, mainLayout.FindByName otherChartViewName let tapGestureRecognizer = TapGestureRecognizer() +#if XAMARIN tapGestureRecognizer.Tapped.Add(fun _ -> let shouldNotOpenNewPage = @@ -467,6 +497,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, FrontendHelpers.SwitchToNewPage self page true ) +#endif totalCurrentFiatAmountFrame.GestureRecognizers.Add tapGestureRecognizer tapGestureRecognizer @@ -479,7 +510,11 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, RedrawCircleView false normalBalanceStates if startWithReadOnlyAccounts then +#if XAMARIN tapper.SendTapped null +#else + () // No tapper.SendTapped in MAUI +#endif member private __.AssignColorLabels (readOnly: bool) = let labels,color = @@ -506,23 +541,32 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState, self.BalanceRefreshCancelSources <- Seq.empty member private self.Init () = +#if XAMARIN if Device.RuntimePlatform = Device.GTK then // workaround layout issues in Xamarin.Forms/GTK mainLayout.RowDefinitions.[1] <- RowDefinition( Height = GridLength 550.0 ) +#endif normalChartView.DefaultImageSource <- FrontendHelpers.GetSizedImageSource "logo" 512 readonlyChartView.DefaultImageSource <- FrontendHelpers.GetSizedImageSource "logo" 512 let tapGestureRecognizer = TapGestureRecognizer() - tapGestureRecognizer.Tapped.Subscribe(fun _ -> + tapGestureRecognizer.Tapped.Add(fun _ -> Uri "http://www.geewallet.com" - |> Xamarin.Essentials.Launcher.OpenAsync + |> Launcher.OpenAsync |> FrontendHelpers.DoubleCheckCompletionNonGeneric - ) |> ignore + ) +// On Maui/GTK, adding gesture recognizer directly to label doesn't work, +// so we add it to encompassing frame as a workaround. +#if !XAMARIN + let footerLabelFrame = mainLayout.FindByName "footerLabelFrame" + footerLabelFrame.GestureRecognizers.Add tapGestureRecognizer +#else let footerLabel = mainLayout.FindByName