-
Notifications
You must be signed in to change notification settings - Fork 338
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
[Paywalls V2] Add purchase button activity indicator #4787
[Paywalls V2] Add purchase button activity indicator #4787
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.
Good! Just a couple of small comments
.progressViewStyle(CircularProgressViewStyle(tint: bestTint(for: colorInfo))) | ||
case .image, .none: | ||
ProgressView() | ||
.progressViewStyle(CircularProgressViewStyle(tint: .white)) |
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.
Not sure if the tint
here should depend on the colorScheme
and/or on something else. You know, to prevent showing the while progress view on a white background. But then, I don't even know if this case is even possible (looking at the Dashboard, it seems like Buttons only support color-based backgrounds)
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.
Yea I think the best version would be to base the tint on the image pixels underneath the circular progress view. But that can also come in a next iteration imo.
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.
Or actually, @joshdholtz are there any plans on making the loading indicator have a configurable color on the dashboard? That would avoid the need for us to be smart about it.
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.
If not, another way of trying to be smart about it could be to try and use the same color as the (first?) text component in the button. But I'm sure there are edge cases for this (e.g. no text or multiple text components). Just putting ideas out there
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.
are there any plans on making the loading indicator have a configurable color
@JayShortway I didn't want to because its not something our users should have to think about but I'm not opposed if we make it an optional style at some point
Not sure if the tint here should depend on the colorScheme and/or on something else
@ajpallares The calculated tint does take the color scheme into effect so we should be good!
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.
Also, I added a blur to the background it so it should make it even easier for either tint color to be visible 🤞
let gradient = colorInfo.toGradient() | ||
let averageBrightness = gradient.stops | ||
.compactMap { $0.color.brightness() } | ||
.reduce(0, +) / CGFloat(gradient.stops.count) | ||
return averageBrightness > 0.6 ? .black : .white |
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.
I think this is ok as a first version and will work 99%, but perhaps we could try and be smarter about this, in the sense of giving the colors in the center a higher weight when computing the averageBrightness
than to the colors near the edges (because the ProgressView will appear in the center). Although to get a counterexample of this it probably means chosing a bad gradient combination 😄
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.
I would love to be smarter about this in the future 😅 It's not perfect but its something 🤷♂️
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.
Totally! 🚀
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.
Fancy!
extension Color { | ||
func brightness() -> CGFloat { | ||
guard let uiColor = UIColor(self).cgColor.components else { return 1.0 } | ||
return (uiColor[0] * 299 + uiColor[1] * 587 + uiColor[2] * 114) / 1000 |
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.
What are these magic numbers? Maybe a comment or well-named constants could explain them?
.progressViewStyle(CircularProgressViewStyle(tint: bestTint(for: colorInfo))) | ||
case .image, .none: | ||
ProgressView() | ||
.progressViewStyle(CircularProgressViewStyle(tint: .white)) |
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.
Yea I think the best version would be to base the tint on the image pixels underneath the circular progress view. But that can also come in a next iteration imo.
3759244
to
ac405b7
Compare
b1e9e19
to
7770f2c
Compare
Love it! 🎉 |
Motivation
Need a way to show when there is activity happening with a purchase button
Description
Screen.Recording.2025-02-13.at.8.11.14.PM.mov