Open billyjacoby opened 4 months ago
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 useWindowDimensions
hook specifically, I don't think that should make a difference though.
@billyjacoby Can you try running the app with new architecture enabled (Install pods with RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
and see if that fixes the issue?
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)
@okwasniewski
Do you have any idea how to receive notifications about window dimensions updates?
I've tried using NSKeyValueObserver
with other hacks, but with no luck. Does visionOS
even support it?
The same goes for useWindowDimensions
- it always returns the same size.
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 useWindowDimensions
should accept windowId
(with default to the main window).
So the new APIs that are coming:
WindowManager.addEventListener('change', () => {})
// Listen to each window state changesCurrently, it is a bit unpredictable as useWindowDimensions returns the "last touched" window dimensions. Which version are you running that useWindowDimensions doesn't change?
I used the version from the docs, it's0.73.10
.
@okwasniewski thanks for your hints! I was able to implement it using UnistylesRuntime
!
I will return in the future to support multiple windows; as of now, I support only one.
I used RCTWindowFrameDidChangeNotification
exposed by RCTReactViewController.m
.
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.