-
Notifications
You must be signed in to change notification settings - Fork 30
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
Initial width
and height
are inaccurate when manually setting .defaultSize
on RCTMainWindow
#112
Comments
Hey, Just checked it out on the latest version and it seems to work fine for me: @main
struct SnowEmitterAppApp: App {
@UIApplicationDelegateAdaptor var delegate: AppDelegate
var body: some Scene {
RCTMainWindow(moduleName: "SnowEmitterApp")
.defaultSize(CGSize(width: 500, height: 800))
}
} Then in JS: console.log('Dimensions: ', Dimensions.get('window')); // {"fontScale": 1, "height": 800, "scale": 2, "width": 500}
function App(): React.JSX.Element {
const dimensions = useWindowDimensions();
return (
<View style={styles.container}>
<Text style={styles.title}>
React native visionOS {dimensions.height} {dimensions.width}👋
</Text>
</View>
);
} |
I should have included this in the initial issue but it only seems to be an issue on the initial opening of the app. The way I'm able to reproduce on the simulator and on an actual AVP is to close the app while Metro is still running then click the Build button in XCode. I'm also logging out the values from the |
@billyjacoby Can you try running the app with new architecture enabled (Install pods with |
Running with new arch enabled does in fact seem to fix this 🙌🏼 |
Let's keep this issue open for now but our priority is new architecture (same as React Native's core team) |
Do you have any idea how to receive notifications about window dimensions updates? I've tried using The same goes for Thanks! |
Hey @jpudysz, React Native visionOS doesn't support it at the moment - I'm working on the implementation of this, together with a way of tracking each window state. Also, I think So the new APIs that are coming:
Currently, it is a bit unpredictable as useWindowDimensions returns the "last touched" window dimensions. Which version are you running that useWindowDimensions doesn't change? CleanShot.2024-04-16.at.09.16.17.mp4 |
I used the version from the docs, it's |
@okwasniewski thanks for your hints! I was able to implement it using I used RocketSim_Recording_Apple_Vision_Pro_-1.0_2024-04-16_10.20.39.mp4 |
Description
When setting a custom height and/or width on the
RCTMainWindow
, the values reported byuseWindowDimension
are incorrect until the window is either moved or resized.Steps to reproduce
.defaultSize(.init(width: 2000, height: 180))
onRCTMainWindow
useWindowDimensions
in the app file, and note the difference between the initially logged value and window sizeReact Native Version
0.73.4
Affected Platforms
Other (please specify)
Output of
npx react-native info
Reproducer
https://github.com/billyjacoby/callstack-visionos-repro/tree/window-size
Screenshots and Videos
I have very limited experience with the native library portion of React Native, but if someone wants to point me in the right direction I'm happy to try and fix this issue.
I assume the initial size just isn't being sent to the RN side of things for some reason.
The text was updated successfully, but these errors were encountered: