SteffeyDev / react-native-popover-view

A well-tested, adaptable, lightweight <Popover> component for react-native
MIT License
608 stars 90 forks source link

Significant Delay on Popover Opening #177

Closed wallzero closed 1 month ago

wallzero commented 2 months ago

Describe the bug There is quite a delay in the popover before opening. This delay is even seen in the ReadMe gif. Compare to react-native-paper's menu.

Device/Setup Info:

SunlightFR commented 1 month ago

Hi, any news? I have the same problem

AdamGerthel commented 1 month ago

There's a built-in delay of 100ms here: https://github.com/SteffeyDev/react-native-popover-view/blob/dc2986c4a58e985abc4ae6d467c8a69886e6799d/src/AdaptivePopover.tsx#L239

It looks like some sort of safeguarding but I'm not sure why it exists or why there's a need to always run that delay. My guess is that getRectForRef might return an incorrect value, and if so, it performs another 20 loops until it either gets the correct value, or times out and returns. There ought to be a way to not run the delay if the value is correct on the first loop.

Something like:

      if (count === 0 && !(rect.equals(initialRect) || rect.y < -1000 || rect.x < -1000)) {
        break;
      }

right before the delay. I did notice when doing this though, that calculateRectFromRef still takes 100+ ms to run the first time. Since I don't know what the delay is actually for, instead of removing it, it could be shortened to, say 25ms instead, with an increased nr of cycles:

      await new Promise(resolve => {
        setTimeout(resolve, 25);
      });
      // Timeout after 2 seconds
      if (count++ > 80) return;