Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

[Architecture] Add lifecycle events to widget (mount, dismount, create, destroy) #25

Closed
Tracked by #23
TimLariviere opened this issue Dec 7, 2021 · 5 comments · Fixed by #135
Closed
Tracked by #23
Milestone

Comments

@TimLariviere
Copy link
Owner

No description provided.

@TimLariviere TimLariviere changed the title Add lifecycle events to widget (mount, dismount, create, destroy) [Architecture] Add lifecycle events to widget (mount, dismount, create, destroy) Dec 7, 2021
@TimLariviere TimLariviere added this to the v2 Release #1 milestone Dec 9, 2021
@SergejDK
Copy link

In which order should this happen?

Create -> Mount -> Dismount -> Destroy ?

@TimLariviere
Copy link
Owner Author

TimLariviere commented Dec 13, 2021

Yes. I think that's the good order.
Just after dismount, the widget can be re-mounted.

An example is ListView with virtualization

@SergejDK
Copy link

SergejDK commented Dec 13, 2021

Yes that sounds correct.
Do you have an idea or a preference how to act on them?

e.g. like a extensionmethod ?

StackLayout().onCreate(fun _ => printfn "OnCreate")

@twop
Copy link
Collaborator

twop commented Dec 13, 2021

I think instead of lambda we want it to accept a concrete message, or a function that creates a concrete message (in case we need to pass data in).

like so

StackLayout().onCreate(StackCreated)

// if we need to pass args
StackLayout().onCreate(fun args -> StackCreated args)

@TimLariviere
Copy link
Owner Author

TimLariviere commented Dec 13, 2021

@SergejDK Yes, an extension method is good. That lambda should return a 'msg type like @twop said.
I think we can start without parameters.

Contrary to what we do in v1 (create lets you access the XF control), I think we will only notify that the control has been created.
Then with ViewRef, developers will be able to access the XF control itself.

type Msg =
    | LabelCreated

let labelRef = ViewRef<_>()

let update msg model =
    match msg with
    | LabelCreated ->
        labelRef.Value.BackgroundColor <- Color.Blue

let view model =
    StackLayout() {
        Label("Text")
            .reference(labelRef)
            .onCreate(LabelCreated)
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants