Skip to content

Commit 8bfb37f

Browse files
authored
fix: keep keyboard appearance as same brightness as system theme (AppFlowy-IO#264)
1 parent 2688efb commit 8bfb37f

File tree

7 files changed

+85
-58
lines changed

7 files changed

+85
-58
lines changed

example/lib/main.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ class MyApp extends StatelessWidget {
2424
supportedLocales: const [Locale('en', 'US')],
2525
debugShowCheckedModeBanner: false,
2626
home: const MyHomePage(title: 'AppFlowyEditor Example'),
27-
theme: ThemeData(
28-
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
29-
useMaterial3: true,
30-
),
27+
theme: ThemeData.light(useMaterial3: true),
3128
);
3229
}
3330
}

lib/src/editor/editor_component/service/ime/delta_input_impl.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export 'delta_input_on_delete_impl.dart';
33
export 'delta_input_on_insert_impl.dart';
44
export 'delta_input_on_non_text_update_impl.dart';
55
export 'delta_input_on_replace_impl.dart';
6+
export 'non_delta_input_service.dart';
7+
export 'text_input_service.dart';

lib/src/editor/editor_component/service/ime/delta_input_service.dart

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,9 @@
11
import 'dart:math';
22

33
import 'package:appflowy_editor/appflowy_editor.dart';
4+
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_input_service.dart';
45
import 'package:flutter/services.dart';
56

