Skip to content

Commit

Permalink
XF.Android(Renderers): 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 da63ee1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/GWallet.Backend/FSharpUtil.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ module FSharpUtil =
let SPrintF5 (fmt: string) (a: Object) (b: Object) (c: Object) (d: Object) (e: Object) =
String.Format(ToStringFormat fmt, a, b, c, d, e)

let SPrintF6 (fmt: string) (a: Object) (b: Object) (c: Object) (d: Object) (e: Object) (f: Object) =
String.Format(ToStringFormat fmt, a, b, c, d, e, f)

module UwpHacks =
#if STRICTER_COMPILATION_BUT_WITH_REFLECTION_AT_RUNTIME
Expand All @@ -57,6 +59,8 @@ module FSharpUtil =
let SPrintF4 fmt a b c d = sprintf fmt a b c d

let SPrintF5 fmt a b c d e = sprintf fmt a b c d e

let SPrintF6 fmt a b c d e f = sprintf fmt a b c d e f
#else
let SPrintF1 (fmt: string) (a: Object) =
ReflectionlessPrint.SPrintF1 fmt a
Expand All @@ -72,6 +76,9 @@ module FSharpUtil =

let SPrintF5 (fmt: string) (a: Object) (b: Object) (c: Object) (d: Object) (e: Object) =
ReflectionlessPrint.SPrintF5 fmt a b c d e

let SPrintF6 (fmt: string) (a: Object) (b: Object) (c: Object) (d: Object) (e: Object) (f: Object) =
ReflectionlessPrint.SPrintF6 fmt a b c d e f
#endif


Expand Down
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 =
SPrintF6 " [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 da63ee1

Please sign in to comment.