Skip to content

Commit

Permalink
Paywalls: improved IntroEligibilityStateView to avoid layout chan…
Browse files Browse the repository at this point in the history
…ges (#2946)
  • Loading branch information
NachoSoto committed Sep 14, 2023
1 parent c1a0cf0 commit 2cfb83c
Showing 1 changed file with 15 additions and 1 deletion.
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 }

}

0 comments on commit 2cfb83c

Please sign in to comment.