Unverified Commit 1148a2a8 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Migrate EditableTextState from addPostFrameCallbacks to compositionCallbacks (#119359)

* PostFrameCallbacks -> compositionCallbacks

* review

* review
parent 865dc5c5
...@@ -168,9 +168,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { ...@@ -168,9 +168,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin {
assert(delta != 0); assert(delta != 0);
_compositionCallbackCount += delta; _compositionCallbackCount += delta;
assert(_compositionCallbackCount >= 0); assert(_compositionCallbackCount >= 0);
if (parent != null) { parent?._updateSubtreeCompositionObserverCount(delta);
parent!._updateSubtreeCompositionObserverCount(delta);
}
} }
void _fireCompositionCallbacks({required bool includeChildren}) { void _fireCompositionCallbacks({required bool includeChildren}) {
......
...@@ -179,6 +179,9 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex ...@@ -179,6 +179,9 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex
painter(this, offset); painter(this, offset);
} }
@override
VoidCallback addCompositionCallback(CompositionCallback callback) => () {};
@override @override
void noSuchMethod(Invocation invocation) { } void noSuchMethod(Invocation invocation) { }
} }
......
...@@ -14611,6 +14611,66 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async ...@@ -14611,6 +14611,66 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
// Shouldn't crash. // Shouldn't crash.
state.didChangeMetrics(); state.didChangeMetrics();
}); });
testWidgets('_CompositionCallback widget does not skip frames', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true;
final FocusNode focusNode = FocusNode();
final TextEditingController controller = TextEditingController.fromValue(
const TextEditingValue(selection: TextSelection.collapsed(offset: 0)),
);
Offset offset = Offset.zero;
late StateSetter setState;
await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(
builder: (BuildContext context, StateSetter stateSetter) {
setState = stateSetter;
return Transform.translate(
offset: offset,
// The EditableText is configured in a way that the it doesn't
// explicitly request repaint on focus change.
child: TickerMode(
enabled: false,
child: RepaintBoundary(
child: EditableText(
controller: controller,
focusNode: focusNode,
style: const TextStyle(),
showCursor: false,
cursorColor: Colors.blue,
backgroundCursorColor: Colors.grey,
),
),
),
);
}
),
),
);
focusNode.requestFocus();
await tester.pump();
tester.testTextInput.log.clear();
// The composition callback should be registered. To verify, change the
// parent layer's transform.
setState(() { offset = const Offset(42, 0); });
await tester.pump();
expect(
tester.testTextInput.log,
contains(
matchesMethodCall(
'TextInput.setEditableSizeAndTransform',
args: containsPair('transform', Matrix4.translationValues(offset.dx, offset.dy, 0).storage),
),
),
);
EditableText.debugDeterministicCursor = false;
});
} }
class UnsettableController extends TextEditingController { class UnsettableController extends TextEditingController {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment