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

lineHeight not distributed evenly in TextInput #39145

Open
tibbe opened this issue Aug 24, 2023 · 12 comments
Open

lineHeight not distributed evenly in TextInput #39145

tibbe opened this issue Aug 24, 2023 · 12 comments
Labels
Component: TextInput Related to the TextInput component. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Newer Patch Available

Comments

@tibbe
Copy link

tibbe commented Aug 24, 2023

Description

When you have a TextInput with lineHeight > fontSize the remaining space isn't distributed evenly around the text. For example:

<View style={styles.container}>
  <Text style={styles.text}>Text</Text>
  <TextInput style={styles.text} value="TextInput" />
</View>
const styles = StyleSheet.create({
  container: {
    alignItems: 'center',
    flexDirection: 'row',
    gap: 10,
  },
  text: {
    fontFamily: 'Inter-Regular',
    fontSize: 16,
    lineHeight: 26,
    letterSpacing: -0.01,
    color: '#111827',
    textAlignVertical: 'top',
    padding: 0,
    backgroundColor: 'pink',
  },
});

Result:
All the extra space in the TextInput case is on top of the text, making it hard to vertically align TextInputs (e.g. with a Text label preceding it on the same line).

both

React Native Version

0.71.7

Output of npx react-native info

System:
    OS: macOS 13.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 63.06 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: Not Found
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
    Watchman: 2023.07.03.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/tibbe/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.10121639
    Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.19 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.7 => 0.71.7 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

Use the above snippet in the iOS simulator.

Snack, screenshot, or link to a repository

https://snack.expo.dev/UEBid9Vxh

@github-actions
Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.71.13. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@github-actions github-actions bot added the Component: TextInput Related to the TextInput component. label Aug 24, 2023
@tibbe
Copy link
Author

tibbe commented Aug 24, 2023

This also applies to multiline, making it hard to add a Text label that stays aligned with the first line of text of the TextInput.

@tibbe
Copy link
Author

tibbe commented Aug 24, 2023

The best workaround I have so far is to not set lineHeight at all for single line TextInputs and use e.g. a surrounding View to try to align the Text and TextInput. That doesn't work with multiline however because there you want some amount of lineHeight. It's also a bit annoying in general because it means you have to define different styles for Text and TextInputs that only differ in lineHeight, which makes it harder to develop a consistent theme.

@tibbe
Copy link
Author

tibbe commented Aug 28, 2023

After some more testing it seems the issue is limited to iOS. Both web and Android look correct.

@tibbe
Copy link
Author

tibbe commented Sep 18, 2023

Any other information I can provide to clarify the issue?

@showtan001
Copy link

showtan001 commented Dec 28, 2023

So far unresolved! @shergin @mdvacca @sammy-SC @cortinico @RSNara @cortinico @yungsters @NickGerleman

Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 26, 2024
@tibbe
Copy link
Author

tibbe commented Jun 26, 2024

This is still an issue.

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 26, 2024
@TheAdamBorek
Copy link

I can also reproduce it. Problem affects only iOS and only <TextInput />. lineHeight is rendered fine for <Text />

https://snack.expo.dev/@adamfromattio/ios-problem-with-lineheight?platform=ios

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Needs: Triage 🔍 labels Jul 22, 2024
@itsramiel
Copy link

Just came across this. Thought maybe #46362 fixes it, but issue is still there.

Tested on 0.77.0-nightly-20241001-223e98cc4

Can be reproduced with:

import {StyleSheet, Text, TextInput, View} from 'react-native';

function App() {
  return (
    <View style={{justifyContent: 'center', flex: 1}}>
      <View style={styles.container}>
        <TextInput value="Type something" style={styles.text} />
      </View>
      <View style={styles.container}>
        <Text style={styles.text}>Type something</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'gray',
    padding: 16,
  },
  text: {
    backgroundColor: 'white',
    fontSize: 16,
    lineHeight: 1.52 * 16,
    color: 'black',
    padding: 0,
  },
});

export default App;
image

@jpope19
Copy link

jpope19 commented Oct 2, 2024

any update here? is this being worked on?

@mellyeliu
Copy link
Member

#46362 is gated right now for testing, we will open it up soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: TextInput Related to the TextInput component. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Newer Patch Available
Projects
None yet
Development

No branches or pull requests

7 participants