Skip to content

Commit

Permalink
compose: Support images from keyboard for Android
Browse files Browse the repository at this point in the history
Fixes: zulip#419
Fixes: zulip#1173

Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Dec 24, 2024
1 parent df9a1de commit 0ef5179
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
}
}

void _handleContentInserted(KeyboardInsertedContent content) async {
final url = Uri.tryParse(content.uri);
// TODO: is this correct?
String filename = (url == null || url.pathSegments.isEmpty)
? 'file'
: url.pathSegments.last;

if (!content.hasData) {
// TODO: investigate how data can be null and handle it
return;
}

final file = _File(
content: Stream.fromIterable([content.data!]),
length: content.data!.length,
filename: filename,
mimeType: content.mimeType);

await _uploadFiles(
context: context,
contentController: widget.controller.content,
contentFocusNode: widget.controller.contentFocusNode,
files: [file]);
}

static double maxHeight(BuildContext context) {
final clampingTextScaler = MediaQuery.textScalerOf(context)
.clamp(maxScaleFactor: 1.5);
Expand Down Expand Up @@ -405,6 +430,8 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
child: TextField(
controller: widget.controller.content,
focusNode: widget.controller.contentFocusNode,
contentInsertionConfiguration: ContentInsertionConfiguration(
onContentInserted: _handleContentInserted),
// Let the content show through the `contentPadding` so that
// our [InsetShadowBox] can fade it smoothly there.
clipBehavior: Clip.none,
Expand Down

0 comments on commit 0ef5179

Please sign in to comment.