Skip to content

Conversation

MiaKoring
Copy link

This PR introduces a new .onHover modifier to Views.
Related Issue: #211
Added in this PR:

  • Extension View

    • onHover { Bool in }
  • protocol AppBackend

    • createHoverTarget
    • updateHoverTarget
    • Default implementation for Backends without implementation
  • Backend Support

    • AppKitBackend
    • UIKitBackend
    • GtkBackend
    • WinUIBackend
  • Other changes:

    • left & right NSClickGestureRecognizer now get set to nil in NSCustomTapGestureTarget when corresponding function gets set to nil
    • UISlider now Supports macCatalyst (added through compilerflag)
    • Added HoverExample
    • (format_and_lint.sh and generate.sh automatic changes)

HoverExample erfolgreich getestet auf:
macOS 26 (AppKitBackend, GtkBackend, UIKitBackend (macCatalyst))
iPadOS 26 (UIKitBackend)
Windows 11 (WinUI Backend)
Fedora 44 (GtkBackend)

Notes:
Gtk versions below 4.20.0 may encounter compiling problems. I don’t know why or what caused it, I only used the generate script, but on 4.18.6 on Fedora 42 I got this Error:

/home/mia/Documents/swift-cross-ui/Sources/Gtk/Generated/PadActionType.swift:28:6: error: cannot find 'GTK_PAD_ACTION_DIAL' in scope
26 | case GTK_PAD_ACTION_STRIP:
27 |     self = .strip
28 | case GTK_PAD_ACTION_DIAL:
   |      `- error: cannot find 'GTK_PAD_ACTION_DIAL' in scope
29 |     self = .dial
30 |             default:

I checked and it should’ve been available since 4.0 https://docs.gtk.org/gtk4/enum.PadActionType.html
Maybe someone knows how to fix it and maybe it was just a local issue.

test.sh output

   Test Suite 'All tests' started at 2025-09-08 00:03:46.577.
Test Suite 'swift-cross-uiPackageTests.xctest' started at 2025-09-08 00:03:46.584.
Test Suite 'SwiftCrossUITests' started at 2025-09-08 00:03:46.584.
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testBasicLayout]' started.
/Users/miakoring/Documents/Fork/swift-cross-ui/Tests/SwiftCrossUITests/SwiftCrossUITests.swift:203: error: -[SwiftCrossUITests.SwiftCrossUITests testBasicLayout] : XCTAssertEqual failed: ("ViewSize(size: SIMD2<Int>(102, 104), idealSize: SIMD2<Int>(102, 104), idealWidthForProposedHeight: 102, idealHeightForProposedWidth: 104, minimumWidth: 102, minimumHeight: 104, maximumWidth: 102.0, maximumHeight: 104.0, participateInStackLayoutsWhenEmpty: true)") is not equal to ("ViewSize(size: SIMD2<Int>(92, 96), idealSize: SIMD2<Int>(92, 96), idealWidthForProposedHeight: 92, idealHeightForProposedWidth: 96, minimumWidth: 92, minimumHeight: 96, maximumWidth: 92.0, maximumHeight: 96.0, participateInStackLayoutsWhenEmpty: true)") - View update result mismatch
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testBasicLayout]' failed (0.204 seconds).
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testCodableNavigationPath]' started.
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testCodableNavigationPath]' passed (0.001 seconds).
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testStateObservation]' started.
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testStateObservation]' passed (0.000 seconds).
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testThrottledStateObservation]' started.
Test Case '-[SwiftCrossUITests.SwiftCrossUITests testThrottledStateObservation]' passed (0.225 seconds).
Test Suite 'SwiftCrossUITests' failed at 2025-09-08 00:03:47.014.
	 Executed 4 tests, with 1 failure (0 unexpected) in 0.430 (0.431) seconds
Test Suite 'swift-cross-uiPackageTests.xctest' failed at 2025-09-08 00:03:47.014.
	 Executed 4 tests, with 1 failure (0 unexpected) in 0.430 (0.431) seconds
Test Suite 'All tests' failed at 2025-09-08 00:03:47.014.
	 Executed 4 tests, with 1 failure (0 unexpected) in 0.430 (0.437) seconds
􀟈  Test run started.
􀄵  Testing Library Version: 1084
􀄵  Target Platform: arm64e-apple-macos14.0
􁁛  Test run with 0 tests in 0 suites passed after 0.001 seconds.

Added:
- onHover(_ action: (Bool) -> Void) View Extension
- OnHoverModifier TypeSafeView
- createHoverTarget(wrapping: Widget) -> Widget to AppBackend Protocol
- updateHoverTarget(_: Widget, environment: EnvironmentValues, action: (Bool) -> Void) to AppBackend Protocol
- corresponding default implementations
- AppKitBackend hover implementation
   - createHoverTarget implementation
   - updateHoverTarget implementation
   - NSCustomHoverTarget (NSView notifying about hovers)
- HoverExample

Fixed:
- AppKitBackend
   - fixed reference removing for NSClickGestureRecognizer in NSCustomTapGestureTarget
…ming fixes in AppKitBackend

- tapGestureRecognizer and longPressGestureRecognizer now get removed if their corresponding handler is set to nil.
- Added Hoverable Widget
- Added hovertarget creation & update functions
- added macCalatalyst as compatible for UISlider since it supports it
…ming fixes in AppKitBackend

- tapGestureRecognizer and longPressGestureRecognizer now get removed if their corresponding handler is set to nil.
- Added Hoverable Widget
- Added hovertarget creation & update functions
- added macCalatalyst as compatible for UISlider since it supports it
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.

1 participant