Skip to content

AppKitNavigation - #200

Draft
Mx-Iris wants to merge 178 commits into
pointfreeco:mainfrom
MxIris-Library-Forks:main
Draft

Mx-Iris wants to merge 178 commits into
pointfreeco:mainfrom
MxIris-Library-Forks:main

Conversation

@Mx-Iris

@Mx-Iris Mx-Iris commented Aug 14, 2024

Copy link
Copy Markdown
Contributor

Hello everyone, I love AppKit. I am very pleased to see that UIKit has such an excellent framework available.

I have also watched videos from pointfreeco, where it is mentioned more than once that domain modeling is the most important thing, and using tools can make any platform serve the model.

I spent some time porting part of the API, and most of the NSControl can be use. Next, I will add some AppKit-specific navigation, such as sheet, modal, and some macOS-specific controls, and a lot of documentation still needs to be refined, as well as example projects and tests.

This PR is not yet complete, so please do not merge it yet!

For those who are interested, you can try running the example project

@Mx-Iris Mx-Iris changed the title AppKit support AppKitNavigation Aug 14, 2024
@stephencelis
stephencelis marked this pull request as draft August 14, 2024 17:55
@stephencelis

Copy link
Copy Markdown
Member

Awesome work! We're looking forward to diving into it soon 😄 I've converted things to a draft for now, so just tap the "Ready for review" button whenever you think things are in a good place.

@stephencelis

Copy link
Copy Markdown
Member

@Mx-Iris Thanks again for your work on this! We took it for a spin and are definitely excited to incorporate things back into the library.

I think to start it would be nice to break things down into smaller PRs in order to progressively ship things. This PR is still great to leave open as a "full vision" of things that folks can take for a spin. And now we could start isolating smaller chunks of work that can land in main independently.

Some potential steps/chunks:

  1. A PR that adds the AppKit-specific observe helper and AppKit-specific UITransaction infrastructure. This could include the animations, as well, or animations could be split off into their own PR..
  2. A PR that adds the base NSControl binding infrastructure.
  3. PR(s?) that add the individual binding helpers. You could do all the simple helpers in a single PR, and any helpers that are more complex could land in their own PRs.
  4. A PR that adds the navigation helpers.

If there are any obvious ways of breaking any step down further, it's appreciated, and should make it easier to review each PR and also get each PR merged more quickly rather than have any giant PR sit around for too long.

Excited for this!

@stephencelis

Copy link
Copy Markdown
Member

Oh, and another note: let's not worry about documentation or case studies at all right now. Those are typically things we save till the end when we're close to release, and we can discuss how we may want to approach that when things are further along and everything else has landed in main.

@Mx-Iris

Mx-Iris commented Aug 15, 2024

Copy link
Copy Markdown
Contributor Author

@stephencelis I understand your point now. This branch is mainly for quickly implementing my ideas and verifying if they're effective. I'll follow your suggestion and break them down into smaller units, then submit PRs for each one individually.​​​​​​​​​​​​​​​​

The shim's last part redeclared `NSControl`'s multiple target-action API
for SDKs older than macOS 27. The macOS 27 SDK declares it, and Xcode 27
is the only toolchain this fork is built with now, so the target goes
away from every manifest, along with the AppKitPlus import that
`TargetActionProxy` needed to pick a declaration before that SDK.

AppKitNavigation no longer builds with an older SDK.

Draft proposal: Documentations/Evolutions/draft-appkit-remove-shim.md
…ized

Waiting for the presenter's window to be on screen is what a sheet or a
popover needs, since it attaches to that window. A modal window, a
transition of the caller's own and a push do not: before the shim went
away they went ahead as soon as the presenter had appeared once. They
now go ahead while the window that holds the presenter, or the
navigation stack, is minimized too.

The two new tests present a modal window and push from a minimized
window; both failed before.

The review's other findings are recorded in
Documentations/Internal/ReviewDecisions.md.
AppKit has taken a presented view controller off screen by the time
`dismiss(_:)` returns. While the shim reported dismissals from
`viewDidDisappear`, a dismissal the binding asked for therefore ended
while the binding's change was still being applied; since the shim went
away it waited for the run loop turn to end.

`end` now checks right after dismissing and ends the presentation there
and then. A dismissal still on its way out, through an animator of the
caller's own, is left to the watch, and one the user starts is still
noticed as the run loop turn ends.

The new test reads `onDismiss` from a custom transaction key, whose
`perform` runs once the binding's change has been applied. It failed
before.
…make every sheet closable

