Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit e0f3721

Browse files
author
Yuncong Zhang
committed
Update Text Input Sample.
1 parent eb751fe commit e0f3721

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

Runtime/widgets/editable_text.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public EditableText(TextEditingController controller, FocusNode focusNode, TextS
146146
this.textInputAction = textInputAction;
147147
this.textCapitalization = textCapitalization;
148148
this.cursorColor = cursorColor;
149-
this.backgroundCursorColor = backgroundCursorColor ?? Colors.transparent; // TODO: remove ??
149+
this.backgroundCursorColor = backgroundCursorColor ?? Colors.grey; // TODO: remove ??
150150
this.maxLines = maxLines;
151151
this.autofocus = autofocus;
152152
this.selectionColor = selectionColor;
@@ -243,9 +243,9 @@ public class EditableTextState : AutomaticKeepAliveClientWithTickerProviderState
243243
LayerLink _layerLink = new LayerLink();
244244
bool _didAutoFocus = false;
245245

246-
static readonly TimeSpan _fadeDuration = TimeSpan.FromMilliseconds(500);
246+
static readonly TimeSpan _fadeDuration = TimeSpan.FromMilliseconds(250);
247247

248-
static readonly TimeSpan _floatingCursorResetTime = TimeSpan.FromMilliseconds(150);
248+
static readonly TimeSpan _floatingCursorResetTime = TimeSpan.FromMilliseconds(125);
249249

250250
AnimationController _floatingCursorResetController;
251251

Samples/UIWidgetSample/TextInputSample.cs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
using Unity.UIWidgets.widgets;
99
using UnityEngine;
1010
using Color = Unity.UIWidgets.ui.Color;
11-
using TextStyle = Unity.UIWidgets.painting.TextStyle;
1211

1312
namespace UIWidgetsSample {
1413
public class TextInputSample : UIWidgetsSamplePanel {
15-
1614
class _TextInputSample : StatefulWidget {
1715
public readonly string title;
1816

@@ -25,12 +23,12 @@ public override State createState() {
2523
}
2624
}
2725

28-
protected override Widget createWidget() {
26+
protected override Widget createWidget() {
2927
return new WidgetsApp(
3028
home: new EditableInputTypeWidget(),
3129
pageRouteBuilder: this.pageRouteBuilder);
3230
}
33-
31+
3432

3533
class _TextInputSampleState : State<_TextInputSample> {
3634
TextEditingController titleController = new TextEditingController("");
@@ -138,7 +136,7 @@ public override State createState() {
138136
return new _EditableInputTypeWidgetState();
139137
}
140138
}
141-
139+
142140
class _EditableInputTypeWidgetState : State<EditableInputTypeWidget> {
143141
Widget rowWidgets(string title, Widget widget) {
144142
return new Container(
@@ -151,72 +149,83 @@ Widget rowWidgets(string title, Widget widget) {
151149
}
152150
));
153151
}
154-
152+
155153
void textSubmitted(string text) {
156154
Debug.Log($"text submitted {text}");
157155
}
158156

159157
List<Widget> buildInputs(bool unityKeyboard) {
160-
List<Widget> widgets = new List<Widget>();
158+
List<Widget> widgets = new List<Widget>();
161159
var style = new TextStyle();
162160
var cursorColor = new Color(0xFF000000);
163161
var selectionColor = new Color(0xFF6F6F6F);
164-
162+
165163
widgets.Add(this.rowWidgets("Default", new EditStateProvider(builder: ((buildContext, controller, node) =>
166-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, onSubmitted: this.textSubmitted
167-
, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls)))));
164+
new EditableText(controller, node, style, cursorColor, Colors.blue,
165+
selectionColor: selectionColor, onSubmitted: this.textSubmitted
166+
, unityTouchKeyboard: unityKeyboard,
167+
selectionControls: MaterialUtils.materialTextSelectionControls,
168+
cursorWidth: 5.0f, cursorRadius: Radius.circular(2.5f), cursorOpacityAnimates: true, paintCursorAboveText: true)))));
168169

