on xenial help sign in
Refactor textarea visible to make it more flexible.

Move inputmethodVisible proeprty from rating & comment input to previewListRow to avoid code duplication and make it more flexible.

commitcece9cce61a6ab82f6c101805de86733e083eb38 authorGary.Wzl <Gary.Wang@canonical.com> dateMon 17 Aug 2015, 21:15 (11 years ago) parent6cd57b2
3 files changed+49−44
qml/Dash/Previews/Preview.qml+49 qml/Dash/Previews/PreviewCommentInput.qml−22 qml/Dash/Previews/PreviewRatingInput.qml−22
qml/Dash/Previews/Preview.qml+49
@@ -61,8 +61,24 @@ Item {
6161 property real columnWidth: width / columns
6262
6363 Repeater {
64+ id: repeater;
6465 model: previewModel
6566
67+ function findChild(obj, objectName) {
68+ var childs = new Array(0);
69+ childs.push(obj)
70+ while (childs.length > 0) {
71+ if (childs[0].objectName === objectName) {
72+ return childs[0]
73+ }
74+ for (var i in childs[0].data) {
75+ childs.push(childs[0].data[i])
76+ }
77+ childs.splice(0, 1);
78+ }
79+ return null;
80+ }
81+
6682 delegate: ListView {
6783 id: column
6884 objectName: "previewListRow" + index
@@ -70,6 +86,39 @@ Item {
7086 width: row.columnWidth
7187 spacing: row.spacing
7288 bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
89+
90+ readonly property int inputMethodMargin: 30;
91+ property bool inputMethodVisible: Qt.inputMethod.visible;
92+ onInputMethodVisibleChanged: {
93+ if (!inputMethodVisible)
94+ return;
95+
96+ var textArea = null;
97+ var contentItem = column.contentItem;
98+
99+ var reviewTextArea = repeater.findChild(contentItem, "reviewTextArea");
100+ if (reviewTextArea !== null && reviewTextArea.activeFocus) {
101+ textArea = reviewTextArea;
102+ }
103+
104+ if (textArea === null) {
105+ var commentTextArea = repeater.findChild(contentItem, "commentTextArea");
106+ if (commentTextArea !== null && commentTextArea.activeFocus) {
107+ textArea = commentTextArea;
108+ }
109+ }
110+
111+ if (textArea === null)
112+ return;
113+
114+ var textAreaPos = textArea.mapToItem(column, 0, 0);
115+ var textAreaGlobalHeight = textAreaPos.y + textArea.implicitHeight
116+ + column.height / 2.0;
117+
118+ if (textAreaGlobalHeight > column.height) {
119+ column.contentY += textAreaGlobalHeight - column.height + inputMethodMargin;
120+ }
121+ }
73122
74123 model: columnModel
75124 cacheBuffer: height
qml/Dash/Previews/PreviewCommentInput.qml−22
@@ -39,28 +39,6 @@ PreviewWidget {
3939 id: commentTextArea
4040 objectName: "commentTextArea"
4141
42− property var flickableItem: null;
43− property bool inputMethodVisible: Qt.inputMethod.visible;
44− onInputMethodVisibleChanged: {
45− //A workaround to automatically move textArea up on u-touch
46− if (inputMethodVisible && commentTextArea.activeFocus) {
47− var obj = root.parent.parent.parent;
48− if (obj.objectName.indexOf("previewListRow") === 0) {
49− flickableItem = obj;
50−
51− var textAreaPos = commentTextArea.mapToItem(flickableItem, 0, 0);
52− var textAreaGlobalHeight = textAreaPos.y + commentTextArea.implicitHeight
53− + flickableItem.height / 2.0;
54−
55− if (textAreaGlobalHeight > flickableItem.height) {
56− flickableItem.contentY += textAreaGlobalHeight - flickableItem.height;
57− }
58− }
59− } else {
60− flickableItem = null;
61− }
62− }
63−
6442 anchors {
6543 top: parent.top
6644 left: parent.left
qml/Dash/Previews/PreviewRatingInput.qml−22
@@ -144,28 +144,6 @@ PreviewWidget {
144144 id: reviewTextArea
145145 objectName: "reviewTextArea"
146146
147− property var flickableItem: null;
148− property bool inputMethodVisible: Qt.inputMethod.visible;
149− onInputMethodVisibleChanged: {
150− //A workaround to automatically move textArea up on u-touch
151− if (inputMethodVisible && reviewTextArea.activeFocus) {
152− var obj = root.parent.parent.parent;
153− if (obj.objectName.indexOf("previewListRow") === 0) {
154− flickableItem = obj;
155−
156− var textAreaPos = reviewSubmitContainer.mapToItem(flickableItem, 0, 0);
157− var textAreaGlobalHeight = textAreaPos.y + reviewSubmitContainer.implicitHeight
158− + flickableItem.height / 2.0;
159−
160− if (textAreaGlobalHeight > flickableItem.height) {
161− flickableItem.contentY += textAreaGlobalHeight - flickableItem.height;
162− }
163− }
164− } else {
165− flickableItem = null;
166− }
167− }
168−
169147 anchors {
170148 top: parent.top
171149 left: parent.left