The Basics case study's Boolean sheet showed one line of text and no
button, so once it came up nothing could close it; the Wi-Fi network
detail sheet had the same dead end after cancelling "Forget". Half of
the AppKit pages were also line-for-line ports of the UIKit ones: a pile
of buttons in the middle of the window, with the state written into
their titles as emoji.

Every AppKit page now lays its controls out the way System Settings
does: titled groups of rows in rounded boxes, each row's title on its
leading side and its state and controls on its trailing side, in a
column that scrolls. The layout lives in the shared support file, so no
file is added to the project.

Every presented sheet has a Done button that Return triggers. The
presented view controllers also implement cancel(_:): a sheet asks its
delegate, which is the view controller AppKit presented, for it when
nothing else handles Escape.
…presentation's state

On the Mac the case studies still lived in the drill-down list the iOS
app uses: Case studies, then AppKit, then the page, with a back button
in between. The AppKit pages had also lost the presentation state the
old ones wrote into their button titles; only a few rows showed it, as
grey text.

The Mac app now opens a split view. Its sidebar lists every SwiftUI and
AppKit case study, grouped as before and each with a symbol, and the
chosen one shows beside it. The read-me moves from an About sheet to a
popover behind the toolbar's info button, and the SwiftUI forms use the
grouped style the AppKit pages use. iOS keeps the existing list.

Every AppKit row that presents something now shows whether it is
presented, and what, with a green check or a grey cross. The
type-erased stack shows how many values its path holds, and the Wi-Fi
settings show where they navigate to above the list.
… pages fill the window

Pushing onto an AppKit navigation stack showed both screens at once: the
screens drew no background, so the old one showed through the new one
as it slid in. Each screen now has the window's background material
behind it. windowBackgroundColor would be a shade darker than the
window, whose background takes on the desktop picture's tint.

Every AppKit page was also laid out 688 points wide and centered. The
form column's wish to fill the page minus its margins was stronger
(750) than the width SwiftUI holds a hosted view controller at (500),
so it narrowed the whole page to the column. The column now prefers 640
points at 490 and is required to stay within the page, so the pages
fill the space beside the sidebar again.
…d where it is fixed

The screen a pop takes away slid out as its bare background. AppKitPlus,
like the UXKit it ports, sets that screen's frame wholly outside the
container as the animation starts, and AppKit only redraws the part of
a view inside the window. The fix is in AppKitPlus and reaches the case
studies with its next release; nothing changes here.
The fix for the blank screen a pop slides away has landed in AppKitPlus
as proposal 0116 and is pushed, but no AppKitPlus-Release carries it
yet: the case studies pin 0.21.0, and 0.22.0 predates it. Bumping that
pin after the next release is all that is left here.
The shim removal and the macOS case study redesign land together: the
redesign was built on top of the shim removal. The case studies still
pin AppKitPlus-Release 0.21.0; 0.23.0 carries the fix for the blank
screen a pop slides away, and moving the pin is left as a follow-up.
0.23.0 fixes the blank screen a pop slides away in stack navigation.
Only the case studies' lockfile moves; Package.swift still asks for
0.21.0 or later, which already allows 0.23.0.
AppKitPlus's next release requires macOS 14, and with the AppKitPlus
trait on, SwiftPM rejects this package while it declares less, whatever
the app's deployment target. Below macOS 13.3 Swift also loses
conformances to protocols with a changed runtime name
(swiftlang/swift#94329), and the stack controller's delegate adopts
one. Only the two manifests that carry the trait change; the Swift 6.0
and 6.1 manifests keep macOS 10.15.
Raising the floor surfaces five deprecation warnings in files this fork
shares with upstream; leaving them keeps upstream merges clean.
The macOS 14 floor lands together with the case studies' move to
AppKitPlus-Release 0.23.0, which it was built on.
The protocol has to stay public because it constrains the content of the
public sheet and modal methods, but its three underscored requirements were
implementation details that came along with it: they hung as public members
on every NSWindow and NSAlert, and a type outside the library could conform
by implementing them.

WindowBackedContent is now a marker protocol with no requirements. The
implementation moves, unchanged apart from losing the underscore, into the
internal PresentableWindowBackedContent, which only NSWindow and NSAlert
conform to. The sheet and modal-loop styles cast the content to it when they
begin. Content of a type conformed from outside the library reports an issue
and ends right away, as if the user had dismissed it, instead of showing.

Nothing downstream conforms to the protocol or calls the removed members.
Add the proposal and point to it from 0005.

This branch has not been deployed

No deployments
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.

3 participants