question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TextInput Alignment does not work on iOS 11

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fmannscommented, 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
        }
    }
    
}
0reactions
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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

text input alignment wrong on mobile devices (possibly only ...
I got 2 forms at my webpage and they are wrongly aligned on iOS devices (iPhone, iPad Safari).
Read more >
text alignment in SwiftUI | Apple Developer Forums
I would like to center align the text inside a TextField. I just couldn't find a way to do it. I know in...
Read more >
align-content - CSS: Cascading Style Sheets - MDN Web Docs
The CSS align-content property sets the distribution of space between and around content items along a flexbox's cross-axis or a grid's ...
Read more >
Input - Lightning Design System
You can style the HTML <input> element to align with the Salesforce brand by using the ... not an anchor <a> , in...
Read more >
TextInput - React Native
This may cause issues with components that have position: 'absolute' while the keyboard is active. To avoid this behavior either specify ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found