6-
abstract class TextInputService {
7-
TextInputService({
8-
required this.onInsert,
9-
required this.onDelete,
10-
required this.onReplace,
11-
required this.onNonTextUpdate,
12-
required this.onPerformAction,
13-
});
14-
15-
Future<void> Function(TextEditingDeltaInsertion insertion) onInsert;
16-
Future<void> Function(TextEditingDeltaDeletion deletion) onDelete;
17-
Future<void> Function(TextEditingDeltaReplacement replacement) onReplace;
18-
Future<void> Function(TextEditingDeltaNonTextUpdate nonTextUpdate)
19-
onNonTextUpdate;
20-
Future<void> Function(TextInputAction action) onPerformAction;
21-
22-
TextRange? get composingTextRange;
23-
bool get attached;
24-
25-
void updateCaretPosition(Size size, Matrix4 transform, Rect rect);
26-
27-
/// Updates the [TextEditingValue] of the text currently being edited.
28-
///
29-
/// Note that if there are IME-related requirements,
30-
/// please config `composing` value within [TextEditingValue]
31-
void attach(TextEditingValue textEditingValue);
32-
33-
/// Applies insertion, deletion and replacement
34-
/// to the text currently being edited.
35-
///
36-
/// For more information, please check [TextEditingDelta].
37-
Future<void> apply(List<TextEditingDelta> deltas);
38-
39-
/// Closes the editing state of the text currently being edited.
40-
void close();
41-
}
42-
437
class DeltaTextInputService extends TextInputService with DeltaTextInputClient {
448
DeltaTextInputService({
459
required super.onInsert,
@@ -82,17 +46,22 @@ class DeltaTextInputService extends TextInputService with DeltaTextInputClient {
8246
}
8347

8448
@override
85-
void attach(TextEditingValue textEditingValue) {
49+
void attach(
50+
TextEditingValue textEditingValue,
51+
TextInputConfiguration configuration,
52+
) {
8653
if (_textInputConnection == null ||
8754
_textInputConnection!.attached == false) {
8855
_textInputConnection = TextInput.attach(
8956
this,
90-
const TextInputConfiguration(
91-
enableDeltaModel: true,
92-
inputType: TextInputType.multiline,
93-
textCapitalization: TextCapitalization.sentences,
94-
inputAction: TextInputAction.newline,
95-
),
57+
configuration,
58+
// TextInputConfiguration(
59+
// enableDeltaModel: true,
60+
// inputType: TextInputType.multiline,
61+
// textCapitalization: TextCapitalization.sentences,
62+
// inputAction: TextInputAction.newline,
63+
// keyboardAppearance: Theme.of(context).brightness,
64+
// ),
9665
);
9766
}
9867

lib/src/editor/editor_component/service/ime/non_delta_input_service.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:math';
22

33
import 'package:appflowy_editor/appflowy_editor.dart';
44
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_diff.dart';
5+
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_input_service.dart';
56
import 'package:flutter/services.dart';
67

78
class NonDeltaTextInputService extends TextInputService with TextInputClient {
@@ -54,7 +55,10 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
5455
}
5556

5657
@override
57-
void attach(TextEditingValue textEditingValue) {
58+
void attach(
59+
TextEditingValue textEditingValue,
60+
TextInputConfiguration configuration,
61+
) {
5862
final formattedValue = textEditingValue.format();
5963
if (currentTextEditingValue == formattedValue) {
6064
return;
@@ -64,12 +68,14 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
6468
_textInputConnection!.attached == false) {
6569
_textInputConnection = TextInput.attach(
6670
this,
67-
const TextInputConfiguration(
68-
enableDeltaModel: false,
69-
inputType: TextInputType.multiline,
70-
textCapitalization: TextCapitalization.sentences,
71-
inputAction: TextInputAction.newline,
72-
),
71+
configuration,
72+
// TextInputConfiguration(
73+
// enableDeltaModel: false,
74+
// inputType: TextInputType.multiline,
75+
// textCapitalization: TextCapitalization.sentences,
76+
// inputAction: TextInputAction.newline,
77+
// keyboardAppearance: Theme.of(context).brightness,
78+
// ),
7379
);
7480
}
7581

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
3+
4+
abstract class TextInputService {
5+
TextInputService({
6+
required this.onInsert,
7+
required this.onDelete,
8+
required this.onReplace,
9+
required this.onNonTextUpdate,
10+
required this.onPerformAction,
11+
});
12+
13+
Future<void> Function(TextEditingDeltaInsertion insertion) onInsert;
14+
Future<void> Function(TextEditingDeltaDeletion deletion) onDelete;
15+
Future<void> Function(TextEditingDeltaReplacement replacement) onReplace;
16+
Future<void> Function(TextEditingDeltaNonTextUpdate nonTextUpdate)
17+
onNonTextUpdate;
18+
Future<void> Function(TextInputAction action) onPerformAction;
19+
20+
TextRange? get composingTextRange;
21+
bool get attached;
22+
23+
void updateCaretPosition(Size size, Matrix4 transform, Rect rect);
24+
25+
/// Updates the [TextEditingValue] of the text currently being edited.
26+
///
27+
/// Note that if there are IME-related requirements,
28+
/// please config `composing` value within [TextEditingValue]
29+
///
30+
/// [BuildContext] is used to get current keyboard appearance(light or dark)
31+
void attach(
32+
TextEditingValue textEditingValue,
33+
TextInputConfiguration configuration,
34+
);
35+
36+
/// Applies insertion, deletion and replacement
37+
/// to the text currently being edited.
38+
///
39+
/// For more information, please check [TextEditingDelta].
40+
Future<void> apply(List<TextEditingDelta> deltas);
41+
42+
/// Closes the editing state of the text currently being edited.
43+
void close();
44+
}

lib/src/editor/editor_component/service/keyboard_service_widget.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:appflowy_editor/appflowy_editor.dart';
2-
import 'package:appflowy_editor/src/editor/editor_component/service/ime/non_delta_input_service.dart';
32
import 'package:flutter/foundation.dart';
43
import 'package:flutter/material.dart';
54
import 'package:flutter/services.dart';
@@ -198,7 +197,16 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
198197
void _attachTextInputService(Selection selection) {
199198
final textEditingValue = _getCurrentTextEditingValue(selection);
200199
if (textEditingValue != null) {
201-
textInputService.attach(textEditingValue);
200+
textInputService.attach(
201+
textEditingValue,
202+
TextInputConfiguration(
203+
enableDeltaModel: false,
204+
inputType: TextInputType.multiline,
205+
textCapitalization: TextCapitalization.sentences,
206+
inputAction: TextInputAction.newline,
207+
keyboardAppearance: Theme.of(context).brightness,
208+
),
209+
);
202210
// disable shortcuts when the IME active
203211
enableShortcuts = textEditingValue.composing == TextRange.empty;
204212
} else {

test/new/infra/testable_editor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:appflowy_editor/appflowy_editor.dart';
2+
import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_input_service.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter/services.dart';
45
import 'package:flutter_localizations/flutter_localizations.dart';
@@ -81,7 +82,7 @@ class TestableEditor {
8182
home: Scaffold(
8283
body: wrapper == null
8384
? editor
84-
: wrapper!(
85+
: wrapper(
8586
editor,
8687
),
8788
),

0 commit comments

Comments
 (0)