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

Fix perception check in iOS 15. #38

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 348,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -405,7 405,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand All @@ -430,7 430,6 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -459,7 458,6 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
22 changes: 16 additions & 6 deletions Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 41,24 @@ struct ContentView: View {
}
}
.sheet(isPresented: $model.isPresentingSheet) {
WithPerceptionTracking {
Form {
Text(model.count.description)
Button("Decrement") { model.decrementButtonTapped() }
Button("Increment") { model.incrementButtonTapped() }
if #available(iOS 16.0, *) {
WithPerceptionTracking {
Form {
Text(model.count.description)
Button("Decrement") { model.decrementButtonTapped() }
Button("Increment") { model.incrementButtonTapped() }
}
.presentationDetents([.medium])
}
} else {
WithPerceptionTracking {
Form {
Text(model.count.description)
Button("Decrement") { model.decrementButtonTapped() }
Button("Increment") { model.incrementButtonTapped() }
}
Comment on lines 44 to 59

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we'd have to do in our code to if we're supporting iOS 15?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimRoepcke No, this if #available check is only for .presentationDetents([.medium]), which is iOS 16 .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derp. (despite WithPerceptionTracking, my 👀 did not perceive or track that .presentationDetents line)

}
}
.presentationDetents([.medium])
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Perception/PerceptionRegistrar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 268,9 @@ extension PerceptionRegistrar: Hashable {
}
fileprivate var isActionClosure: Bool {
var view = self[...].utf8
guard
view.starts(with: "closure #".utf8) || view.starts(with: "implicit closure #".utf8)
else { return false }
view = view.drop(while: { $0 != .init(ascii: "#") })
view = view.dropFirst()
view = view.drop(while: { $0 >= .init(ascii: "0") && $0 <= .init(ascii: "9") })
view = view.drop(while: { $0 != .init(ascii: "-") })
return view.starts(with: "-> () in ".utf8)
}
Expand Down
Loading