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

Nested View and Text vertical alignment issue. #31955

Open
rayan1810 opened this issue Aug 4, 2021 · 12 comments
Open

Nested View and Text vertical alignment issue. #31955

rayan1810 opened this issue Aug 4, 2021 · 12 comments

Comments

@rayan1810
Copy link

Description

Nesting View inside Text adds lineHeight's marginBottom to View and when we add Text inside that View it doesn't gets aligned properly.

React Native version:

System:
OS: macOS 11.4
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 55.67 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.0 - /usr/local/bin/node
Yarn: 1.22.10 - ~/npm-global/bin/yarn
npm: 6.14.13 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: ~0.63.4 => 0.63.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

  1. Setup a CRNA or Expo app.
  2. Replace the code in App.js with -
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.outsideText}>
        Outside Text{" "}
        <View style={styles.insideView}>
          <Text>Inside Text</Text>
        </View>
      </Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
  outsideText: {
    backgroundColor: "#cecece",
  },
  insideView: {
    backgroundColor: "#fcc9",
  },
});
  1. Start your App on iOS or Android with yarn ios or yarn android.

Expected Results

The text should be in the same line aligned vertically. Like it looks when we run this example on the Web.

Snack, code example, screenshot, or link to a repository:

https://snack.expo.dev/gdbQbTirc
Screenshot 2021-08-05 at 1 40 11 AM

@brian-reed-software
Copy link

I think I solved this, May I have a Pull Authorization?

@fxhrgco
Copy link

fxhrgco commented Mar 7, 2022

Hi! I'm experimenting the same issue with the 0.65.1 RN version.

@brian-reed-software In which react native version it has been released?

Cheers,

@Syphonjr
Copy link

@fxhrgco Did you find any solution for this. I'm also experiencing the exact same problem.

@fxhrgco
Copy link

fxhrgco commented May 17, 2022

Hey @Syphonjr , I ended up using flex container with direction row and align-items center. But sadly it's still happening.

@fxhrgco
Copy link

fxhrgco commented May 17, 2022

I do not know it it has been solved in the last versions though. I still have the 0.65.1. Does anybody know?

@yannickpschroeder
Copy link

I have the same issue. Any solutions yet?

@mtzfactory
Copy link

I'm experiencing the same problem... Any solution?

@SupertigerDev
Copy link

why is this still not fixed :c this is a huge issue for people who want to make a markup lib that has mentions support

@SupertigerDev
Copy link

I kind of found a solution. Just use transform: [{translate: 10}] on the element you want to align. change that 10 to whatever

@nathantew14
Copy link

nathantew14 commented Mar 4, 2024

I kind of found a solution. Just use transform: [{translate: 10}] on the element you want to align. change that 10 to whatever

@SupertigerDev this still introduces some extra spacing on top which is evident in multiline text :(

@SupertigerDev
Copy link

Yea its not perfect. sucks how this issue is still not fixed.

@SupertigerDev
Copy link

aaagh can this be fixed already 😭 its so annoying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants