Skip to content

Commit

Permalink
Merge pull request #33 from wordpress-mobile/try/improve-sizing-mecha…
Browse files Browse the repository at this point in the history
…nism

iOS: Improves the text view automatic sizing mechanism.
  • Loading branch information
diegoreymendez authored Jul 20, 2018
2 parents 395b22b + 54f54db commit d80e220
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions ios/RNTAztecView/RCTAztecView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,27 @@ class RCTAztecView: Aztec.TextView {
private var previousContentSize: CGSize = .zero

// MARK - View Height: Match to content height

override func layoutSubviews() {
super.layoutSubviews()

updateContentSizeInRN()
}

func updateContentSizeInRN() {
let newSize = contentSize
let newSize = sizeThatFits(frame.size)

guard previousContentSize != newSize else {
return
guard previousContentSize != newSize,
let onContentSizeChange = onContentSizeChange else {
return
}

previousContentSize = newSize
updateHeightToMatch(newSize.height)

guard let onContentSizeChange = onContentSizeChange else {
return
}

let body = packForRN(newSize, withName: "contentSize")
onContentSizeChange(body)
}

func updateHeightToMatch(_ newHeight: CGFloat) {
bounds = CGRect(origin: .zero, size: CGSize(width: frame.width, height: newHeight))
}

// MARK: - Native-to-RN Value Packing Logic

func packForRN(_ size: CGSize, withName name: String) -> [AnyHashable: Any] {
Expand Down
2 changes: 1 addition & 1 deletion ios/RNTAztecView/RCTAztecViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class RCTAztecViewManager: RCTViewManager {
defaultParagraphStyle: .default,
defaultMissingImage: UIImage())

view.isScrollEnabled = true
view.isScrollEnabled = false

view.backgroundColor = .yellow
view.text = "Hello world!"
Expand Down

0 comments on commit d80e220

Please sign in to comment.