Sharpnado.Shadows icon indicating copy to clipboard operation
Sharpnado.Shadows copied to clipboard

How can I hide Shadows depending on platform?

Open Symxn opened this issue 4 years ago • 4 comments

Hello!

Your shadow library is really great! It works perfectly and I'm glad to finally have found someone who has managed to correctly display shadows easily on both Android and iOS.

But I have a suggestion. That is, could you add a property that indicates whether the shadow will be displayed? In some cases, I would like to display or render the shadow only on Android and not on iOS.

So that you can achieve something like this:

    <sh:Shadows CornerRadius="12">
        <sh:Shadows.Shades>
            <sh:ImmutableShades>
                <sh:Shade BlurRadius="12"
                          Opacity="0.3"
                          Offset="0,10"
                          Color="Black" />
            </sh:ImmutableShades>
        </sh:Shadows.Shades>

        <sh:Shadows.IsShown>
            <OnPlatform Android="True"
                        iOS="False"></OnPlatform>
        </sh:Shadows.IsShown>

        <ContentView Content="Some content."></ContentView>
    </sh:Shadows>

Of course I could set Opacity or all values to 0. But that would be unnecessary computing, since the shadow would still be rendered. Would you be able to do this or is it too complex?

Thanks! :)

Symxn avatar Jun 11 '20 15:06 Symxn

hey! I think it could be solved using OnPlatform and multiple type arguments according to ms docs: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/generics#multiple-type-arguments

But I have a compile error doing so... You can follow the twitter thread :)

https://twitter.com/Piskariov/status/1271376529612845056

roubachof avatar Jun 12 '20 09:06 roubachof

Ok so in fact it's working perfectly, this was just a resharper xaml error... Here is what you can do, I just tested it:

<sh:Shadows.Shades>
    <OnPlatform x:TypeArguments="gen:IEnumerable(sh:Shade)">
        <On Platform="Android">
            <sh:ImmutableShades>
                <sh:Shade BlurRadius="10"
                          Opacity="0.5"
                          Offset="8,8"
                          Color="Yellow" />
                <sh:Shade BlurRadius="10"
                          Opacity="0.5"
                          Offset="-8,-6"
                          Color="Violet" />
            </sh:ImmutableShades>
        </On>
        <On Platform="iOS">
            <sh:ImmutableShades />
        </On>
    </OnPlatform>
</sh:Shadows.Shades>

roubachof avatar Jun 12 '20 14:06 roubachof

Thank you! ;)

Symxn avatar Jun 14 '20 20:06 Symxn

Will keep that opened since it could be useful for the others users.

roubachof avatar Jun 20 '20 14:06 roubachof