Skip to content

Commit

Permalink
Merge pull request #50 from wordpress-mobile/try/add-onEnter-callback…
Browse files Browse the repository at this point in the history
…-to-ios

Adds an onEnter callback to iOS.
  • Loading branch information
diegoreymendez authored Sep 6, 2018
2 parents 79388a6 + e9dfd53 commit b8cec63
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class Editor extends Component {
placeholderTextColor = {'lightgray'} // See http://facebook.github.io/react-native/docs/colors
onContentSizeChange= { onContentSizeChange }
onChange= {(event) => console.log(event.nativeEvent) }
onEnter= {(event) => console.log("asta") }
onEndEditing= {(event) => console.log(event.nativeEvent) }
onActiveFormatsChange = { this.onActiveFormatsChange }
color = {'black'}
Expand Down
11 changes: 10 additions & 1 deletion ios/RNTAztecView/RCTAztecView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit

class RCTAztecView: Aztec.TextView {
@objc var onChange: RCTBubblingEventBlock? = nil
@objc var onEnter: RCTBubblingEventBlock? = nil
@objc var onContentSizeChange: RCTBubblingEventBlock? = nil

@objc var onActiveFormatsChange: RCTBubblingEventBlock? = nil
Expand Down Expand Up @@ -61,8 +62,14 @@ class RCTAztecView: Aztec.TextView {
// MARK: - Edits

open override func insertText(_ text: String) {
guard text != "\n" else {
onEnter?([:])
return
}

super.insertText(text)
updatePlaceholderVisibility()

if let onChange = onChange {
let text = packForRN(getHTML(), withName: "text")
onChange(text)
Expand All @@ -72,6 +79,7 @@ class RCTAztecView: Aztec.TextView {
open override func deleteBackward() {
super.deleteBackward()
updatePlaceholderVisibility()

if let onChange = onChange {
let text = packForRN(getHTML(), withName: "text")
onChange(text)
Expand All @@ -81,7 +89,8 @@ class RCTAztecView: Aztec.TextView {
// MARK: - Native-to-RN Value Packing Logic

func packForRN(_ text: String, withName name: String) -> [AnyHashable: Any] {
return [name: text, "eventCount": 1]
return [name: text,
"eventCount": 1]
}

func packForRN(_ size: CGSize, withName name: String) -> [AnyHashable: Any] {
Expand Down
1 change: 1 addition & 0 deletions ios/RNTAztecView/RCTAztecViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ @implementation RCTAztecViewManager (RCTExternModule)
RCT_REMAP_VIEW_PROPERTY(text, contents, NSDictionary)
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onEnter, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onActiveFormatsChange, RCTBubblingEventBlock)

Expand Down
1 change: 1 addition & 0 deletions src/AztecView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AztecView extends React.Component {
minImagesWidth: PropTypes.number,
onChange: PropTypes.func,
onContentSizeChange: PropTypes.func,
onEnter: PropTypes.func,
onScroll: PropTypes.func,
onActiveFormatsChange: PropTypes.func,
...ViewPropTypes, // include the default view properties
Expand Down

0 comments on commit b8cec63

Please sign in to comment.