From 436165b1f4b8ffede016bcebbeb743b16c4f7bef Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 11 Aug 2023 14:49:05 +0800 Subject: [PATCH] XF.Android(Renderers): rather report warn, not crash Instead of crashing when we find an unexpected layout in this DatePicker hack, we report a Sentry warning; this way we mitigate this bug: https://gitlab.com/nodeffect/backlog/-/issues/47 --- .../Renderers/DatePickerYearFirstRenderer.fs | 65 ++++++++++++------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/src/GWallet.Frontend.XF.Android/Renderers/DatePickerYearFirstRenderer.fs b/src/GWallet.Frontend.XF.Android/Renderers/DatePickerYearFirstRenderer.fs index 078859a24..56810985b 100644 --- a/src/GWallet.Frontend.XF.Android/Renderers/DatePickerYearFirstRenderer.fs +++ b/src/GWallet.Frontend.XF.Android/Renderers/DatePickerYearFirstRenderer.fs @@ -2,9 +2,11 @@ namespace GWallet.Frontend.XF.Android open Android.Widget +open Xamarin.Essentials open Xamarin.Forms open Xamarin.Forms.Platform.Android +open GWallet.Backend open GWallet.Backend.FSharpUtil.UwpHacks // Custom renderer for Xamarin.Forms.DatePicker @@ -20,33 +22,50 @@ type DatePickerYearFirstRenderer (context) = // Android.Widget.DatePicker implementation // We navigate through multiple layers of child elements until we arrive // at the text element which displays the year and emit a click on it - let maybeLayoutA = dialog.DatePicker.GetChildAt 0 - match maybeLayoutA with - | :? LinearLayout as layoutA -> - let maybeLayoutB = layoutA.GetChildAt 0 - match maybeLayoutB with - | :? LinearLayout as layoutB -> - let maybeLayoutC = layoutB.GetChildAt 0 - match maybeLayoutC with - | :? LinearLayout as layoutC -> - let yearText = layoutC.GetChildAt 0 - yearText.PerformClick () |> ignore - dialog + let warningMsg = + let maybeLayoutA = dialog.DatePicker.GetChildAt 0 + match maybeLayoutA with + | :? LinearLayout as layoutA -> + let maybeLayoutB = layoutA.GetChildAt 0 + match maybeLayoutB with + | :? LinearLayout as layoutB -> + let maybeLayoutC = layoutB.GetChildAt 0 + match maybeLayoutC with + | :? LinearLayout as layoutC -> + let yearText = layoutC.GetChildAt 0 + yearText.PerformClick () |> ignore + None + | null -> + Some "Unexpected DatePicker layout when trying to find layoutC (got null)" + | _ -> + Some <| SPrintF1 "Unexpected DatePicker layout when trying to find layoutC (got %s)" + (maybeLayoutC.GetType().FullName) | null -> - failwith "Unexpected DatePicker layout when trying to find layoutC (got null)" + Some "Unexpected DatePicker layout when trying to find layoutB (got null)" | _ -> - failwith <| SPrintF1 "Unexpected DatePicker layout when trying to find layoutC (got %s)" - (maybeLayoutC.GetType().FullName) + Some <| SPrintF1 "Unexpected DatePicker layout when trying to find layoutB (got %s)" + (maybeLayoutB.GetType().FullName) | null -> - failwith "Unexpected DatePicker layout when trying to find layoutB (got null)" + Some <| "Unexpected DatePicker layout when trying to find layoutA (got null)" | _ -> - failwith <| SPrintF1 "Unexpected DatePicker layout when trying to find layoutB (got %s)" - (maybeLayoutB.GetType().FullName) - | null -> - failwith "Unexpected DatePicker layout when trying to find layoutA (got null)" - | _ -> - failwith <| SPrintF1 "Unexpected DatePicker layout when trying to find layoutA (got %s)" - (maybeLayoutA.GetType().FullName) + Some <| SPrintF1 "Unexpected DatePicker layout when trying to find layoutA (got %s)" + (maybeLayoutA.GetType().FullName) + + match warningMsg with + | Some msg -> + let devInfo = + sprintf " [DevInfo: (Type=%s, Idiom=%s, Platform=%s, Version=%s, Manufacturer=%s, Model=%s)]" + (DeviceInfo.DeviceType.ToString()) + (DeviceInfo.Idiom.ToString()) + (DeviceInfo.Platform.ToString()) + DeviceInfo.VersionString + DeviceInfo.Manufacturer + DeviceInfo.Model + + Infrastructure.ReportWarningMessage (msg + devInfo) |> ignore + | _ -> () + + dialog [, typeof)>]