From df629d74bb843ee0a626e8639dbc5bd7593589fa Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 12 Oct 2026 00:56:09 +0800 Subject: [PATCH] fix(display-list): make moveContents nonoptional --- Package.resolved | 2 +- .../OpenRenderBox/Render/ORBDisplayList.swift | 2 +- .../OpenRenderBoxObjC/Render/ORBDisplayList.h | 2 +- .../DisplayListTests.swift | 19 +++++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Package.resolved b/Package.resolved index ef0c0e2..78475d9 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "39e20ae06a042bbac3eefd4c3ff9d901b423dac8" + "revision" : "10ace67d6ed884f4dbae0c52e157adf2bbb5301c" } }, { diff --git a/Sources/OpenRenderBox/Render/ORBDisplayList.swift b/Sources/OpenRenderBox/Render/ORBDisplayList.swift index 6fd4d39..fc6e53e 100644 --- a/Sources/OpenRenderBox/Render/ORBDisplayList.swift +++ b/Sources/OpenRenderBox/Render/ORBDisplayList.swift @@ -154,7 +154,7 @@ public final class ORBDisplayList: NSObject, ORBDisplayListContents { // MARK: - Contents - public func moveContents() -> (any ORBDisplayListContents)? { + public func moveContents() -> any ORBDisplayListContents { _openRenderBoxUnimplementedFailure() } diff --git a/Sources/OpenRenderBoxCxx/include/OpenRenderBoxObjC/Render/ORBDisplayList.h b/Sources/OpenRenderBoxCxx/include/OpenRenderBoxObjC/Render/ORBDisplayList.h index 934db07..ff88559 100644 --- a/Sources/OpenRenderBoxCxx/include/OpenRenderBoxObjC/Render/ORBDisplayList.h +++ b/Sources/OpenRenderBoxCxx/include/OpenRenderBoxObjC/Render/ORBDisplayList.h @@ -56,7 +56,7 @@ ORB_ASSUME_NONNULL_BEGIN - (void)drawDisplayList:(id)list alpha:(float)alpha; - (void)drawInRect:(CGRect)rect alpha:(float)alpha blendMode:(int)mode flags:(unsigned int)flags operation:(id /* block */)operation; - (void)renderInContext:(CGContextRef)context options:(nullable id)options; -- (nullable id)moveContents; +- (id)moveContents; - (void)setIdentifier:(unsigned int)identifier namespace:(nullable NSUUID *)ns; - (void)beginRecordingXML; - (void)addAffineTransformStyle:(CGAffineTransform)style; diff --git a/Tests/OpenRenderBoxCompatibilityTests/DisplayListTests.swift b/Tests/OpenRenderBoxCompatibilityTests/DisplayListTests.swift index d2d15cf..637c040 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/DisplayListTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/DisplayListTests.swift @@ -63,8 +63,20 @@ struct DisplayListTests { context.fill([CGRect(x: 0, y: 0, width: 10, height: 10)]) displayList.endCGContext() - let contents = displayList.moveContents() - #expect(contents != nil) + let contents: any ORBDisplayListContents = displayList.moveContents() + #expect(!contents.isEmpty()) + #expect(displayList.isEmpty()) + + let emptyContents: any ORBDisplayListContents = displayList.moveContents() + #expect(emptyContents.isEmpty()) + #expect(displayList.isEmpty()) + } + + @Test + func testMoveEmptyContents() { + let displayList = ORBDisplayList() + let contents: any ORBDisplayListContents = displayList.moveContents() + #expect(contents.isEmpty()) #expect(displayList.isEmpty()) } @@ -94,8 +106,7 @@ struct DisplayListTests { displayList.endCGContext() let contents = displayList.moveContents() - #expect(contents != nil) - #expect(contents!.isEmpty() == false) + #expect(!contents.isEmpty()) } #endif }