callstack / react-native-visionos

A framework for building native visionOS applications using React
https://callstack.github.io/react-native-visionos-docs/
MIT License
1.02k stars 30 forks source link

fix: allow to manually move dev menu to avoid conflicts #150

Closed okwasniewski closed 5 months ago

okwasniewski commented 5 months ago

Summary:

This PR allows users to move dev menu to avoid conflicts with their custom ornaments.

Changelog:

[VISIONOS] [ADDED] - allow to manually move dev menu to avoid conflicts

Test Plan:

Test if dev menu ornament can be moved

thymikee commented 5 months ago

cc @thiagobrez, would you be able to test it in your app?

thiagobrez commented 5 months ago

@thymikee I'm using a custom setup on my app with native TabViews, so I need to add the DevMenu myself, but it is not exported.

Already synced with @okwasniewski and he is aware, he will release a fix soon

var body: some Scene {
    WindowGroup {
      TabView {
        RCTRootViewRepresentable(moduleName: "visionary")
          .tabItem {
            Label("Home", systemImage: "house.fill")
          }
        RCTRootViewRepresentable(moduleName: "SettingsScreen")
          .tabItem {
            Label("Settings", systemImage: "gear")
          }
      }

      // Works great
      .ornament(attachmentAnchor: .scene(.bottom)) {
        VStack {
          Button("Hey!") {}
        }
        .glassBackgroundEffect()
      }

      // Error: Cannot find 'DevMenuView' in scope
      .toolbar {
        DevMenuView(placement: .bottomOrnament)
      }
    }
  }
okwasniewski commented 5 months ago

After checking @thiagobrez custom solution I took a different approach. Now the dev menu is attached to RCTRootViewRepresentable so even with something totally custom you will still get the dev menu ornament:

There is no need to add it manually now.

var body: some Scene {
    WindowGroup {
      TabView {
// Move dev menu ornament to the top
        RCTRootViewRepresentable(moduleName: "visionary", devMenuSceneAnchor: .top)
          .tabItem {
            Label("Home", systemImage: "house.fill")
          }
// Remove dev menu ornament from second window
        RCTRootViewRepresentable(moduleName: "SettingsScreen", devMenuSceneAnchor: nil)
          .tabItem {
            Label("Settings", systemImage: "gear")
          }
      }
      .ornament(attachmentAnchor: .scene(.bottom)) {
        VStack {
          Button("Hey!") {}
        }
        .glassBackgroundEffect()
      }
    }
  }

CleanShot 2024-06-24 at 11 44 26@2x