-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Feature] Add transparent present cover view #31
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest is good to me 👍
|
||
public struct PresentCoverTransparentView: UIViewRepresentable { | ||
|
||
private let uiHostingViewCount: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name uiHostingViewCount might not clearly convey its purpose. Consider renaming it to something more descriptive
private let uiHostingViewCount: Int | |
private let maxUIHostingViewsToTraverse: Int: Int: Int |
public class PresentCoverTransparentBackgroundView: UIView { | ||
|
||
private let uiHostingViewName = "_UIHostingView" | ||
private let uiHostingViewCount: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private let uiHostingViewCount: Int | |
private let maxUIHostingViewsToTraverse: Int |
override public func didMoveToWindow() { | ||
super.didMoveToWindow() | ||
var superview = superview | ||
var traversedUIHostingView = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var traversedUIHostingView = 0 | |
var traversedCount = 0 |
super.didMoveToWindow() | ||
var superview = superview | ||
var traversedUIHostingView = 0 | ||
while superview != nil && traversedUIHostingView < uiHostingViewCount { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of force unwrapping, you can safely unwrap them using if let or guard let statements.
while superview != nil && traversedUIHostingView < uiHostingViewCount { | |
while let superview = currentSuperview, traversedCount < maxUIHostingViewsToTraverse { |
What happened 👀
PresentCoverTransparentView
to present a cover view with transparent background.Insight 📝
FlowStacks.presentCover
orUIKit. modalPresentationStyle = .presentCover
.What it does
When presenting a .presentCover screen by FlowStacks, FlowStacks creates a
UIHostingView
that contains views with background color.To present a view with no background color, these are set on the views
Why user
.presentCover
.presentCover
guaranteed that the view is present above all existing views. To visualize this clearer, alternative are discussed:.overlay
: Overlay lives on the current view and does not translate to other views. Overlay is also order dependent when declare.fullScreenCover
: Lives on the current view and does not translate to other views. Can have only on activefullScreenCover
at a time. UseUIHostingView
and require this library.Proof Of Work 📹
Example usage:
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-08-28.at.17.03.33.mp4