reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Add on_view functions to Base Event Triggers (Intersection Observer)

Open Cheesy-Brik opened this issue 1 year ago β€’ 4 comments

on_view would be called when the element is rendered on screen. on_load would be called when the window is initially loaded/reloaded.

Cheesy-Brik avatar Feb 06 '23 05:02 Cheesy-Brik

We already had an on_load event trigger, you can use it like app.add_page(my_page, '/my_route', on_load=MyState.fetch_data)

FHU-yezi avatar Feb 06 '23 06:02 FHU-yezi

We already had an on_load event trigger, you can use it like app.add_page(my_page, '/my_route', on_load=MyState.fetch_data)

Alright then, an on_element basis would (imo) fit more the current architecture, but that works,

But I feel the on_view idea still stands.

Cheesy-Brik avatar Feb 06 '23 06:02 Cheesy-Brik

I'd like to chime in an on_focus would also be nice to refresh background tasks when they're complete after a tab or window switch for example. Not really an issue on desktop, but for mobile it would be nice.

thavocado avatar Feb 06 '23 09:02 thavocado

on_view should be fairly simple to implement using the Intersection Observer API, which is now supported in all major browsers.

@advo-kat I created a separate issue for your request, you can track as #1314

masenf avatar Jul 06 '23 23:07 masenf

there's a third-party library by @masenf that supports this https://github.com/masenf/reflex-intersection-observer. Will go ahead and close this issue for now

ElijahAhianyo avatar Mar 26 '24 14:03 ElijahAhianyo