169170
widgets.Add(this.rowWidgets("Multiple Line", new EditStateProvider(
170171
builder: ((buildContext, controller, node) =>
171-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, maxLines: 4,
172+
new EditableText(controller, node, style, cursorColor, Colors.transparent,
173+
selectionColor: selectionColor, maxLines: 4,
172174
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
173175
selectionControls: MaterialUtils.materialTextSelectionControls)))));
174176

175177
widgets.Add(this.rowWidgets("ObscureText", new EditStateProvider(
176178
builder: ((buildContext, controller, node) =>
177-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, obscureText: true,
178-
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
179+
new EditableText(controller, node, style, cursorColor, Colors.transparent,
180+
selectionColor: selectionColor, obscureText: true,
181+
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
179182
selectionControls: MaterialUtils.materialTextSelectionControls)))));
180183

181184
widgets.Add(this.rowWidgets("Number", new EditStateProvider(builder: ((buildContext, controller, node) =>
182-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.number,
185+
new EditableText(controller, node, style, cursorColor, Colors.transparent,
186+
selectionColor: selectionColor, keyboardType: TextInputType.number,
183187
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
184188
selectionControls: MaterialUtils.materialTextSelectionControls)))));
185189

186190
widgets.Add(this.rowWidgets("Phone", new EditStateProvider(builder: ((buildContext, controller, node) =>
187-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.phone,
191+
new EditableText(controller, node, style, cursorColor, Colors.transparent,
192+
selectionColor: selectionColor, keyboardType: TextInputType.phone,
188193
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
189194
selectionControls: MaterialUtils.materialTextSelectionControls)))));
190195

191196
widgets.Add(this.rowWidgets("Email", new EditStateProvider(builder: ((buildContext, controller, node) =>
192-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.emailAddress,
197+
new EditableText(controller, node, style, cursorColor, Colors.transparent,
198+
selectionColor: selectionColor, keyboardType: TextInputType.emailAddress,
193199
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
194200
selectionControls: MaterialUtils.materialTextSelectionControls)))));
195201

196202
widgets.Add(this.rowWidgets("Url", new EditStateProvider(builder: ((buildContext, controller, node) =>
197-
new EditableText(controller, node, style, cursorColor, Colors.transparent, selectionColor: selectionColor, keyboardType: TextInputType.url,
203+
new EditableText(controller, node, style, cursorColor, Colors.transparent,
204+
selectionColor: selectionColor, keyboardType: TextInputType.url,
198205
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
199206
selectionControls: MaterialUtils.materialTextSelectionControls)))));
200207
return widgets;
201208
}
202-
209+
203210
public override Widget build(BuildContext context) {
204211
List<Widget> widgets = new List<Widget>();
205-
206-
widgets.Add(new Text("UIWidgets Touch Keyboard", style: new TextStyle(fontSize:20, height:2.0f), textAlign: TextAlign.center));
212+
213+
widgets.Add(new Text("UIWidgets Touch Keyboard", style: new TextStyle(fontSize: 20, height: 2.0f),
214+
textAlign: TextAlign.center));
207215
widgets.AddRange(this.buildInputs(false));
208-
209-
widgets.Add(new Text("Unity Touch Keyboard", style: new TextStyle(fontSize:20, height:2.0f), textAlign: TextAlign.center));
216+
217+
widgets.Add(new Text("Unity Touch Keyboard", style: new TextStyle(fontSize: 20, height: 2.0f),
218+
textAlign: TextAlign.center));
210219
widgets.AddRange(this.buildInputs(true));
211-
220+
212221
return new Container(
213222
padding: EdgeInsets.all(12),
214223
child: new SingleChildScrollView(child: new Column(
215-
crossAxisAlignment: CrossAxisAlignment.stretch,
216-
children: widgets)));
224+
crossAxisAlignment: CrossAxisAlignment.stretch,
225+
children: widgets)));
217226
}
218-
219227
}
228+
220229
public class EditStateProvider : StatefulWidget {
221230
public delegate EditableText EditableBuilder(BuildContext context,
222231
TextEditingController controller, FocusNode focusNode);

0 commit comments

Comments
 (0)