-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from wordpress-mobile/issue/25-integrate-aztec…
…-ios-2 Integrate Aztec into our Aztec RN wrapper.
- Loading branch information
Showing
9 changed files
with
205 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Aztec | ||
import Foundation | ||
|
||
class RCTAztecView: Aztec.TextView { | ||
@objc var onContentSizeChange: RCTBubblingEventBlock? = nil | ||
|
||
// MARK - View Height: Match to content height | ||
|
||
override var contentSize: CGSize { | ||
didSet { | ||
contentSizeChanged() | ||
} | ||
} | ||
|
||
func contentSizeChanged() { | ||
let newSize = contentSize | ||
|
||
updateHeightToMatch(newSize.height) | ||
|
||
guard let onContentSizeChange = onContentSizeChange else { | ||
return | ||
} | ||
|
||
let body = packForRN(newSize, withName: "contentSize") | ||
onContentSizeChange(body) | ||
} | ||
|
||
func updateHeightToMatch(_ newHeight: CGFloat) { | ||
|
||
frame = CGRect(origin: frame.origin, | ||
size: CGSize(width: frame.width, height: newHeight)) | ||
} | ||
|
||
// MARK: - Native-to-RN Value Packing Logic | ||
|
||
func packForRN(_ size: CGSize, withName name: String) -> [AnyHashable: Any] { | ||
|
||
let size = ["width": size.width, | ||
"height": size.height] | ||
|
||
return [name: size] | ||
} | ||
|
||
// MARK: - Set & get Contents | ||
|
||
@objc func setContents(_ contents: NSString) { | ||
super.setHTML(contents as String) | ||
} | ||
|
||
@objc func getContents() -> NSString { | ||
return super.getHTML() as NSString | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#import <React/RCTViewManager.h> | ||
|
||
@interface RCT_EXTERN_REMAP_MODULE(RCTAztecView, RCTAztecViewManager, RCTViewManager) | ||
//RCT_REMAP_VIEW_PROPERTY(text, contents, NSString) | ||
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock) | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
@objc (RCTAztecViewManager) | ||
class RCTAztecViewManager: RCTViewManager { | ||
|
||
@objc override func view() -> UIView { | ||
let view = RCTAztecView( | ||
defaultFont: .systemFont(ofSize: 12), | ||
defaultParagraphStyle: .default, | ||
defaultMissingImage: UIImage()) | ||
|
||
view.backgroundColor = .cyan | ||
view.text = "Hello world!" | ||
|
||
return view | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.