question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flyout component support

See original GitHub issue

According to docs (https://docs.avaloniaui.net/docs/controls/flyouts) Avalonia has Flyout components, but in Avalonia.FuncUI no implementation for that component, so I tried to add it by myself and I’ve got a problem that I’m stuck with.

I’ve implemented basic frame for new component:

namespace Avalonia.FuncUI.DSL

[<AutoOpen>]
module Flyout =
    open Avalonia.Controls
    open Avalonia.FuncUI.Types
    open Avalonia.FuncUI.Builder
    open Avalonia.Controls.Primitives
    
    let create (attrs: IAttr<Flyout> list): IView<Flyout> =
        ViewBuilder.Create<Flyout>(attrs)

    type FlyoutBase with

        /// <summary>
        /// A value indicating whether the flyout is visible.
        /// </summary>
        static member isOpen<'t when 't :> FlyoutBase>(value: bool) : IAttr<'t> =
            AttrBuilder<'t>.CreateProperty<bool>(FlyoutBase.IsOpenProperty, value, ValueNone)
            
        /// <summary>
        /// A value indicating how the flyout is positioned.
        /// </summary>
        static member placement<'t when 't :> FlyoutBase>(value: FlyoutPlacementMode) : IAttr<'t> =
            AttrBuilder<'t>.CreateProperty<FlyoutPlacementMode>(Flyout.PlacementProperty, value, ValueNone)
            
        /// <summary>
        /// A value indicating flyout show mode.
        /// </summary>
        static member showMode<'t when 't :> FlyoutBase>(value: FlyoutShowMode) : IAttr<'t> =
            AttrBuilder<'t>.CreateProperty<FlyoutShowMode>(Flyout.ShowModeProperty, value, ValueNone)
            
    type Flyout with

        static member content<'t when 't :> Flyout>(value: IView option) : IAttr<'t> =
            AttrBuilder<'t>.CreateContentSingle(Flyout.ContentProperty, value)

        static member content<'t when 't :> Flyout>(value: IView) : IAttr<'t> =
            value
            |> Some
            |> Flyout.content
            
    type Button with
    
        /// <summary>
        /// A value for flyout view placement for button.
        /// </summary>
        static member flyout<'t when 't :> Button>(value: IView option) : IAttr<'t> =
            AttrBuilder<'t>.CreateContentSingle(Button.FlyoutProperty, value)
    
        /// <summary>
        /// A value for flyout view placement for button.
        /// </summary>
        static member flyout<'t when 't :> Button>(value: IView) : IAttr<'t> =
            value
            |> Some
            |> Button.flyout

And when I’m trying to use it:

Button.create [
    Button.content "Hello there"
    Button.flyout (
        Flyout.create [
            Flyout.isOpen true
            Flyout.content (
                TextBox.create [
                    TextBox.text "Hello there"
                ]
            )
        ]
    )
]

I’ve got an error:

System.InvalidCastException: Unable to cast object of type 'Avalonia.Controls.Flyout' to type 'Avalonia.Controls.IControl'.
   at Avalonia.FuncUI.VirtualDom.Patcher.create(ViewDelta viewElement)
   at Avalonia.FuncUI.VirtualDom.Patcher.patch_avalonia@165(IControl view, FSharpOption`1 viewElement, AvaloniaProperty property)
   at Avalonia.FuncUI.VirtualDom.Patcher.patchContentSingle(IControl view, Accessor accessor, FSharpOption`1 viewElement)
   ...

Library can’t render Button.flyout because Flyout class doesn’t implement IControl interface (reference).

For now I don’t see any possible workarounds to use this control with FuncUI library, also IControl interface has many references in core of FuncUI library, so I don’t see any quick fixes for that. Any thoughts?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sleepyfrancommented, Nov 2, 2022

@picolino just had time to try this out: are you in the latest master? I just copy-pasted your code and it’s working. The only thing I removed is the isOpen property, since it’s not settable and it errors; other than that the flyout appears when clicking the button. I modified the inline example and it works: image

Feel free to create a PR with your changes if you manage to make it work, otherwise I’ll try to open a PR whenever I get some time 😃

0reactions
sleepyfrancommented, Nov 3, 2022

Closed in #229.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flyout
Property Required Type Default animationDuration no Number 200 animationEasing no String cubic‑bezier(0.25, 0.46, 0.45, 0.94) bodyClassName no String
Read more >
Flyout - Helios Design System
The body of the Flyout supports any custom content, local components, or Helios components via an instance swap property (customInstance) in Figma.
Read more >
Flyout - Components - Mosaic Design System
A Flyout component is a way of presenting a navigable menu hierarchy. When menu items are selected that have submenus, it displays the...
Read more >
Flyout | Block Editor Handbook
Flyout is a component to render a floating content modal. It is similar in purpose to a tooltip, but renders content of any...
Read more >
Components Flyout Menu | Figma Community
Figma Community plugin - Browse and insert local and team components via a flyout menu. Familiar workflow to Sketch users. Features • Browse...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found