Skip to content

Commit

Permalink
XF.Android(Renderers): rather report warn, not crash
Browse files Browse the repository at this point in the history
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
  • Loading branch information
knocte committed Aug 11, 2023
1 parent 3596eed commit 436165b
Showing 1 changed file with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<bool>
| _ -> ()

dialog


[<assembly:ExportRenderer(typeof<DatePicker>, typeof<DatePickerYearFirstRenderer>)>]
Expand Down

0 comments on commit 436165b

Please sign in to comment.