Skip to content

Text content area dims when formatter sheet is displayed. #238

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

Open
brendand opened this issue Apr 10, 2025 · 3 comments
Open

Text content area dims when formatter sheet is displayed. #238

brendand opened this issue Apr 10, 2025 · 3 comments

Comments

@brendand
Copy link

brendand commented Apr 10, 2025

Is there a way to prevent the text editor area from dimming when the formatting sheet is displayed on iOS? It's especially noticeable in dark mode. Note the difference in the yellow colour in the formatter vs. the yellow colour in the text above.

Image

This is what it should look like (when the formatter has been dismissed):

Image

@danielsaidi
Copy link
Owner

You should be able to use the presentation detents to achieve this, as described here:

https://danielsaidi.com/blog/2022/06/15/swiftui-4-custom-sheet-sizes

I actually thought that this was already being applied. Can you check if this is possible?

@brendand
Copy link
Author

It does look like RichTextKeyboardToolbar is using it:

private extension View {

    @ViewBuilder
    func prefersMediumSize() -> some View {
        #if macOS
        self
        #else
        if #available(iOS 16, *) {
            self.presentationDetents([.medium])
        } else {
            self
        }
        #endif
    }
}

But doesn't seem to be working for me.

I tried adding it myself:

RichTextKeyboardToolbar(
        context: context,
        leadingButtons: { $0 },
        trailingButtons: {_ in 
        Button {
              let defaultCenter = NotificationCenter.default
              defaultCenter.post(name: NSNotification.Name("ShowBarcodeScanner"), object: nil, userInfo: [:])
        } label: {
              Image(systemName: "qrcode")
                .contentShape(Rectangle())
                .imageScale(.large)

        }
        Button {
        if context.hasLink == true {
            let range = context.selectedRange
            let attributes = context.attributedString.attributes(at: range.location, effectiveRange: nil)
            let link = attributes[.link] as? URL ?? URL(filePath: "")
            linkURL = link.absoluteString
        } else {
            linkURL = context.selectedText ?? ""
         }
         self.showEditLinkAlert = true
         } label: {
              Image(systemName: "link.badge.plus")
               .contentShape(Rectangle())
               .imageScale(.large)

         }
                        
         },
             formatSheet: { $0 }
         )
        .presentationDetents([.medium])

But this didn't seem to work.

@brendand
Copy link
Author

I sort of got something working with this:

formatSheet: { $0
                        .presentationBackgroundInteraction(
                            .enabled(upThrough: .medium))
                        .task {
                            UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to:nil, from:nil, for:nil)
                        }
                    }

I noticed when I did that the keyboard wouldn't go away, so I had to add the task there to dismiss the keyboard when the sheet appeared.

But now when I do that, if I tap into the text area, it just brings the keyboard over top the sheet, but they kinda get merged together. It doesn't work well.

I tested with the RichTextKit demo app and it behaves the same.

iOS 18.4

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

2 participants