Reputation: 1234
We have a view in which the users current location can be used.
We are doing the standard 'can we use your location' when the view is 1st shown (and the user hasn't previously said no). If user says yes then it looks up the current location and then shows this.
If user says no (or this isn't the 1st time) then the view stays on screen with the choice of either entering a location textually or pressing the 'use current location' button. Clearly if user has declined location previously we then prompt for permission again if they press the 'use current location' position.
We have this currently implemented through a 'prompt for permission' property on the View Model which the view then subscribes to. If the user says 'yes' we (the view) executes the 'userconfirmed' command in the view model otherwise we execute the 'userdeclined' command (in the view model).
Whilst this works, it just doesn't feel right. We've seen the UserError code and could potentially use this but it feels a bit strange using a mechanism potentially for errors to prompt the user for permission. Clearly this is a scenario which MVVM implementations have numerous different solutions but given the concise nature of ReactiveUI we expected a subtle solution.
Suggestions anyone?
Upvotes: 1
Views: 135
Reputation: 74654
The UserError framework would work well for this scenario, it's probably what I would do. The advantage of using UserError is that you can simulate all of the scenarios really easily (i.e. user declines first view, decides yes later; user clicks yes; etc etc).
Define a subclass of UserError (LocationPermissionError or something), then register a handler on your View that is only interested in LocationPermissionError.
Upvotes: 1