Inconsistency in View Alignment within Text Component on Android/iOS Platforms
未关闭
还没有人认领这个 Issue。
Issue: Author Provided Repro
Needs: Triage :mag:
Newer Patch Available
Platform: Android
Platform: iOS
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Description
When wrapping View children in a Text component, the views are displayed inline with the text on web platforms. However, on Android and iOS platforms, adjusting the line height of the parent Text component causes the View children to no longer be inline with the text.
Steps to reproduce
- Create a parent Text component.
- Wrap View children within the Text component.
- Note how the views are inline with the text on web platforms.
- Adjust the line height of the parent Text component.
- Observe that the views are no longer inline with the text on Android and iOS platforms.
export default function App() {
return (
<SafeAreaView style={styles.container}>
<Text style={styles.text} >
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr
<View
style={{
borderRadius: 40,
height: 50,
paddingHorizontal: 32,
backgroundColor: 'yellow'
}}
>
<Text>Button Text</Text>
</View>
</Text>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
text: {
fontSize: 17,
lineHeight: 29
},
});
React Native Version
0.72.4
Affected Platforms
Runtime - Android, Runtime - iOS
Output of npx react-native info
System:
OS: macOS 14.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 32.88 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 21.6.1
path: /opt/homebrew/bin/node
Yarn:
version: 4.0.2
path: /opt/homebrew/bin/yarn
npm:
version: 9.9.2
path: ~/Documents/dev/finanztip/app-components/node_modules/.bin/npm
Watchman:
version: 2024.01.22.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK: Not Found
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11076708
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 11.0.17
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.4
wanted: 0.72.4
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
Stacktrace or Logs
none
Reproducer
https://snack.expo.dev/CABd_oOlH8QkEUCdWhRkL
Screenshots and Videos
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 Expo Snack 复现示例开始,在 Android、iOS 和 web 上比较指定 lineHeight 时 Text 和 View 的布局。在更改行为之前,确认平台特定的对齐差异,并确定相关的原生文本布局入口点;完成的标准是,换行后的 View 在受影响的平台上都能一致地保持 inline。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, ios, react-native
- 领域
- mobile
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100