Skip to content

Commit

Permalink
Remove force unwrap (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Aug 23, 2024
1 parent fa41b70 commit 7ed9fcd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions DemoApp/DemoApp/TestViews/PreviewVariants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ extension NamedViewModifier {
.init(name: "XXL Text Size", value: { $0.dynamicTypeSize(.xxxLarge) })
}

@available(macOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
@available(tvOS, unavailable)
static var accessibility: NamedViewModifier {
.init(name: "Accessibility", value: { $0.emergeAccessibility(true) })
}
Expand All @@ -81,6 +85,10 @@ extension NamedViewModifier {
extension [NamedViewModifier] {
/// The default named view modifiers in a ``PreviewVariants``.
static var previewDefault: [NamedViewModifier] {
#if os(iOS)
[.unmodified, .darkMode, .xxlTextSize, .rtl, .accessibility, .landscape]
#else
[.unmodified, .darkMode, .rtl]
#endif
}
}
4 changes: 4 additions & 0 deletions DemoApp/DemoApp/TestViews/RideShareButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ struct RideShareButtonView_Previews: PreviewProvider {
.previewDisplayName("Ride Share Button View - Light")
// This should never show as a diff
.emergeSnapshotPrecision(0.0)
#if os(iOS)
.emergeRenderingMode(.coreAnimation)
#endif

RideShareButtonView(title: "Request Ride") {
print("Button tapped")
Expand All @@ -52,7 +54,9 @@ struct RideShareButtonView_Previews: PreviewProvider {
.previewLayout(.sizeThatFits)
.padding()
.previewDisplayName("Ride Share Button View - Light")
#if os(iOS)
.emergeRenderingMode(.coreAnimation)
.emergeAccessibility(true)
#endif
}
}
5 changes: 4 additions & 1 deletion Sources/SnapshotPreferences/AccessibiltyPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ struct AccessibilityPreferenceKey: PreferenceKey {
}

extension View {
@available(iOS 15, *)
@available(macOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
@available(tvOS, unavailable)
public func emergeAccessibility(_ enabled: Bool?) -> some View {
preference(key: AccessibilityPreferenceKey.self, value: enabled)
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/SnapshotPreferences/RenderingModePreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ struct RenderingModePreferenceKey: PreferenceKey {
}

extension View {
@available(iOS 15, *)
@available(macOS, unavailable)
@available(watchOS, unavailable)
@available(visionOS, unavailable)
@available(tvOS, unavailable)
public func emergeRenderingMode(_ renderingMode: EmergeRenderingMode?) -> some View {
preference(key: RenderingModePreferenceKey.self, value: renderingMode?.rawValue)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SnapshotPreviewsCore/AppKitRenderingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ final class AppKitContainer: NSHostingController<EmergeModifierView>, ScrollExpa

if !supportsExpansion {
// Reset the scroll point
(firstScrollView as! NSScrollView).documentView!.scroll(NSPoint(x: 0, y: 0))
(firstScrollView as? NSScrollView)?.documentView?.scroll(NSPoint(x: 0, y: 0))
}

updateHeight {
Expand Down

0 comments on commit 7ed9fcd

Please sign in to comment.