Skip to content

Commit

Permalink
Full GIF Insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
zlshames committed Aug 31, 2022
1 parent ffccd96 commit 1f6c4a4
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 4 deletions.
33 changes: 33 additions & 0 deletions packages/flutter/lib/src/cupertino/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class CupertinoTextField extends StatefulWidget {
this.maxLength,
this.maxLengthEnforcement,
this.onChanged,
this.onContentCommitted,
this.onEditingComplete,
this.onSubmitted,
this.inputFormatters,
Expand All @@ -272,6 +273,7 @@ class CupertinoTextField extends StatefulWidget {
this.restorationId,
this.scribbleEnabled = true,
this.enableIMEPersonalizedLearning = true,
List<String> contentCommitMimeTypes = const <String>[],
}) : assert(textAlign != null),
assert(readOnly != null),
assert(autofocus != null),
Expand Down Expand Up @@ -309,8 +311,19 @@ class CupertinoTextField extends StatefulWidget {
'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.',
),
assert(enableIMEPersonalizedLearning != null),
assert(contentCommitMimeTypes != null),
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText),
contentCommitMimeTypes = contentCommitMimeTypes.isEmpty
? onContentCommitted == null ? const <String>[] : const <String>[
'image/png',
'image/bmp',
'image/jpg',
'image/tiff',
'image/gif',
'image/jpeg',
'image/webp'
] : contentCommitMimeTypes,
toolbarOptions = toolbarOptions ??
(obscureText
? (readOnly
Expand Down Expand Up @@ -409,6 +422,7 @@ class CupertinoTextField extends StatefulWidget {
this.maxLength,
this.maxLengthEnforcement,
this.onChanged,
this.onContentCommitted,
this.onEditingComplete,
this.onSubmitted,
this.inputFormatters,
Expand All @@ -428,6 +442,7 @@ class CupertinoTextField extends StatefulWidget {
this.scrollController,
this.scrollPhysics,
this.autofillHints = const <String>[],
this.contentCommitMimeTypes = const <String>[],
this.clipBehavior = Clip.hardEdge,
this.restorationId,
this.scribbleEnabled = true,
Expand Down Expand Up @@ -470,6 +485,7 @@ class CupertinoTextField extends StatefulWidget {
),
assert(clipBehavior != null),
assert(enableIMEPersonalizedLearning != null),
assert(contentCommitMimeTypes != null),
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText),
toolbarOptions = toolbarOptions ??
Expand Down Expand Up @@ -680,6 +696,9 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.onChanged}
final ValueChanged<String>? onChanged;

/// {@macro flutter.widgets.editableText.contentCommitMimeTypes}
final ValueChanged<CommittedContent>? onContentCommitted;

/// {@macro flutter.widgets.editableText.onEditingComplete}
final VoidCallback? onEditingComplete;

Expand Down Expand Up @@ -778,6 +797,9 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning}
final bool enableIMEPersonalizedLearning;

/// {@macro flutter.services.TextInputConfiguration.contentCommitMimeTypes}
final List<String> contentCommitMimeTypes;

@override
State<CupertinoTextField> createState() => _CupertinoTextFieldState();

Expand Down Expand Up @@ -821,6 +843,16 @@ class CupertinoTextField extends StatefulWidget {
properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.hardEdge));
properties.add(DiagnosticsProperty<bool>('scribbleEnabled', scribbleEnabled, defaultValue: true));
properties.add(DiagnosticsProperty<bool>('enableIMEPersonalizedLearning', enableIMEPersonalizedLearning, defaultValue: true));
properties.add(DiagnosticsProperty<List<String>>('contentCommitMimeTypes', contentCommitMimeTypes,
defaultValue: onContentCommitted == null ? null : <String>[
'image/png',
'image/bmp',
'image/jpg',
'image/tiff',
'image/gif',
'image/jpeg',
'image/webp'
]));
}
}

