izyumkin / MCEmojiPicker

👻 EmojiPicker. Emoji picker for iOS like on macOS. With SwiftUI support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatic arrow direction

lucasfeijo opened this issue · comments

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

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)