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

💄 Add fit to readable content layout guide #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

komkovla
Copy link

@komkovla komkovla commented Dec 6, 2024

Add SwiftUI Layout Guides

Description

Adds utilities for working with SwiftUI layout margins and readable content guides. This implementation is based on the work from swiftui-layout-guides and provides a clean API for handling layout constraints in SwiftUI.

Key Features:

  • WithLayoutMargins view for accessing layout margins and readable content insets
  • View modifiers for fitting content to readable width or layout margins width:
    • .fitToReadableContentWidth()
    • .fitToLayoutMarginsWidth()
  • Environment values for accessing layout metrics:
    • layoutMarginsInsets
    • readableContentInsets

Usage Example

struct ContentView: View {
  var body: some View {
    Text("Hello World")
    .frame(maxWidth: .infinity)
    .fitToReadableContentWidth() // Constrains text to readable width
  }
}

Platform Support

  • iOS
  • tvOS
  • macOS (partial support)
  • watchOS (partial support)

Testing

Includes preview examples demonstrating usage in:

  • ScrollView
  • List with different styles
  • Split view layouts

Attribution

Original implementation inspired by @tgrapperon's swiftui-layout-guides library.

@komkovla komkovla requested a review from olejnjak December 6, 2024 10:51
@komkovla komkovla self-assigned this Dec 6, 2024
@komkovla komkovla force-pushed the swiftui/layout-guides branch from 7448d38 to b6bafe3 Compare December 6, 2024 12:25
@available(
watchOS, deprecated: 9999.0, message: "Use the `.fitToReadableContentWidth` modifier instead."
)
public struct FitReadableContentWidth<Content>: View where Content: View {
Copy link
Member

Choose a reason for hiding this comment

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

I would rather not add a code that is already marked as deprecated, can we remove it?

@available(
watchOS, deprecated: 9999.0, message: "Use the `.fitToLayoutMarginsWidth` modifier instead."
)
public struct FitLayoutMarginsWidth<Content>: View where Content: View {
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

}
}

struct LayoutGuidesModifier: ViewModifier {
Copy link
Member

Choose a reason for hiding this comment

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

I would rather keep top level objects explicitly state that they are internal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants