SteffeyDev / react-native-popover-view

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

on android the popover is offset by a about 10 px more than intended #155

Closed dannyhw closed 1 year ago

dannyhw commented 1 year ago

Describe the bug

When rendering on android the arrow is offset by more than it should be

code:

    <View>
        <Popover
          from={
            <TouchableOpacity style={{ borderWidth: 1, borderColor: "red" }}>
              <Text>Press here to open popover!</Text>
            </TouchableOpacity>
          }
        >
          <Text>
            Officia aute magna velit veniam sunt nisi exercitation adipisicing
            pariatur. Irure amet id fugiat laborum culpa velit culpa commodo
            officia excepteur deserunt officia. Labore magna eiusmod laborum id
            pariatur reprehenderit adipisicing. Consectetur laboris nulla ex eu
            excepteur ut in sint consequat minim eu minim. Dolore tempor dolor
            proident aliqua. Enim do commodo quis nostrud ipsum commodo sit elit
            fugiat proident eu est. Fugiat esse mollit irure veniam dolore
            excepteur pariatur sint Lorem.
          </Text>
        </Popover>
      </View>
    ); 

Device/Setup Info:

Screenshots android:

image

web: (also not calculating the width properly)

image

ios:

image

seems like ios is working as intended.

Debug Output Pass the debug={true} prop into the Popover, and then paste the contents of the log here.

