Skip to content
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

Add advanced range-based platform version predicates #285

Merged
merged 16 commits into from
Jul 1, 2023

Conversation

davdroman
Copy link
Collaborator

@davdroman davdroman commented Jun 30, 2023

This is a different take on #284 without overloading the introspect modifier, as suggested by @paescebu.

It reads quite clean, though it's a tiny bit more obscure to find (which might be a good thing, really), and it allows mixing current + current and past matching all in the same expression (which again, might be a good thing).

Examples:

import SwiftUI
@_spi(Advanced) import SwiftUIIntrospect

struct ContentView: View {
    @State var name = ""

    var body: some View {
        TextField("Name", text: $name)
            .introspect(.textField, on: .iOS(.v13...)) { textField in
                // do something with textField
            }
    }
}
struct ContentView: View {
    var body: some View {
        List {
            Text("Item 1")
            Text("Item 2")
        }
        .introspect(.list, on: .iOS(.v13, .v14, .v15)) { tableView in

        }
        .introspect(.list, on: .iOS(.v16...)) { collectionView in

        }
    }
}

@paescebu
Copy link
Contributor

paescebu commented Jun 30, 2023

Yes!
I think that's perfect. It's an advanced use case which requires an "advanced" syntax.

That looks really beautiful 👌

But looks hard to maintain for you 😁

@davdroman
Copy link
Collaborator Author

Brilliant, glad we found the sweet spot. And maintenance is not a problem, that's what I'm here for 😄

I'll polish this branch over the weekend and probably merge by Monday.

Self(versions, matches: \.isCurrent)
}

@_spi(Advanced)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the question is... should we still gate these? Maybe not 🤔

Copy link
Collaborator Author

@davdroman davdroman Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to keep it, and will also rename existing @_spi(Internals) annotations to @_spi(Advanced) in a separate PR, so everything is accessible from a single entry point. "Advanced" is also a better name than "Internals" because it denotes intent ("Advanced Mode").

Copy link
Contributor

@paescebu paescebu Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sry for the late reply! I definitely think Advanced is such a better name. Internal really gives me "not intended for use" vibes.
With that convention I would say it encourages more advanced people to use it actually.
(Internal also made me a bit unsure initially and hence the question in #280)

@davdroman
Copy link
Collaborator Author

davdroman commented Jul 1, 2023

Some feature requests popped up yesterday so I'll merge this now and get a 0.8.0 release going later today.

@davdroman davdroman marked this pull request as ready for review July 1, 2023 10:03
@davdroman davdroman merged commit fb2f27d into master Jul 1, 2023
@davdroman davdroman deleted the experiment/version-range branch July 1, 2023 10:04
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