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.

Configure flip modifier to avoid restoring original placement after update

See original GitHub issue

In this example, we are using Popper with a preferred placement of top-start along with the flip modifier.

When the popper originally mounts, it shows a loading spinner. The flip modifier comes into action and correctly overrides the preferred placement so that the popper doesn’t overflow.

When the content finishes loading, the popper size changes. We are calling update any time the size changes via a ResizeObserver. This time, the popper is smaller in height so it doesn’t need to be flipped.

https://user-images.githubusercontent.com/921609/142389942-5a18b92c-1af9-4836-a79a-299bbe32e659.mov

This results in a fairly jarrying user experience—especially if the content loads quickly meaning the load state will appear as a flash.

I think the ideal user experience would be to preserve the placement that was originally applied by the flip modifier after we call update, rather than reverting to the preferred placement. We should only revert to the preferred placement if we need to, so the popper position doesn’t change.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
atomikscommented, Nov 18, 2021

we don’t have the information to make an informed decision on whether or not to preserve the flipped position. I don’t think it’s as simple as “always preserve the flipped position” because we need to consider that the “flipped position” may no longer be valid, e.g. it now overflows.

If you set the placement to the flipped one on the update, it’s still fine because it will know to flip again to the opposite placement, which was previously the original one

1reaction
FezVrastacommented, Nov 18, 2021

Ok I see, it makes sense. I think you can achieve that by setting the placement to the result of the previous flip result right now, but an option would be a nice idea.

Something like this:

const lazyFlip = {
  name: 'lazyFlip',
  enabled: true,
  requires: ['flip'],
  fn: ({ state }) => {
    instance.setOptions(opts => ({ ...opts, placement: state.placement }));
  }
}

const i = createPopper(a, b, {
  modifiers: [lazyFlip]
});

// [...]

i.update();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Flip | Popper
Flip. The flip modifier can change the placement of a popper when it's scheduled to overflow a given boundary. Don't mind tech-related ads?...
Read more >
Change the behavior of the modifier keys on Mac
On your Mac, change the action that modifier keys, such as Control or Option, ... To return the keys to their original settings,...
Read more >
Jetpack Compose saving state on orientation change
There is another approach to handle config changes in Compose, it is rememberSaveable . As docs says: While remember helps you retain state ......
Read more >
lStewieAl's Tweaks and Engine Fixes at Fallout New Vegas
Engine bugfixes, optional tweaks and new features with no performance impact. Fully customisable via in-game menu and INIs.
Read more >
Compose Foundation - Android Developers
The crash with Modifier.animateItemPlacement() and Lazy grids was fixed. It was happening in some conditions when the new items count is smaller then...
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