Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Take into account safe area insets
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezreal committed Jan 21, 2021
1 parent 98b392d commit 8d66e40
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/AttributedText/AttributedText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
}

public var body: some View {
GeometryReader { proxy in
GeometryReader { geometry in
TextViewWrapper(attributedText: attributedText, store: store)
.preference(key: ContainerSizePreference.self, value: proxy.size)
.preference(key: ContainerSizePreference.self, value: geometry.maxSize)
}
.onPreferenceChange(ContainerSizePreference.self) { value in
store.onContainerSizeChange(value)
Expand All @@ -28,6 +28,16 @@
}
}

@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)
private extension GeometryProxy {
var maxSize: CGSize {
CGSize(
width: size.width - safeAreaInsets.leading - safeAreaInsets.trailing,
height: size.height - safeAreaInsets.top - safeAreaInsets.bottom
)
}
}

@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)
private struct ContainerSizePreference: PreferenceKey {
static var defaultValue: CGSize?
Expand Down

0 comments on commit 8d66e40

Please sign in to comment.