Skip to content
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

unwrap PopoverContent on macOS #239

Merged
merged 1 commit into from
May 2, 2023
Merged

Conversation

mayoff
Copy link

@mayoff mayoff commented Apr 11, 2023

On macOS, a popover is displayed in its own NSWindow, and the contentView of that window is an NSHostingView. The hosted SwiftUI View structure looks like this:

ModifiedContent<AnyView, PopoverRootModifier>
  AnyView
    PopoverContent<ModifiedContent<ModifiedContent<ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>, _EnvironmentKeyWritingModifier<NavigationEnabled>>, _EnvironmentKeyWritingModifier<Optional<NavigationState>>>>
      ModifiedContent<ModifiedContent<ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>, _EnvironmentKeyWritingModifier<NavigationEnabled>>, _EnvironmentKeyWritingModifier<Optional<NavigationState>>>
        ModifiedContent<ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>, _EnvironmentKeyWritingModifier<NavigationEnabled>>
          ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>
            YourPopoverContent

This commit allows ViewInspector to unwrap PopoverContent so that it can inspect the user-provided views of the popover.

On macOS, a popover is displayed in its own `NSWindow`, and the `contentView` of that window is an `NSHostingView`. The hosted SwiftUI `View` structure looks like this:

```
ModifiedContent<AnyView, PopoverRootModifier>
  AnyView
    PopoverContent<ModifiedContent<ModifiedContent<ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>, _EnvironmentKeyWritingModifier<NavigationEnabled>>, _EnvironmentKeyWritingModifier<Optional<NavigationState>>>>
      ModifiedContent<ModifiedContent<ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>, _EnvironmentKeyWritingModifier<NavigationEnabled>>, _EnvironmentKeyWritingModifier<Optional<NavigationState>>>
        ModifiedContent<ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>, _EnvironmentKeyWritingModifier<NavigationEnabled>>
          ModifiedContent<YourPopoverContent, ClearNavigationContextModifier>
            YourPopoverContent
```

This commit allows ViewInspector to unwrap PopoverContent so that it can inspect the user-provided views of the popover.
@nalexn nalexn merged commit 4aa8923 into nalexn:0.9.6 May 2, 2023
@nalexn
Copy link
Owner

nalexn commented May 2, 2023

This is great! Thanks @mayoff !

nalexn added a commit that referenced this pull request May 2, 2023
@nalexn nalexn added pending release A fixed issue that'll be released in an upcoming update and removed pending release A fixed issue that'll be released in an upcoming update labels May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants