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

Paywalls: improved IntroEligibilityStateView to avoid layout changes #2946

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion RevenueCatUI/Views/IntroEligibilityStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct IntroEligibilityStateView: View {
// Hide until we've determined intro eligibility
// only if there is a custom intro text.
.withPendingData(self.needsToWaitForIntroEligibility, alignment: self.alignment)
// Hide if there is no intro but we have no text to ensure layout does not change.
.hidden(if: self.isNotEligibleForIntro && self.textWithNoIntroOffer.isEmpty)
.foregroundColor(self.foregroundColor)
.tint(self.foregroundColor)
}
Expand All @@ -45,7 +47,9 @@ struct IntroEligibilityStateView: View {
if let textWithIntroOffer = self.textWithIntroOffer, self.isEligibleForIntro {
return textWithIntroOffer
} else {
return self.textWithNoIntroOffer
// Display text with intro offer as a backup to ensure layout does not change
// when switching states.
return self.textWithNoIntroOffer.notEmpty ?? self.textWithIntroOffer ?? ""
}
}

Expand All @@ -60,6 +64,10 @@ private extension IntroEligibilityStateView {
return self.introEligibility?.isEligible != false
}

var isNotEligibleForIntro: Bool {
return self.introEligibility?.isEligible == false
}

var needsToWaitForIntroEligibility: Bool {
return self.introEligibility == nil && self.textWithIntroOffer != nil
}
Expand All @@ -83,3 +91,9 @@ private extension View {
}

}

private extension String {

var notEmpty: String? { return self.isEmpty ? nil : self }

}