Skip to content

💄 Add fit to readable content layout guide#151

Merged
olejnjak merged 7 commits intomainfrom
swiftui/layout-guides
Jan 21, 2025
Merged

💄 Add fit to readable content layout guide#151
olejnjak merged 7 commits intomainfrom
swiftui/layout-guides

Conversation

@komkovla
Copy link
Contributor

@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
@olejnjak
Copy link
Member

@komkovla

@komkovla komkovla force-pushed the swiftui/layout-guides branch from 2a69ada to 4fae358 Compare January 21, 2025 09:41
@komkovla komkovla force-pushed the swiftui/layout-guides branch from 2deae0d to 5fb412b Compare January 21, 2025 09:52
@komkovla komkovla force-pushed the swiftui/layout-guides branch from 8aa4c6f to 702ed1c Compare January 21, 2025 10:08
@komkovla komkovla force-pushed the swiftui/layout-guides branch from 702ed1c to 09b39de Compare January 21, 2025 10:10
Copy link
Member

@olejnjak olejnjak left a comment

Choose a reason for hiding this comment

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

LGTM!

@olejnjak olejnjak merged commit dae31ae into main Jan 21, 2025
6 checks passed
@olejnjak olejnjak deleted the swiftui/layout-guides branch January 21, 2025 12:18
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