Skip to content

Add scroll-to-node and zoom features#83

Merged
vade merged 1 commit intoFabric-Project:mainfrom
JustinMeans:feature/scroll-to-first-node
Nov 16, 2025
Merged

Add scroll-to-node and zoom features#83
vade merged 1 commit intoFabric-Project:mainfrom
JustinMeans:feature/scroll-to-first-node

Conversation

@JustinMeans
Copy link
Copy Markdown
Contributor

@JustinMeans JustinMeans commented Nov 16, 2025

1: Adds pinch-to-zoom (two-finger magnify gesture)

Screen.Recording.2025-11-15.at.8.39.17.PM.mov

The SwiftUI Canvas + ScrollView is notorious to get the pinch magnification right but this is a first-step and adds value where it's at.

2: Scrolls to first node when opening a project.

Problem: When opening a project, it doesn't scroll to the first node. Test it with this example:
Test Sphere.zip
Before: Project opens in top left corner, lost in the canvas, have to scroll all the way to center to find nodes.
After: The ScrollView automatically scrolls to the nodes

@JustinMeans JustinMeans deleted the feature/scroll-to-first-node branch November 16, 2025 03:35
@JustinMeans JustinMeans restored the feature/scroll-to-first-node branch November 16, 2025 03:35
@JustinMeans JustinMeans reopened this Nov 16, 2025
@vade
Copy link
Copy Markdown
Contributor

vade commented Nov 16, 2025

nice! I had a version of pinch to zoom working, but didnt get it to a place where patching / wireing nodes up worked while zoomed out. Does your work solve the coordinate transforms for that to work?

Nice stuff!

@JustinMeans
Copy link
Copy Markdown
Contributor Author

It does solve the coordinate transforms by only applying the scale effect to the root view. Of course when you're too far zoomed out you won't hit the hitbox. Went through a couple iterations before that and had the same issue, but this version seems to have solved it in my testing.

Screen.Recording.2025-11-15.at.8.45.58.PM.mov

@JustinMeans
Copy link
Copy Markdown
Contributor Author

It does have that offset / stutter though when the magnification gesture initiates, as seen in the recording... been wrestling with that and SwiftUI but haven't gotten it better than this. Still a starting point in the right direction and nice to have building out larger files.

@vade
Copy link
Copy Markdown
Contributor

vade commented Nov 16, 2025

One of the stutter/ scroll issues is due to use of @\environment, which ive been meaning to factor out. Apparently @\environment cascades recalculations through the view tree, stopping some optimization from happening that the new @\Observable mechanisms support.

#66 has a link to a newer Apple video espousing some advice for optimizing some view redraw logic.

Nice stuff with the coordinate transform just working!!

@JustinMeans
Copy link
Copy Markdown
Contributor Author

Oh interesting, good to know. I'll check that out 👍🏻

@vade vade merged commit 170fd49 into Fabric-Project:main Nov 16, 2025
JustinMeans added a commit to JustinMeans/Fabric that referenced this pull request Nov 16, 2025
Addresses feedback from Fabric-Project#83 regarding zoom stutter caused by @Environment
observation cascades. Marks Graph drag preview properties as @ObservationIgnored
to prevent view recalculation during gestures. Calculates zoom anchor from
current scroll position instead of gesture location to eliminate jumps between
magnification gestures.

Related: Fabric-Project#83, Fabric-Project#66
JustinMeans added a commit to JustinMeans/Fabric that referenced this pull request Nov 16, 2025
Addresses feedback from Fabric-Project#83 regarding zoom stutter caused by @Environment
observation cascades. Marks Graph drag preview properties as @ObservationIgnored
to prevent view recalculation during gestures. Calculates zoom anchor from
current scroll position instead of gesture location to eliminate jumps between
magnification gestures.

Related: Fabric-Project#83, Fabric-Project#66
JustinMeans added a commit to JustinMeans/Fabric that referenced this pull request Nov 16, 2025
Addresses feedback from Fabric-Project#83 regarding zoom stutter caused by @Environment
observation cascades. Marks Graph drag preview properties as @ObservationIgnored
to prevent view recalculation during gestures. Calculates zoom anchor from
current scroll position instead of gesture location to eliminate jumps between
magnification gestures.

Related: Fabric-Project#83, Fabric-Project#66
JustinMeans added a commit to JustinMeans/Fabric that referenced this pull request Nov 16, 2025
Addresses feedback from Fabric-Project#83 regarding zoom stutter caused by @Environment
observation cascades. Marks Graph drag preview properties as @ObservationIgnored
to prevent view recalculation during gestures. Calculates zoom anchor from
current scroll position instead of gesture location to eliminate jumps between
magnification gestures.

Related: Fabric-Project#83, Fabric-Project#66
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.

2 participants