[2023-01-26T22:31:03.272Z] calculateRectFromRef - waiting for ref LOG [2023-01-26T22:31:03.273Z] calculateRectFromRef - waiting for ref to move from: {"x":0,"y":0,"width":0,"height":0} LOG [2023-01-26T22:31:03.396Z] calculateRectFromRef - calculated Rect: {"x":106.90908813476562,"y":372,"width":178.90908813476562,"height":21.090909957885742} LOG [2023-01-26T22:31:03.416Z] setDefaultDisplayArea - newDisplayArea: {"x":0,"y":-0.000055486505743829184,"width":392.7272644042969,"height":781.0908813476562} LOG [2023-01-26T22:31:03.416Z] setDefaultDisplayArea - displayAreaOffset: {"x":0,"y":0} LOG [2023-01-26T22:31:03.419Z] [BasePopover] componentDidUpdate - changedProps: ["displayArea"] LOG [2023-01-26T22:31:03.419Z] componentDidUpdate - isVisible not changed, handling other changes LOG [2023-01-26T22:31:03.420Z] handleChange - no requestedContentSize, exiting... LOG [2023-01-26T22:31:03.420Z] calculateRectFromRef - waiting for ref LOG [2023-01-26T22:31:03.420Z] calculateRectFromRef - waiting for ref to move from: {"x":106.90908813476562,"y":372,"width":178.90908813476562,"height":21.090909957885742} LOG [2023-01-26T22:31:03.447Z] measureContent - new requestedContentSize: {"width":3155.636474609375,"height":51.272727966308594} (used to be null) LOG [2023-01-26T22:31:03.449Z] handleChange - waiting 100ms to accumulate all changes LOG [2023-01-26T22:31:03.563Z] handleChange - requestedContentSize: {"width":3155.636474609375,"height":51.272727966308594} LOG [2023-01-26T22:31:03.563Z] handleChange - displayArea: {"x":0,"y":-0.000055486505743829184,"width":392.7272644042969,"height":781.0908813476562} LOG [2023-01-26T22:31:03.563Z] handleChange - fromRect: {"x":106.90908813476562,"y":372,"width":178.90908813476562,"height":21.090909957885742} LOG [2023-01-26T22:31:03.563Z] handleChange - placement: "auto" LOG [2023-01-26T22:31:03.564Z] computeAutoGeometry - displayArea: {"x":0,"y":-0.000055486505743829184,"width":392.7272644042969,"height":781.0908813476562} LOG [2023-01-26T22:31:03.564Z] computeAutoGeometry - fromRect: {"x":106.90908813476562,"y":372,"width":178.90908813476562,"height":21.090909957885742} LOG [2023-01-26T22:31:03.564Z] computeAutoGeometry - List of available space: {"left":{"sizeAvailable":90.90908813476562,"sizeRequested":3155.636474609375,"fits":false,"extraSpace":-3064.7273864746094},"right":{"sizeAvailable":90.90908813476562,"sizeRequested":3155.636474609375,"fits":false,"extraSpace":-3064.7273864746094},"top":{"sizeAvailable":356.00005548650574,"sizeRequested":51.272727966308594,"fits":true,"extraSpace":304.72732752019715},"bottom":{"sizeAvailable":371.99991590326476,"sizeRequested":51.272727966308594,"fits":true,"extraSpace":320.72718793695617}} LOG [2023-01-26T22:31:03.564Z] computeAutoGeometry - Found best postition for placement: "bottom" LOG [2023-01-26T22:31:03.565Z] computeGeometry - initial chosen geometry: {"popoverOrigin":{"x":10,"y":393.09090995788574},"anchorPoint":{"x":196.36363220214844,"y":393.09090995788574},"placement":"bottom","forcedContentSize":{"width":372.7272644042969,"height":377.99991590326476},"viewLargerThanDisplayArea":{"height":false,"width":true}} LOG [2023-01-26T22:31:03.565Z] computeGeometry - final chosen geometry: {"popoverOrigin":{"x":10,"y":393.09090995788574},"anchorPoint":{"x":196.36363220214844,"y":393.09090995788574},"placement":"bottom","forcedContentSize":{"width":372.7272644042969,"height":377.99991590326476},"viewLargerThanDisplayArea":{"height":false,"width":true}} LOG [2023-01-26T22:31:03.567Z] handleChange - delaying showing popover because viewLargerThanDisplayArea LOG [2023-01-26T22:31:03.596Z] measureContent - new requestedContentSize: {"width":372.7272644042969,"height":201.81817626953125} (used to be {"width":3155.636474609375,"height":51.272727966308594}) LOG [2023-01-26T22:31:03.598Z] handleChange - waiting 100ms to accumulate all changes LOG [2023-01-26T22:31:03.712Z] handleChange - requestedContentSize: {"width":372.7272644042969,"height":201.81817626953125} LOG [2023-01-26T22:31:03.713Z] handleChange - displayArea: {"x":0,"y":-0.000055486505743829184,"width":392.7272644042969,"height":781.0908813476562} LOG [2023-01-26T22:31:03.713Z] handleChange - fromRect: {"x":106.90908813476562,"y":372,"width":178.90908813476562,"height":21.090909957885742} LOG [2023-01-26T22:31:03.713Z] handleChange - placement: "auto" LOG [2023-01-26T22:31:03.713Z] computeAutoGeometry - Top/bottom tryping to keep same, geometry: {"popoverOrigin":{"x":10,"y":393.09090995788574},"anchorPoint":{"x":196.36363220214844,"y":393.09090995788574},"placement":"bottom","forcedContentSize":{"width":372.7272644042969,"height":377.99991590326476},"viewLargerThanDisplayArea":{"height":false,"width":false}} LOG [2023-01-26T22:31:03.713Z] computeGeometry - initial chosen geometry: {"popoverOrigin":{"x":10,"y":393.09090995788574},"anchorPoint":{"x":196.36363220214844,"y":393.09090995788574},"placement":"bottom","forcedContentSize":{"width":372.7272644042969,"height":377.99991590326476},"viewLargerThanDisplayArea":{"height":false,"width":false}} LOG [2023-01-26T22:31:03.713Z] computeGeometry - final chosen geometry: {"popoverOrigin":{"x":10,"y":393.09090995788574},"anchorPoint":{"x":196.36363220214844,"y":393.09090995788574},"placement":"bottom","forcedContentSize":{"width":372.7272644042969,"height":377.99991590326476},"viewLargerThanDisplayArea":{"height":false,"width":false}} LOG [2023-01-26T22:31:03.715Z] handleChange - animating in LOG [2023-01-26T22:31:03.716Z] getTranslateOrigin - popoverSize: {"width":372.7272644042969,"height":209.81817626953125} LOG [2023-01-26T22:31:03.716Z] getTranslateOrigin - anchorPoint: {"x":196.36363220214844,"y":393.09090995788574} LOG [2023-01-26T22:31:03.717Z] animateIn - translateStart: {"x":10,"y":1898.3636400049384} LOG [2023-01-26T22:31:03.717Z] animateIn - translatePoint: {"x":10,"y":393.09090995788574} LOG [2023-01-26T22:31:03.721Z] Setting up keyboard listeners LOG [2023-01-26T22:31:04.047Z] animateIn - onOpenComplete - Calculated Popover Rect: {"x":0,"y":-1602.1817626953125,"width":372.7272644042969,"height":201.81817626953125} LOG [2023-01-26T22:31:04.048Z] animateIn - onOpenComplete - Calculated Arrow Rect: {"x":178.5454559326172,"y":-1610.1817626953125,"width":17.81818199157715,"height":10.181818008422852}

SteffeyDev commented 1 year ago

Take a look at the verticalOffset prop on the readme. You may need to set that prop on Android to account for a strange behavior I have seen before as well.

dannyhw commented 1 year ago

@SteffeyDev Wow you're a lifesaver! thanks so much for the fast response. I guess I missed that note there, that works perfectly now.

I'll close this as solved!