GithubHelp home page GithubHelp logo

Add Shell component about mobileblazorbindings HOT 8 OPEN

dotnet avatar dotnet commented on May 22, 2024
Add Shell component

from mobileblazorbindings.

Comments (8)

Eilon avatar Eilon commented on May 22, 2024

Initial work done here: 14641a1

Blazor Native Xaminals sample started, with Shell, here: 18f510b

from mobileblazorbindings.

Dreamescaper avatar Dreamescaper commented on May 22, 2024

Thanks for a great work!

Is there any way I could currently set TabBarIsVisible property for Shell?

from mobileblazorbindings.

Eilon avatar Eilon commented on May 22, 2024

Hi @Dreamescaper thanks! It seems that TabBarIsVisible is an "attached property", meaning it isn't a direct property of Shell. I haven't figured out a good way to support attached properties directly in the Blazor markup.

Fortunately, in Mobile Blazor Bindings there's an "escape hatch" to get to the Xamarin.Forms controls via the NativeControl property, described in the docs here.

For example, in the Xaminals Shell sample's BearPage I changed the code to this:

@inject ShellNavigationManager NavigationManager

<ContentPage @ref="bearPage">
    <ScrollView>
        <StackLayout>
            @foreach (var animal in BearData.Bears)
            {
                <AnimalTemplate Animal="animal" OnClick="AnimalClicked"></AnimalTemplate>
            }
        </StackLayout>
    </ScrollView>
</ContentPage>

@code {
    Microsoft.MobileBlazorBindings.Elements.ContentPage bearPage;

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
        if (firstRender)
        {
            Xamarin.Forms.Shell.SetTabBarIsVisible(bearPage.NativeControl, false);
        }
    }

    async Task AnimalClicked(Animal animal)
    {
        await NavigationManager.NavigateToAsync($"/beardetails/{animal.Name}");
    }
}

On the first "render" of this page (think of that as the first time the Xamarin.Forms controls are made to show up), it takes a reference to the current ContentPage and calls SetTabBarIsVisible on it with false so that the tab bar is not visible on the BearsPage.

from mobileblazorbindings.

Eilon avatar Eilon commented on May 22, 2024

Oh, and yes, this is kind of cumbersome. I'll have to think about how to make this easier. Attached Properties are a very XAML-ish thing, and they do work well from regular C# (as they do in my example above), but they're not great in Blazor syntax.

from mobileblazorbindings.

Dreamescaper avatar Dreamescaper commented on May 22, 2024

@Eilon
What do you think about creating component ShellProperties with handler implementing INonPhysicalChild, which sets Shell attached properties for parent?
Something like that:

<ContentPage Title="Page Title">
    <ShellProperties NavBarIsVisible="false" 
                     TabBarIsVisible="false" />

    <StackLayout>
    ...
    </StackLayout>
</ContentPage>

(I would prefer it to be nested Shell type, so it would be <Shell.Properties />, but blazor does not support that dotnet/aspnetcore#20765)

from mobileblazorbindings.

Eilon avatar Eilon commented on May 22, 2024

That is a very interesting idea!!! That is a very clever way to simulate attached properties. Definitely worth exploration!

from mobileblazorbindings.

lachlanwgordon avatar lachlanwgordon commented on May 22, 2024

I like what I see here. If it works I'll copy it for FlexLayout.

from mobileblazorbindings.

Eilon avatar Eilon commented on May 22, 2024

The attached properties idea from @Dreamescaper is in!

Thank you: https://twitter.com/original_ejl/status/1334253894772244482

from mobileblazorbindings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.