transformOrigin produces incorrect results on android
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Description
Transforming a view with perspective and transformOrigin to achieve 3d-effects is working perfectly on iOS, but not on android.
This has probably something to do with the normalization of camera perspectives: https://github.com/facebook/react-native/blob/7b7c45030ba6ae196b89f0fb8615d184a261cd4a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java#L599
I would be very thankful for possible workarounds.
Steps to reproduce
- Create a RN App using cli or Expo
- Add a View which is transformed with origin and perspective
const {width, height} = Dimensions.get('window');
export default function App() {
return (
<View
style={{
width,
height,
backgroundColor: 'red',
transformOrigin: [0, height / 2, 0],
transform: [
{perspective: width},
{rotateY: '45deg'}],
}}>
<Text>test</Text>
</View>
);
}```
### React Native Version
0.77.0
### Affected Platforms
Runtime - Android
### Output of `npx react-native info`
```text
System:
OS: macOS 15.3
CPU: (14) arm64 Apple M3 Max
Memory: 101.89 MB / 36.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 21.4.0
path: ~/.nodenv/versions/21.4.0/bin/node
Yarn:
version: 1.22.21
path: ~/.nodenv/versions/21.4.0/bin/yarn
npm:
version: 10.2.4
path: ~/.nodenv/versions/21.4.0/bin/npm
Watchman:
version: 2024.12.02.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK:
API Levels:
- "31"
- "33"
- "34"
- "35"
Build Tools:
- 30.0.3
- 31.0.0
- 33.0.0
- 33.0.1
- 34.0.0
- 35.0.0
System Images:
- android-34 | Google APIs ARM 64 v8a
- android-34 | Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23726.103.2422.12816248
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.10
path: /Users/take/.sdkman/candidates/java/current/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 15.0.1
wanted: 15.0.1
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.77.0
wanted: 0.77.0
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: false
Stacktrace or Logs
no stacktrace
Reproducer
https://snack.expo.dev/TUuheLubQqqLvtaHBxTR8
Screenshots and Videos
iOS: android:
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 React Native 0.77.0,通过链接的 Expo Snack 重现 Android 和 iOS 之间的差异。首先检查 ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java 第 599 行附近的位置,这里疑似存在 perspective 规范化处理。比较各平台上的变换行为;当 transformOrigin 和 perspective 在 Android 上产生匹配的 3D 结果时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, javascript, react-native
- 领域
- mobile
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100