adospace / reactorui-maui

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

Unable to use the StatusBarBehavior? #207

Closed cris-m closed 7 months ago

cris-m commented 7 months ago

Is there a possibility to use StatusBarBehavior set the color and theme of the status bar? I tried the following and I am getting an exception.

[Scaffold(typeof(CommunityToolkit.Maui.Behaviors.StatusBarBehavior))]
partial class StatusBarBehavior { }
   public override VisualNode Render()
    =>  new ContentPage()
        {
            new  StatusBarBehavior()
                .StatusBarColor(Colors.Red)
                .StatusBarStyle(StatusBarStyle.LightContent),
        };
adospace commented 7 months ago

Which exception? are you updated with MauiReactor?

cris-m commented 7 months ago
System.NotImplementedException: Either set MainPage or override CreateWindow.
at Microsoft.Maui.Controls.Application.CreateWindow(IActivationState activationState)
at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.CreateWindow(IActivationState activationState)
at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states)
at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions)
adospace commented 7 months ago

That exception is thrown when MauiReactor encounters an error in rendering a component and can be caused by something else. Please provide a small app reproducing the issue so I can look into it.

FYI Trackizer app uses StatusBarBehavior as well, maybe you can take a look: https://github.com/adospace/mauireactor-samples/tree/main/TrackizerApp

Also, you can attach a callback to MauiReactor that is called when the exception is raised let you know exactly where it happened:

var builder = MauiApp.CreateBuilder();
...
builder.OnMauiReactorUnhandledException(ex => ....)
cris-m commented 7 months ago

I have checked how it implemented in TrackizerApp. it execute well in Android. The error is thrown when using iOS. I have to add a condition to exclude iOS.

public override VisualNode Render()
    =>  new ContentPage([
          #if !IOS
            new StatusBarBehavior()
                .StatusBarColor(_statusBarColor)
                .StatusBarStyle(Themes.IsDarkTheme ? StatusBarStyle.LightContent : StatusBarStyle.DarkContent)
        #endif
        ]);

Is the iOS issue related to reactorui-maui or dotnet MAUI?

adospace commented 7 months ago

hum, ok not sure why is not working on ios, probably I found it not working on ios and I've removed it, will look into it.

For the future please provide your environment ios/android etc as I usually use VisualStudio under windows with Android emulator.

let's keep the issue open for now

adospace commented 7 months ago

just found https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/statusbar-behavior?tabs=ios

you have to set this under ios

<key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>

let me know if it works

cris-m commented 7 months ago

I am still getting an exception.

at CommunityToolkit.Maui.Core.Platform.StatusBar.UpdateStatusBarAppearance(UIWindow window)\n   at CommunityToolkit.Maui.Core.Platform.StatusBar.PlatformSetColor(Color color)\n   at CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color color)
adospace commented 7 months ago

ok, much probably this is why I've removed the ios target in Trackizer, I guess it's something related to the CommunityToolkit then

cris-m commented 7 months ago

Okay. I will close the issue.