adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
586 stars 49 forks source link

How to navigate to another page when not on UI thread? #52

Closed phollyer closed 1 year ago

phollyer commented 1 year ago

I asked this on Microsoft Q&A because I thought it was more of a Maui issue but was re-directed here.

I'm building a mobile and desktop app with Maui + MauiReactor that communicates with my server over Websockets. I have this working fine.

My problem is that if I try to Navigate to another page when I receive a Websocket reply with await Navigation.pushAsync<NewPage>(); I get the following error:

UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

I understand why this happening, just not how best to handle it.

I can display a button after the message has been received, which the user can click to navigate which is obviously performing the navigaton on the UI thread due to the button click, but this feels really clunky. Is it possible to raise the process onto the UI thread so that I can programmatically navigate automatically?

My use case is as follows:

User starts the app, navigates to the sign in page, and enters credentials

Credentials get sent to my server over a websocket

Websocket reply confirms credentials and supplies a session token

Now I need to navigate to another page based on the current state of their profile settings i.e. if incomplete, go to profile page, if complete go back home. I would like this to be automatic without forcing the user to click a button to navigate.

adospace commented 1 year ago

replied on #53