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

SwiftUI API #56

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

SwiftUI API #56

wants to merge 19 commits into from

Conversation

muukii
Copy link
Collaborator

@muukii muukii commented Jun 2, 2023

This PR provides new APIs that display Rideau in SwiftUI world.
those are designed following SwiftUI standard API such sheet modifier.

CleanShot 2023-06-02 at 22 00 17@2x

Comment on lines +8 to +47
public func rideau<Content: View>(
configuration: RideauView.Configuration = .init(snapPoints: [.hidden, .fraction(1)]),
initialSnapPoint: RideauSnapPoint = .fraction(1),
isPresented: Binding<Bool>,
onDismiss: (() -> Void)? = nil,
@ViewBuilder content: () -> Content
) -> some View {
modifier(
SwiftUIRideauBooleanModifier(
configuration: configuration,
initialSnapPoint: initialSnapPoint,
isPresented: isPresented,
onDismiss: onDismiss ?? {},
body: content()
)
)

}

/**
Displays a Rideau using the given item as a data source for the Rideau’s content.
*/
public func rideau<Item: Identifiable, Content: View>(
configuration: RideauView.Configuration = .init(snapPoints: [.hidden, .fraction(1)]),
initialSnapPoint: RideauSnapPoint = .fraction(1),
item: Binding<Item?>,
onDismiss: (() -> Void)? = nil,
@ViewBuilder content: @escaping (Item) -> Content
) -> some View {

modifier(
SwiftUIRideauItemModifier(
configuration: configuration,
initialSnapPoint: initialSnapPoint,
item: item,
onDismiss: onDismiss ?? {},
body: content
)
)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here is public header


}

private struct SwiftUIRideau<Content: View>: UIViewControllerRepresentable {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

host view to present the view controller that hosts Rideau internally.


}

private struct SwiftUIRideauItemModifier<Item: Identifiable, Body: View>: ViewModifier {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made a modifier for displaying with item binding


}

private struct SwiftUIRideauBooleanModifier<Body: View>: ViewModifier {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made a modifier for displaying with boolean binding

configuration: RideauView.Configuration,
initialSnapPoint: RideauSnapPoint,
onDidDismiss: @escaping @MainActor () -> Void,
@ViewBuilder conetnt: () -> Content
Copy link
Collaborator

Choose a reason for hiding this comment

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

content

}
}

#if DEBUG
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI in release build, PreviewProviders will not be included

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I know that. I just added macro for just in case of like adding a dummy struct inside macro.
even though, any types that are defined inside PreviewProvider, will be deleted in production. but not sure.
so still, adding macro makes me relieved.


// MARK: - Properties

var onWillDismiss: () -> Void = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hm, yes, that's called.
but anymore it's not meaningful.
I'll delete it.

rideauView.containerView.set(bodyView: bodyViewController.view, resizingOption: resizingOption)
}

@objc private dynamic func didTapBackdropView(gesture: UITapGestureRecognizer) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need it to by dynamic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah it's kind of classic way to support objc dynamics. in some swift version, swift compiler deleted those symbols in optimization. we could solve that by adding dynamic.
but seems nowadays we don't need to do that anymore.

@muukii
Copy link
Collaborator Author

muukii commented Jun 5, 2023

@ntnmrndn
I noticed that programmatically Sheet dismissal animation was not supported yet.

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