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

Renames additionalInset to safeAreaInset #24

Merged
merged 3 commits into from
May 7, 2022
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
40 changes: 13 additions & 27 deletions Sources/Runestone/TextView/TextInput/LayoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ final class LayoutManager {
}
}
}
var scrollViewSafeAreaInsets: UIEdgeInsets = .zero {
didSet {
if scrollViewSafeAreaInsets != oldValue {
if isLineWrappingEnabled {
invalidateContentSize()
invalidateLines()
}
}
}
}
var viewport: CGRect = .zero
var contentSize: CGSize {
return CGSize(width: contentWidth, height: contentHeight)
Expand Down Expand Up @@ -225,7 +215,7 @@ final class LayoutManager {
// MARK: - Sizing
private var contentWidth: CGFloat {
if isLineWrappingEnabled {
return scrollViewWidth - scrollViewSafeAreaInsets.left - scrollViewSafeAreaInsets.right
return scrollViewWidth - safeAreaInset.left - safeAreaInset.right
} else {
return ceil(textContentWidth + leadingLineSpacing + textContainerInset.right + maximumLineBreakSymbolWidth)
}
Expand Down Expand Up @@ -287,7 +277,7 @@ final class LayoutManager {
private var lineIDTrackingWidth: DocumentLineNodeID?
private var maximumLineWidth: CGFloat {
if isLineWrappingEnabled {
return scrollViewWidth - leadingLineSpacing - textContainerInset.right - scrollViewSafeAreaInsets.left - scrollViewSafeAreaInsets.right
return scrollViewWidth - leadingLineSpacing - textContainerInset.right - safeAreaInset.left - safeAreaInset.right
} else {
// Rendering multiple very long lines is very expensive. In order to let the editor remain useable,
// we set a very high maximum line width when line wrapping is disabled.
Expand All @@ -301,18 +291,14 @@ final class LayoutManager {
let height = viewport.height + textContainerInset.top + textContainerInset.bottom
return CGRect(x: x, y: y, width: width, height: height)
}
private var additionalInset: UIEdgeInsets {
if let editorView = scrollView {
let adjustContentInset = editorView.adjustedContentInset
let contentInset = editorView.contentInset
let top = adjustContentInset.top - contentInset.top
let left = adjustContentInset.left - contentInset.left
let bottom = adjustContentInset.bottom - contentInset.bottom
let right = adjustContentInset.right - contentInset.right
return UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
} else {
return .zero
}
private var safeAreaInset: UIEdgeInsets {
let adjustContentInset = scrollView?.adjustedContentInset ?? .zero
let contentInset = scrollView?.contentInset ?? .zero
let topInset = adjustContentInset.top - contentInset.top
let leftInset = adjustContentInset.left - contentInset.left
let bottomInset = adjustContentInset.bottom - contentInset.bottom
let rightInset = adjustContentInset.right - contentInset.right
return UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
}

// MARK: - Rendering
Expand Down Expand Up @@ -594,15 +580,15 @@ extension LayoutManager {
}

private func layoutGutter() {
let totalGutterWidth = additionalInset.left + gutterWidth
let totalGutterWidth = safeAreaInset.left + gutterWidth
gutterContainerView.frame = CGRect(x: viewport.minX, y: 0, width: totalGutterWidth, height: contentSize.height)
gutterBackgroundView.frame = CGRect(x: 0, y: viewport.minY, width: totalGutterWidth, height: viewport.height)
lineNumbersContainerView.frame = CGRect(x: 0, y: 0, width: totalGutterWidth, height: contentSize.height)
}

private func layoutLineSelection() {
if let rect = getLineSelectionRect() {
let totalGutterWidth = additionalInset.left + gutterWidth
let totalGutterWidth = safeAreaInset.left + gutterWidth
gutterSelectionBackgroundView.frame = CGRect(x: 0, y: rect.minY, width: totalGutterWidth, height: rect.height)
let lineSelectionBackgroundOrigin = CGPoint(x: viewport.minX + totalGutterWidth, y: rect.minY)
let lineSelectionBackgroundSize = CGSize(width: scrollViewWidth - gutterWidth, height: rect.height)
Expand Down Expand Up @@ -753,7 +739,7 @@ extension LayoutManager {
}
let lineController = lineController(for: line)
let fontLineHeight = theme.font.lineHeight
let xPosition = additionalInset.left + gutterLeadingPadding
let xPosition = safeAreaInset.left + gutterLeadingPadding
var yPosition = textContainerInset.top + line.yPosition
if lineController.numberOfLineFragments > 1 {
// There are more than one line fragments, so we align the line number number at the top.
Expand Down
8 changes: 0 additions & 8 deletions Sources/Runestone/TextView/TextInput/TextInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,6 @@ final class TextInputView: UIView, UITextInput {
layoutManager.scrollViewWidth = newValue
}
}
var scrollViewSafeAreaInsets: UIEdgeInsets {
get {
return layoutManager.scrollViewSafeAreaInsets
}
set {
layoutManager.scrollViewSafeAreaInsets = newValue
}
}
var contentSize: CGSize {
return layoutManager.contentSize
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/Runestone/TextView/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ public final class TextView: UIScrollView {
backgroundColor = .white
textInputView.delegate = self
textInputView.scrollView = self
textInputView.scrollViewSafeAreaInsets = safeAreaInsets
editableTextInteraction.textInput = textInputView
nonEditableTextInteraction.textInput = textInputView
editableTextInteraction.delegate = self
Expand Down Expand Up @@ -557,7 +556,6 @@ public final class TextView: UIScrollView {
/// Called when the safe area of the view changes.
override public func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
textInputView.scrollViewSafeAreaInsets = safeAreaInsets
contentSize = preferredContentSize
layoutIfNeeded()
}
Expand Down