Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create onmounted Event #894

Merged
merged 15 commits into from
May 18, 2023
Merged

Create onmounted Event #894

merged 15 commits into from
May 18, 2023

Conversation

ealmloff
Copy link
Member

@ealmloff ealmloff commented Mar 19, 2023

resolves #631
resolves #517
resolves #804
resolves #423

Implements a new onmounted event with a trait object in the HTML crate. (More API discussion in #631)

The element allows:

  • The raw element type of the platform
  • The position of the element
  • Scrolling to the element
  • Focusing the element
    Each of these APIs are optional for the underlying renderer to implement.

Todo:

  • Create new event in html crate
  • Platform specific implementations
    • Web
    • Desktop
    • Liveview
    • TUI
  • Add example of onmounted event

@ealmloff ealmloff added the enhancement New feature or request label Mar 19, 2023
@ealmloff ealmloff added this to the 0.4 Release milestone Mar 23, 2023
@ealmloff ealmloff marked this pull request as ready for review March 24, 2023 16:37
@yusefnapora
Copy link

This looks so cool! I've been writing components that render svg shapes and have been using polling hacks to query JS for the the rendered size of the SVG element so I can calculate scaling factors, etc. Can't wait to toss that code out 😄 This seems like it will open up quite a few new possibilities.

@jkelleyrtp jkelleyrtp merged commit 379ea09 into DioxusLabs:master May 18, 2023
@jkelleyrtp
Copy link
Member

Awesome! Thank you! @Demonthos

@ealmloff ealmloff deleted the query-system branch May 18, 2023 12:30
@zoechi
Copy link
Contributor

zoechi commented May 18, 2023

A bit late, but should the event name not be onmount?
All event names in the browser are in this form onmousemove onmouseenter, onkeypress, ...
I'm not aware of one event name in past tense.

I'm curious is there also an onunmount event (planned)?

@ealmloff
Copy link
Member Author

ealmloff commented May 18, 2023

A bit late, but should the event name not be onmount? All event names in the browser are in this form onmousemove onmouseenter, onkeypress, ... I'm not aware of one event name in past tense.

Yes, onmount would be more consistant. If you want to, you can open a PR to change it

I'm curious is there also an onunmount event (planned)?

Effects also run after the component is first mounted, but they don't provide information about the element that was mounted. That is what the onmount event adds.

Hooks are dropped when the component is dropped. You can use them to run any of your cleanup logic. We could defiantly provide a hook that makes it easier to run a closure when the component is unmounted. We could have a onunmount event that runs directly before the element is unmounted, but I can't think of a use case that would use the element.

@zoechi
Copy link
Contributor

zoechi commented May 18, 2023

Hooks are dropped when the component is dropped.

Right, I remember seeing a comment in Discord where you mentioned that 🤦

I can't think of a use case that would use the element.

Right, the information I would be interested in is available in the components state anyway.

@ealmloff ealmloff mentioned this pull request Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants