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

Only render iOS preview component when opening the action menu #110

Open
Nico0302 opened this issue Feb 12, 2024 · 3 comments
Open

Only render iOS preview component when opening the action menu #110

Nico0302 opened this issue Feb 12, 2024 · 3 comments

Comments

@Nico0302
Copy link

Would it be possible to only render the preview component, when the user opens the action menu (the component becomes visible)?

I'm currently developing a notes like app, where I have a FlatList of ContextMenu items for each note item. When the user opens the context menu, he can view a preview of the note. This preview component is pretty expensive to render (richt text support, Latex, etc.).
Currently, all preview components get rendered simultaneously to the children of the ContextMenu.
A delayed render of the preview item would greatly improve performance for such a use case. An alternative would be to provide a callback prop which is called when the preview item gets rendered (e.g. onPreviewWillShow: (event) => void or onMenuWillShow).
Maybe there is also a workaround which would make it possible to check if the component is visible from inside the preview component, but I could not find a solution.

@mpiannucci
Copy link
Owner

mpiannucci commented Feb 12, 2024

can you show a screenshot or screen recording?

@peterjskaltsis
Copy link

peterjskaltsis commented Aug 25, 2024

Running into the same thing as well.

can you show a screenshot or screen recording?

@mpiannucci this is a breakdown of what I'm seeing:

TLDR: Putting a console.log inside the dropdown preview component shows console many console logs when rendering a ContextMenu as a list item.

Let's say we have a component TransactionView we want as the preview:

const TransactionView = () => {
   console.log("testing if this is rendered yet")
   return ....
}

We put it as the preview like so for TransactionListItem:

export const TransactionListItem = () => {
   return (
      <ContextMenu
         preview={
              <View style={{ height: 350 }}>
                <TransactionView id={transaction.id} />
              </View>
            }
        ....
      />
   )
}

Now when we use the TransactionListItem in eg a FlatList:

const Screen = () => {
   return (
      <FlatList renderItem={TransactionView} data=[...] />  
    )
}

We see the TransactionView rendered many times without actually opening the preview, like this:

 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
 LOG  testing if this is rendered yet
...

This will cause quite a lot of lag if the TransactionView is a heavy component.

Perhaps there's some way to lazy load the preview only on long press etc?

@peterjskaltsis
Copy link

A potential solution for this might be some sort of internal state management that listens for whether the menu is opened or not.

This could also enable other things like allowing users to change the appearance of the trigger when the menu is open.

Twitter/X UI has something like this which I don't believe this lib currently supports?

IMG_7126 IMG_7127
Closed Open

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

No branches or pull requests

3 participants