Skip to content

Commit

Permalink
fix: keep keyboard appearance as same brightness as system theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hyj1204 committed Jun 29, 2023
1 parent ed75bf6 commit dbf8e0d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

abstract class TextInputService {
Expand All @@ -27,8 +28,10 @@ abstract class TextInputService {
/// Updates the [TextEditingValue] of the text currently being edited.
///
/// Note that if there are IME-related requirements,
/// please config `composing` value within [TextEditingValue]
void attach(TextEditingValue textEditingValue);
/// please config `composing` value within [TextEditingValue]
///
/// [BuildContext] is used to get current keyboard appearance(light or dark)
void attach(TextEditingValue textEditingValue, BuildContext context);

/// Applies insertion, deletion and replacement
/// to the text currently being edited.
Expand Down Expand Up @@ -82,16 +85,17 @@ class DeltaTextInputService extends TextInputService with DeltaTextInputClient {
}

@override
void attach(TextEditingValue textEditingValue) {
void attach(TextEditingValue textEditingValue, BuildContext context) {
if (_textInputConnection == null ||
_textInputConnection!.attached == false) {
_textInputConnection = TextInput.attach(
this,
const TextInputConfiguration(
TextInputConfiguration(
enableDeltaModel: true,
inputType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
inputAction: TextInputAction.newline,
keyboardAppearance: Theme.of(context).brightness,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_diff.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class NonDeltaTextInputService extends TextInputService with TextInputClient {
Expand Down Expand Up @@ -54,7 +55,10 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
}

@override
void attach(TextEditingValue textEditingValue) {
void attach(
TextEditingValue textEditingValue,
BuildContext context,
) {
final formattedValue = textEditingValue.format();
if (currentTextEditingValue == formattedValue) {
return;
Expand All @@ -64,11 +68,12 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
_textInputConnection!.attached == false) {
_textInputConnection = TextInput.attach(
this,
const TextInputConfiguration(
TextInputConfiguration(
enableDeltaModel: false,
inputType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
inputAction: TextInputAction.newline,
keyboardAppearance: Theme.of(context).brightness,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
void _attachTextInputService(Selection selection) {
final textEditingValue = _getCurrentTextEditingValue(selection);
if (textEditingValue != null) {
textInputService.attach(textEditingValue);
textInputService.attach(
textEditingValue,
context,
);
// disable shortcuts when the IME active
enableShortcuts = textEditingValue.composing == TextRange.empty;
} else {
Expand Down

0 comments on commit dbf8e0d

Please sign in to comment.