Skyscanner / SkyFloatingLabelTextField

A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.
Apache License 2.0
4.09k stars 540 forks source link

Text's end is hidden when it get the field's width limit #256

Open felipesantanadev opened 5 years ago

felipesantanadev commented 5 years ago

When I'm typing the text on the field and it get at the end of the field, the string keeps increasing, but visually the text is hidden.

If I press the left arrow on the keyboard (<-) to back positions on the text, the hidden piece of string is shown.

I have already tested in a real device and I'm getting the same error.

I expect that the text become visible while we are typing, even if the field's width be overflown.

This image represents the moment that I was typing without stopping. captura de tela 2018-11-22 as 20 17 45

And this image represents when I stop typing and press the left arrow key (<-).

captura de tela 2018-11-22 as 20 18 22

Environment

Xcode Version: 9.4 SkyFloatingLabelTextField Version: 3.6 Deployment Target: iPhone 6 and iPhone 8 Method of Integration: CocoaPods

felipesantanadev commented 5 years ago

I think that is not the better solution, but I solved the problem by creating the following function:

func putCaretAtTheEnd()
    {
        if(selectedTextRange?.end == endOfDocument)
        {
            let arbitraryValue: Int = text!.count - 1
            if let newPosition = position(from: beginningOfDocument, offset: arbitraryValue) {
                selectedTextRange = textRange(from: newPosition, to: newPosition)
                textAlignment = .left
            }

            let arbitraryValue2: Int = text!.count
            if let newPosition2 = position(from: beginningOfDocument, offset: arbitraryValue2) {
                selectedTextRange = textRange(from: newPosition2, to: newPosition2)
                textAlignment = .left
            }
        }
    }

It's called inside the editingChanged() in SkyFloatingTextField.swift:

@objc open func editingChanged() {
        updateControl(true)
        updateTitleLabel(true)
        putCaretAtTheEnd()
    }
antonyjamese commented 5 years ago

Hi, The function is working fine. But still a char is visible partially.

Davtyanag commented 5 years ago

This happens if height of SkyFloatingLabelTextField is too small. Setting 50.0 as height resolves this issue.