Skip to content
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

TextInput Alignment does not work on iOS 11 #16341

Closed
n-kumari opened this issue Oct 12, 2017 · 6 comments
Closed

TextInput Alignment does not work on iOS 11 #16341

n-kumari opened this issue Oct 12, 2017 · 6 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@n-kumari
Copy link

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 7.7.2
Yarn: Not Found
npm: 5.4.2
Watchman: 4.7.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: Not Found

Packages: (wanted => installed)
react-native: 0.49.3 => 0.49.3
react: 16.0.0-alpha.12 => 16.0.0-alpha.12

Steps to Reproduce

  1. Create a TextInput and few buttons. Set the alignment dynamically as you press buttons using textAlign.
<View style ={{marginTop: 42}}>
            <Button
            onPress={ this.setStateLeft }
            title="Left"
            color="#841584"
            />
            <Button
            onPress={ this.setStateCenter }
            title="Center"
            color="#841584"
            />
            <Button
            onPress={ this.setStateRight }
            title="Right"
            color="#841584"
            />
            <TextInput
                style={{height: 40, borderColor: 'gray', borderWidth: 1, marginTop: 112, textAlign: this.state.alignText}}
                onChangeText={(text) => this.setState({text})}
                value={this.state.text}
            />
</View>
  1. Press the buttons

Expected Behavior

The alignment should work on iOS devices, irrespective of versions.

Actual Behavior

The alignment works as expected on iOS 10, but not on iOS 11 as seen below. The simulator on the left is iOS 11 and on right is iOS 10.

align_demo

Reproducible Demo

https://snack.expo.io/rkX3DXphb

@n-kumari n-kumari changed the title TextInput Alignment does not work on iOS11 TextInput Alignment does not work on iOS 11 Oct 12, 2017
@gusgard
Copy link
Contributor

gusgard commented Oct 12, 2017

Could you try this.state = { text: 'Alignment', alignText: 'right'}; in the constructor ?

@n-kumari
Copy link
Author

n-kumari commented Oct 12, 2017

In the constructor we are just setting the initial state. All that this.state = { text: 'Alignment', alignText: 'right'}; does is setting the initial alignment of the text to the right. It makes no difference to the issue.

@gusgard
Copy link
Contributor

gusgard commented Oct 13, 2017

The TextInput is re-rendered when the value changes, not when the style. In your example if you focus on the TextInput or change to this value={this.state.alignText}, it works.

@n-kumari
Copy link
Author

@gusgard Thank you for your input. I understand that the TextInput is re-rendered when the value changes, not when the style.

The issue I am talking about here is that re-rendering is not required on iOS 10. In the gif above, as shown, with the same code, it works as expected on iOS 10 (right simulator) but not on iOS 11 (left simulator).

@fmanns
Copy link
Contributor

fmanns commented Oct 20, 2017

This appears to be an IOS 11 bug. I was able to reproduce it in a simple standalone app.

class ViewController: UIViewController {

    @IBOutlet weak var alignmentSelector: UISegmentedControl!
    @IBOutlet weak var alignedTextField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        alignmentSelector.addTarget(self, action: #selector(alignmentSelected), for: .valueChanged)
    }
    
    @objc func alignmentSelected() {
        switch alignmentSelector.selectedSegmentIndex {
        case 0:
            alignedTextField.textAlignment = .left
        case 1:
            alignedTextField.textAlignment = .center
        default:
            alignedTextField.textAlignment = .right
        }
    }
    
}

@stale
Copy link

stale bot commented Dec 19, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 19, 2017
@stale stale bot closed this as completed Dec 26, 2017
@facebook facebook locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants