Getting Cursor Position of TextView in IOS


#1

Hello,

I am having a problem getting the current cursor position of a TextView element in iOS.

I have the following code:

const beginOfDoc = this.input.ios.beginningOfDocument;
const selectedRange = this.input.ios.selectedTextRange;

 // This errors
const cursorPos = this.input.ios.offset(beginOfDoc, selectedRange.start);

I have tried this as well:

const cursorPos = this.input.ios.offset({from: beginOfDoc, to: selectedRange.start});

but it errors all the same.

I am getting a problem though with the offset function. I got this far from this SO post: https://stackoverflow.com/questions/34922331/getting-and-setting-cursor-position-of-uitextfield-and-uitextview-in-swift

Has anyone tried to get and successfully got the cursor position in iOS?

Thank you in advance for any insights you may have.


#2

I figured it out with help of the tns-platform-declarations package.

const iosEle: UITextField = this.input.ios;
const beginOfDoc = iosEle.beginningOfDocument;
const selectedRange = iosEle.selectedTextRange;
const cursorPos = iosEle.offsetFromPositionToPosition(beginOfDoc, selectedRange.start);