Skip to content

Commit

Permalink
Fixed TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
vkjr committed Oct 9, 2018
1 parent 3737d0a commit c571cf7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 15 additions & 1 deletion ReactQt/runtime/src/qml/ReactTextInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Item {
property var textInputManager: null
property var textInputControl: null

property string p_text: textInputControl ? textInputControl.text : ""
property string p_text
property color p_color
property bool p_multiline: false
property bool p_onChange: false
Expand All @@ -30,9 +30,23 @@ Item {


property var flexbox: React.Flexbox {control: textInputRoot; viewManager: textInputManager}
property bool sendTextChanged: true

objectName: p_nativeID

onP_textChanged: {
if(textInputControl) {
sendTextChanged = false

var cursorPos = textInputControl.cursorPosition
textInputControl.text = p_text
cursorPos = Math.min(cursorPos+1, p_text.length)
textInputControl.cursorPosition = cursorPos

sendTextChanged = true
}
}

onP_fontWeightChanged: {
switch(p_fontWeight) {
case "100": p_fontWeightEnum = Font.Thin; break;
Expand Down
8 changes: 6 additions & 2 deletions ReactQt/runtime/src/qml/ReactTextInputArea.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import "../js/utils.js" as Utils
Flickable {
id: textField
property var textInputRoot: parent
property alias cursorPosition: textArea.cursorPosition
property alias text: textArea.text
anchors.fill: textInputRoot
ScrollBar.vertical: ScrollBar {}

TextArea.flickable: TextArea {

id: textArea
text: textInputRoot.p_text
color: textInputRoot.p_color
placeholderText: textInputRoot.p_placeholderText
selectionColor: textInputRoot.p_selectionColor
Expand All @@ -37,7 +37,11 @@ Flickable {
radius: textInputRoot.p_borderRadius
}

onTextChanged: textInputRoot.textInputManager.sendTextEditedToJs(textField)
onTextChanged: {
if(textInputRoot.sendTextChanged) {
textInputRoot.textInputManager.sendTextEditedToJs(textField)
}
}
onCursorPositionChanged: textInputRoot.textInputManager.sendSelectionChangeToJs(textField)
Keys.onPressed: textInputManager.sendOnKeyPressToJs(textField,
textInputRoot.keyText(event.key, event.text),
Expand Down
7 changes: 5 additions & 2 deletions ReactQt/runtime/src/qml/ReactTextInputField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ TextField {
property var textInputRoot: parent

anchors.fill: textInputRoot
text: textInputRoot.p_text
color: textInputRoot.p_color
placeholderText: textInputRoot.p_placeholderText
selectionColor: textInputRoot.p_selectionColor
Expand All @@ -32,7 +31,11 @@ TextField {
radius: textInputRoot.p_borderRadius
}

onTextChanged: textInputManager.sendTextEditedToJs(textField)
onTextChanged: {
if(textInputRoot.sendTextChanged) {
textInputRoot.textInputManager.sendTextEditedToJs(textField)
}
}
onCursorPositionChanged: textInputManager.sendSelectionChangeToJs(textField)
onAccepted: textInputManager.sendOnSubmitEditingToJs(textField)
onEditingFinished: textInputManager.sendOnEndEditingToJs(textField)
Expand Down

0 comments on commit c571cf7

Please sign in to comment.