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

Automatic arrow direction #31

Open
lucasfeijo opened this issue Jan 22, 2024 · 1 comment
Open

Automatic arrow direction #31

lucasfeijo opened this issue Jan 22, 2024 · 1 comment

Comments

@lucasfeijo
Copy link

There should be an automatic arrow direction option, because we might not know where the popover fits best.
If you try to display it too close to the edge of the screen the popover renders truncated:

image
@lucasfeijo
Copy link
Author

lucasfeijo commented Jan 23, 2024

My current solution is to add this to the button from where you're launching the popover:

  @State private var buttonRect: CGRect = .zero

  var pickerDirection: MCPickerArrowDirection {
    if buttonRect.minY < 300 {
      return .up
    } else {
      return .down
    }
  }

Either use a Geometry Reader on the background of the button, or a helper method like I do:

      .onRectChange {
        buttonRect = $0
      }
      .emojiPicker(isPresented: $isShowingEmojiPicker,
                   selectedEmoji: $selectedEmoji,
                   arrowDirection: pickerDirection)

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

1 participant