UITextView giving wrong UITextPosition with closestPosition on iOS 17 with custom arabic font

Hi,

I have used some custom Arabic fonts in UITextView to render some Arabic fonts. On iOS 17 the following code is not giving me the correct position of the tapped text in some special cases.

Following the code i am using with the TapGestureRecognizer.

@objc func arabicTextViewTapped(_ sender: UITapGestureRecognizer) {
        
        let attributedString = NSMutableAttributedString(attributedString: arabicTextView.attributedText)
        attributedString.removeAttribute(.backgroundColor, range: NSRange(location: 0, length: attributedString.length))

        let touchPosition = sender.location(in: sender.view)
        guard let textPosition = arabicTextView.closestPosition(to: touchPosition),
              let textRange = arabicTextView.tokenizer
            .rangeEnclosingPosition(textPosition, with: .word, inDirection: .init(rawValue: 1)) else { return }
        
        guard let text = arabicTextView.text(in: textRange) else { return }
}

In the image below

if there is some special character (called Ramos e aukaf) as the first character (which in this case is the small first character on the second line) then this code gives the position on the first line.

 guard let textPosition = arabicTextView.closestPosition(to: touchPosition)

In the below case, the above code works perfectly fine as small character is not the first character on the second line. Also this is only happening on ios 17.

Any help is highly appriciated.