Popover content jumps from the top-left corner on its first open (6.1.0+)
Bug Report
Since 6.1.0 the first time a Popover (and therefore Datepicker, Select, OverflowMenu, Tooltip) opens, its content is briefly drawn near the top-left corner of the window and then jumps next to the anchor. Every later open is fine.
The cause is the lazy mount added in 6.1.0 (ui/popover/popover.component.tsx, if (!everVisibleRef.current)):
- Until the popover has been visible once, the anchor is rendered without a
MeasureElement, sochildFrameis stillFrame.zero()when the popover opens. - The content is laid out and
onContentMeasurecomputes the placement against that zero anchor frame, so the content is positioned relative to (0, 0). - Only afterwards is the anchor measured (
forceMeasure),childFramechanges, and the content moves to the right place.
In addition, the anchor moves from View > anchor to View > MeasureElement > anchor on that first open, so the anchor element is remounted, which adds a flicker of its own.
To Reproduce
- Render a
Datepicker(or aPopoverwith a calendar as content) anywhere below the top of the screen. - Open it for the first time after the app starts.
- The calendar appears near the top-left corner for a frame and then jumps under the input.
Expected behavior
The content appears next to the anchor on the first open, without an intermediate position, and the anchor is not remounted.
A fix that works for us:
- keep wrapping the anchor in
MeasureElementeven while the popover has never been shown (only theModalstays lazy), so the anchor frame is known before the first open and the tree shape does not change; - in
onContentMeasure, do not place the content whilechildFrameis stillFrame.zero()(keep it off screen), remember the content frame, and re-run the placement fromonChildMeasurewhen the anchor frame arrives or changes.
UI Kitten and Eva version
| Package | Version |
|---|---|
| @ui-kitten/eva | 6.0.2 |
| @ui-kitten/components | 6.1.3 |
Environment information
React Native 0.86.3, React 19.2.3, Expo SDK 57, react-native-web 0.21.2. Reproduced on iOS, Android and web.
Source: akveo/react-native-ui-kitten