Skip to content

Commit

Permalink
[Paywalls] Make iOS version calculation lazy (#4163)
Browse files Browse the repository at this point in the history
Since iOS version cannot change at runtime, we can make it a stored
variable so we only compute it once.

---------

Co-authored-by: Toni Rico <[email protected]>
  • Loading branch information
MarkVillacampa and tonidero authored Aug 9, 2024
1 parent dd0ee26 commit 201a0e3
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions RevenueCatUI/Modifiers/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ extension View {

}

private var isIOSVersionWithCrash: Bool = {
// There is a bug in iOS 18 beta 5 (as of writing, future versions unconfirmed) that causes a crash.
// This has been reported to Apple as FB14699941.
// Until this is fixed, we're rolling back to pre-iOS 16 behavior for this view.
// More information and discussion here: https://github.com/RevenueCat/purchases-ios/issues/4150
let iOSVersionWithCrash = OperatingSystemVersion(majorVersion: 18, minorVersion: 0, patchVersion: 0)
return ProcessInfo.processInfo.isOperatingSystemAtLeast(iOSVersionWithCrash)
}()

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
extension View {

Expand Down Expand Up @@ -84,20 +93,11 @@ extension View {
#endif
}

private static var isIOSVersionWithCrash: Bool {
// There is a bug in iOS 18 beta 5 (as of writing, future versions uncofirmed) that causes a crash.
// This has been reporte to Apple as FB14699941.
// Until this is fixed, we're rolling back to pre-iOS 16 behavior for this view.
// More information and discussion here: https://github.com/RevenueCat/purchases-ios/issues/4150
let iOSVersionWithCrash = OperatingSystemVersion(majorVersion: 18, minorVersion: 0, patchVersion: 0)
return ProcessInfo.processInfo.isOperatingSystemAtLeast(iOSVersionWithCrash)
}

@ViewBuilder
// @PublicForExternalTesting
func scrollableIfNecessary(_ axis: Axis = .vertical, enabled: Bool = true) -> some View {
if enabled {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *), !Self.isIOSVersionWithCrash {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *), !isIOSVersionWithCrash {
ViewThatFits(in: axis.scrollViewAxis) {
self

Expand All @@ -118,7 +118,7 @@ extension View {
@ViewBuilder
func scrollableIfNecessaryWhenAvailable(_ axis: Axis = .vertical, enabled: Bool = true) -> some View {
if enabled {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *), !Self.isIOSVersionWithCrash {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *), !isIOSVersionWithCrash {
ViewThatFits(in: axis.scrollViewAxis) {
self

Expand Down

0 comments on commit 201a0e3

Please sign in to comment.