Expand Down Expand Up @@ -1260,6 +1292,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
selectionControls: widget.selectionEnabled
? textSelectionControls : null,
onChanged: widget.onChanged,
onContentCommitted: widget.onContentCommitted,
onSelectionChanged: _handleSelectionChanged,
onEditingComplete: widget.onEditingComplete,
onSubmitted: widget.onSubmitted,
Expand Down
30 changes: 30 additions & 0 deletions packages/flutter/lib/src/material/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class TextField extends StatefulWidget {
this.maxLength,
this.maxLengthEnforcement,
this.onChanged,
this.onContentCommitted,
this.onEditingComplete,
this.onSubmitted,
this.onAppPrivateCommand,
Expand All @@ -329,6 +330,7 @@ class TextField extends StatefulWidget {
this.restorationId,
this.scribbleEnabled = true,
this.enableIMEPersonalizedLearning = true,
List<String> contentCommitMimeTypes = const <String>[],
}) : assert(textAlign != null),
assert(readOnly != null),
assert(autofocus != null),
Expand Down Expand Up @@ -364,8 +366,19 @@ class TextField extends StatefulWidget {
),
assert(clipBehavior != null),
assert(enableIMEPersonalizedLearning != null),
assert(contentCommitMimeTypes != null),
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText),
contentCommitMimeTypes = contentCommitMimeTypes.isEmpty
? (onContentCommitted == null ? const <String>[] : const <String>[
'image/png',
'image/bmp',
'image/jpg',
'image/tiff',
'image/gif',
'image/jpeg',
'image/webp'
]) : contentCommitMimeTypes,
toolbarOptions = toolbarOptions ??
(obscureText
? (readOnly
Expand Down Expand Up @@ -575,6 +588,9 @@ class TextField extends StatefulWidget {
/// which are more specialized input change notifications.
final ValueChanged<String>? onChanged;

/// {@macro flutter.widgets.editableText.onContentCommitted}
final ValueChanged<CommittedContent>? onContentCommitted;

/// {@macro flutter.widgets.editableText.onEditingComplete}
final VoidCallback? onEditingComplete;

Expand Down Expand Up @@ -766,6 +782,9 @@ class TextField extends StatefulWidget {
/// {@macro flutter.services.TextInputConfiguration.enableIMEPersonalizedLearning}
final bool enableIMEPersonalizedLearning;

/// {@macro flutter.widgets.editableText.contentCommitMimeTypes}
final List<String> contentCommitMimeTypes;

@override
State<TextField> createState() => _TextFieldState();

Expand Down Expand Up @@ -808,6 +827,16 @@ class TextField extends StatefulWidget {
properties.add(DiagnosticsProperty<Clip>('clipBehavior', clipBehavior, defaultValue: Clip.hardEdge));
properties.add(DiagnosticsProperty<bool>('scribbleEnabled', scribbleEnabled, defaultValue: true));
properties.add(DiagnosticsProperty<bool>('enableIMEPersonalizedLearning', enableIMEPersonalizedLearning, defaultValue: true));
properties.add(DiagnosticsProperty<List<String>>('contentCommitMimeTypes', contentCommitMimeTypes,
defaultValue: onContentCommitted == null ? null : <String>[
'image/png',
'image/bmp',
'image/jpg',
'image/tiff',
'image/gif',
'image/jpeg',
'image/webp'
]));
}
}

Expand Down Expand Up @@ -1248,6 +1277,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
selectionColor: focusNode.hasFocus ? selectionColor : null,
selectionControls: widget.selectionEnabled ? textSelectionControls : null,
onChanged: widget.onChanged,
onContentCommitted: widget.onContentCommitted,
onSelectionChanged: _handleSelectionChanged,
onEditingComplete: widget.onEditingComplete,
onSubmitted: widget.onSubmitted,
Expand Down
17 changes: 16 additions & 1 deletion packages/flutter/lib/src/services/text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class TextInputConfiguration {
this.textCapitalization = TextCapitalization.none,
this.autofillConfiguration = AutofillConfiguration.disabled,
this.enableIMEPersonalizedLearning = true,
this.contentCommitMimeTypes = const <String>[],
this.enableDeltaModel = false,
}) : assert(inputType != null),
assert(obscureText != null),
Expand All @@ -485,6 +486,7 @@ class TextInputConfiguration {
assert(inputAction != null),
assert(textCapitalization != null),
assert(enableIMEPersonalizedLearning != null),
assert(contentCommitMimeTypes != null),
assert(enableDeltaModel != null);

/// The type of information for which to optimize the text input control.
Expand Down Expand Up @@ -624,6 +626,9 @@ class TextInputConfiguration {
/// {@endtemplate}
final bool enableIMEPersonalizedLearning;

/// {@macro flutter.widgets.editableText.contentCommitMimeTypes}
final List<String> contentCommitMimeTypes;

/// Creates a copy of this [TextInputConfiguration] with the given fields
/// replaced with new values.
TextInputConfiguration copyWith({
Expand All @@ -641,6 +646,7 @@ class TextInputConfiguration {
TextCapitalization? textCapitalization,
bool? enableIMEPersonalizedLearning,
AutofillConfiguration? autofillConfiguration,
List<String>? contentCommitMimeTypes,
bool? enableDeltaModel,
}) {
return TextInputConfiguration(
Expand All @@ -657,6 +663,7 @@ class TextInputConfiguration {
keyboardAppearance: keyboardAppearance ?? this.keyboardAppearance,
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning?? this.enableIMEPersonalizedLearning,
autofillConfiguration: autofillConfiguration ?? this.autofillConfiguration,
contentCommitMimeTypes: contentCommitMimeTypes ?? this.contentCommitMimeTypes,
enableDeltaModel: enableDeltaModel ?? this.enableDeltaModel,
);
}
Expand Down Expand Up @@ -705,6 +712,7 @@ class TextInputConfiguration {
'enableIMEPersonalizedLearning': enableIMEPersonalizedLearning,
if (autofill != null) 'autofill': autofill,
'enableDeltaModel' : enableDeltaModel,
'contentCommitMimeTypes': contentCommitMimeTypes,
};
}
}
Expand Down Expand Up @@ -1118,6 +1126,9 @@ mixin TextInputClient {
/// Requests that this client perform the given action.
void performAction(TextInputAction action);

/// Notify client about new content insertion from Android keyboard.
void commitContent(Map<String, dynamic> content);

/// Request from the input method that this client perform the given private
/// command.
///
Expand Down Expand Up @@ -1814,7 +1825,11 @@ class TextInput {
(_currentConnection!._client as DeltaTextInputClient).updateEditingValueWithDeltas(deltas);
break;
case 'TextInputClient.performAction':
_currentConnection!._client.performAction(_toTextInputAction(args[1] as String));
if (args[1] as String == 'TextInputAction.commitContent') {
_currentConnection!._client.commitContent(args[2] as Map<String, dynamic>);
} else {
_currentConnection!._client.performAction(_toTextInputAction(args[1] as String));
}
break;
case 'TextInputClient.performPrivateCommand':
final Map<String, dynamic> firstArg = args[1] as Map<String, dynamic>;
Expand Down
Loading

0 comments on commit 1f6c4a4

Please sign in to comment.