-
Notifications
You must be signed in to change notification settings - Fork 42
Add initial rendering support for NSHostingView #291
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// OpenSwiftUI+NSView.h | ||
// COpenSwiftUI | ||
// | ||
// Audited for macOS 15.0 | ||
// Status: WIP | ||
|
||
#ifndef OpenSwiftUI_NSView_h | ||
#define OpenSwiftUI_NSView_h | ||
|
||
#include "OpenSwiftUIBase.h" | ||
|
||
#if OPENSWIFTUI_TARGET_OS_OSX | ||
|
||
#import <AppKit/AppKit.h> | ||
|
||
OPENSWIFTUI_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSView (OpenSwiftUI) | ||
|
||
@property (strong, nullable) NSView *maskView; | ||
|
||
- (void)setFlipped:(BOOL)flipped; | ||
|
||
@end | ||
|
||
OPENSWIFTUI_ASSUME_NONNULL_END | ||
|
||
#endif /* OPENSWIFTUI_TARGET_OS_OSX */ | ||
|
||
#endif /* OpenSwiftUI_NSView_h */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// __FILEBASENAME__.m | ||
// COpenSwiftUI | ||
// | ||
// Audited for macOS 15.0 | ||
// Status: WIP | ||
|
||
#import "OpenSwiftUI+NSView.h" | ||
|
||
#if OPENSWIFTUI_TARGET_OS_OSX | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// CAChameleonLayer.h | ||
// COpenSwiftUI | ||
// | ||
// Audited for macOS 15.0 | ||
// Status: WIP | ||
|
||
#include "OpenSwiftUIBase.h" | ||
|
||
#if OPENSWIFTUI_TARGET_OS_OSX | ||
|
||
#import <QuartzCore/QuartzCore.h> | ||
|
||
OPENSWIFTUI_ASSUME_NONNULL_BEGIN | ||
|
||
@interface CAChameleonLayer : CALayer | ||
|
||
@end | ||
|
||
OPENSWIFTUI_ASSUME_NONNULL_END | ||
|
||
#endif /* OPENSWIFTUI_TARGET_OS_OSX */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// | ||
// CAChameleonLayer.m | ||
// OpenSwiftUI | ||
// | ||
// Created by JH on 2025/5/14. | ||
// | ||
Mx-Iris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#import "CAChameleonLayer.h" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// NSGraphicsView.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for macOS 15.0 | ||
// Status: WIP | ||
|
||
#if os(macOS) | ||
|
||
import OpenSwiftUI_SPI | ||
import AppKit | ||
|
||
final class _NSGraphicsView: NSView { | ||
var recursiveIgnoreHitTest: Bool = false | ||
|
||
var customAcceptsFirstMouse: Bool? | ||
|
||
override init(frame frameRect: NSRect) { | ||
super.init(frame: frameRect) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -127,6 +127,7 @@ open class NSHostingView<Content>: NSView, XcodeViewDebugDataProvider where Cont | |||||||||||||||||
// TODO | ||||||||||||||||||
wantsLayer = true | ||||||||||||||||||
// TODO | ||||||||||||||||||
renderer.host = self | ||||||||||||||||||
HostingViewRegistry.shared.add(self) | ||||||||||||||||||
// TODO | ||||||||||||||||||
Update.end() | ||||||||||||||||||
|
@@ -182,7 +183,7 @@ open class NSHostingView<Content>: NSView, XcodeViewDebugDataProvider where Cont | |||||||||||||||||
context.allowsImplicitAnimation = false | ||||||||||||||||||
isUpdating = true | ||||||||||||||||||
// TODO | ||||||||||||||||||
render() | ||||||||||||||||||
render(targetTimestamp: Time()) | ||||||||||||||||||
// TODO | ||||||||||||||||||
isUpdating = false | ||||||||||||||||||
// TODO | ||||||||||||||||||
|
@@ -318,8 +319,67 @@ extension NSHostingView: ViewRendererHost { | |||||||||||||||||
|
||||||||||||||||||
package func updateScrollableContainerSize() {} | ||||||||||||||||||
|
||||||||||||||||||
package func renderDisplayList(_ list: DisplayList, asynchronously: Bool, time: Time, nextTime: Time, targetTimestamp: Time?, version: DisplayList.Version, maxVersion: DisplayList.Version) -> Time { | ||||||||||||||||||
.infinity | ||||||||||||||||||
package func renderDisplayList( | ||||||||||||||||||
_ list: DisplayList, | ||||||||||||||||||
asynchronously: Bool, | ||||||||||||||||||
time: Time, | ||||||||||||||||||
nextTime: Time, | ||||||||||||||||||
targetTimestamp: Time?, | ||||||||||||||||||
version: DisplayList.Version, | ||||||||||||||||||
maxVersion: DisplayList.Version | ||||||||||||||||||
) -> Time { | ||||||||||||||||||
func render() -> Time { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The nested render() function increases the complexity of renderDisplayList. Consider extracting it into a separate method to improve readability and maintainability.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||
let scale = window?.screen?.backingScaleFactor ?? 1 | ||||||||||||||||||
let environment = DisplayList.ViewRenderer.Environment(contentsScale: scale, opaqueBackground: isOpaque) | ||||||||||||||||||
#if canImport(SwiftUI, _underlyingVersion: 6.0.87) && _OPENSWIFTUI_SWIFTUI_RENDER | ||||||||||||||||||
|
||||||||||||||||||
return renderer.swiftUI_render( | ||||||||||||||||||
rootView: self, | ||||||||||||||||||
from: list, | ||||||||||||||||||
time: time, | ||||||||||||||||||
nextTime: nextTime, | ||||||||||||||||||
version: version, | ||||||||||||||||||
maxVersion: maxVersion, | ||||||||||||||||||
environment: environment | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
#else | ||||||||||||||||||
return renderer.render( | ||||||||||||||||||
rootView: self, | ||||||||||||||||||
from: list, | ||||||||||||||||||
time: time, | ||||||||||||||||||
nextTime: nextTime, | ||||||||||||||||||
version: version, | ||||||||||||||||||
maxVersion: maxVersion, | ||||||||||||||||||
environment: environment | ||||||||||||||||||
) | ||||||||||||||||||
#endif | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
if asynchronously { | ||||||||||||||||||
if let renderedTime = renderer.renderAsync( | ||||||||||||||||||
to: list, | ||||||||||||||||||
time: time, | ||||||||||||||||||
nextTime: nextTime, | ||||||||||||||||||
targetTimestamp: targetTimestamp, | ||||||||||||||||||
version: version, | ||||||||||||||||||
maxVersion: maxVersion | ||||||||||||||||||
) { | ||||||||||||||||||
return renderedTime | ||||||||||||||||||
} else { | ||||||||||||||||||
var renderedTime = nextTime | ||||||||||||||||||
Update.syncMain { | ||||||||||||||||||
renderedTime = render() | ||||||||||||||||||
} | ||||||||||||||||||
return renderedTime | ||||||||||||||||||
} | ||||||||||||||||||
} else { | ||||||||||||||||||
var renderedTime = nextTime | ||||||||||||||||||
Update.syncMain { | ||||||||||||||||||
renderedTime = render() | ||||||||||||||||||
} | ||||||||||||||||||
return renderedTime | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
package func updateRootView() { | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// NSInheritedView.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for macOS 15.0 | ||
// Status: WIP | ||
|
||
#if os(macOS) | ||
|
||
import OpenSwiftUI_SPI | ||
import AppKit | ||
|
||
final class _NSInheritedView: NSView { | ||
var hitTestsAsOpaque: Bool = false | ||
|
||
override init(frame frameRect: NSRect) { | ||
super.init(frame: frameRect) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// NSProjectionView.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for macOS 15.0 | ||
// Status: WIP | ||
|
||
#if os(macOS) | ||
|
||
import OpenSwiftUI_SPI | ||
import AppKit | ||
|
||
final class _NSProjectionView: NSView { | ||
|
||
override var wantsUpdateLayer: Bool { true } | ||
|
||
override init(frame frameRect: NSRect) { | ||
super.init(frame: frameRect) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -139,8 +139,14 @@ private struct LeafDisplayList<V>: StatefulRule, CustomStringConvertible where V | |||||||||||||||||
) | ||||||||||||||||||
item.canonicalize(options: options) | ||||||||||||||||||
#if _OPENSWIFTUI_SWIFTUI_RENDER | ||||||||||||||||||
|
||||||||||||||||||
// FIXME: Remove me after Layout system is implemented | ||||||||||||||||||
#if os(macOS) | ||||||||||||||||||
item.frame = CGRect(x: 0, y: 0, width: 500, height: 300) | ||||||||||||||||||
#elseif os(iOS) | ||||||||||||||||||
item.frame = CGRect(x: 0, y: 100.333, width: 402, height: 739) | ||||||||||||||||||
Comment on lines
+145
to
147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The temporary hard-coded frame values may hinder adaptability across different screen sizes. Consider deferring to the layout system or using configurable parameters once implemented.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||
#endif | ||||||||||||||||||
|
||||||||||||||||||
#endif | ||||||||||||||||||
value = DisplayList(item) | ||||||||||||||||||
} | ||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.