Skip to content

Commit

Permalink
RenderEditable should dispose created layers. (#135942)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Oct 6, 2023
1 parent 8796955 commit f097036
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 67 deletions.
6 changes: 5 additions & 1 deletion packages/flutter/lib/src/rendering/editable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,

@override
void dispose() {
_leaderLayerHandler.layer = null;
_foregroundRenderObject?.dispose();
_foregroundRenderObject = null;
_backgroundRenderObject?.dispose();
Expand Down Expand Up @@ -2471,14 +2472,17 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
}
}

final LayerHandle<LeaderLayer> _leaderLayerHandler = LayerHandle<LeaderLayer>();

void _paintHandleLayers(PaintingContext context, List<TextSelectionPoint> endpoints, Offset offset) {
Offset startPoint = endpoints[0].point;
startPoint = Offset(
clampDouble(startPoint.dx, 0.0, size.width),
clampDouble(startPoint.dy, 0.0, size.height),
);
_leaderLayerHandler.layer = LeaderLayer(link: startHandleLayerLink, offset: startPoint + offset);
context.pushLayer(
LeaderLayer(link: startHandleLayerLink, offset: startPoint + offset),
_leaderLayerHandler.layer!,
super.paint,
Offset.zero,
);
Expand Down
58 changes: 9 additions & 49 deletions packages/flutter/test/widgets/editable_text_cursor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 500));
expect(renderEditable.cursorColor!.alpha, 0);
expect(renderEditable, paintsExactlyCountTimes(#drawRect, 0));
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 5},
));
});

testWidgetsWithLeakTracking('Cursor does not animates when debugDeterministicCursor is set', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true;
Expand Down Expand Up @@ -332,11 +327,7 @@ void main() {
EditableText.debugDeterministicCursor = false;
},
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }),
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 6},
));
);

testWidgetsWithLeakTracking('Cursor does not animate on Android when debugDeterministicCursor is set', (WidgetTester tester) async {
final Color defaultCursorColor = Color(ThemeData.fallback().colorScheme.primary.value);
Expand Down Expand Up @@ -375,12 +366,7 @@ void main() {
expect(renderEditable, paints..rect(color: defaultCursorColor));

EditableText.debugDeterministicCursor = false;
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 4},
));
});

testWidgetsWithLeakTracking('Cursor animation restarts when it is moved using keys on desktop', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
Expand Down Expand Up @@ -460,11 +446,7 @@ void main() {
debugDefaultTargetPlatformOverride = null;
},
variant: KeySimulatorTransitModeVariant.all(),
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 18},
));
);

testWidgetsWithLeakTracking('Cursor does not show when showCursor set to false', (WidgetTester tester) async {
const Widget widget = MaterialApp(
Expand Down Expand Up @@ -492,12 +474,7 @@ void main() {

await tester.pump(const Duration(milliseconds: 200));
expect(renderEditable, paintsExactlyCountTimes(#drawRect, 0));
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 3},
));
});

testWidgetsWithLeakTracking('Cursor does not show when not focused', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/106512 .
Expand Down Expand Up @@ -527,12 +504,7 @@ void main() {
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(renderEditable, isNot(paintsExactlyCountTimes(#drawRect, 0)));
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 2},
));
});

testWidgetsWithLeakTracking('Cursor radius is 2.0', (WidgetTester tester) async {
const Widget widget = MaterialApp(
Expand Down Expand Up @@ -1031,11 +1003,7 @@ void main() {
debugDefaultTargetPlatformOverride = null;
},
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }),
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 4},
));
);

testWidgetsWithLeakTracking('cursor layout', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true;
Expand Down Expand Up @@ -1287,11 +1255,7 @@ void main() {
);
},
skip: isBrowser && !isCanvasKit, // https://github.com/flutter/flutter/issues/56308
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 1},
));
);

testWidgetsWithLeakTracking('getLocalRectForCaret reports the real caret Rect', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true;
Expand Down Expand Up @@ -1337,9 +1301,5 @@ void main() {
}
},
variant: TargetPlatformVariant.all(),
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 792},
));
);
}
19 changes: 2 additions & 17 deletions packages/flutter/test/widgets/editable_text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3780,11 +3780,6 @@ void main() {

verifyAutocorrectionRectVisibility(expectVisible: false);
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 5},
),
);

testWidgetsWithLeakTracking('Changing controller updates EditableText', (WidgetTester tester) async {
Expand Down Expand Up @@ -12699,12 +12694,7 @@ void main() {
));

EditableText.debugDeterministicCursor = false;
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 2},
));
});

testWidgetsWithLeakTracking('Floating cursor ending with selection', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true;
Expand Down Expand Up @@ -12884,12 +12874,7 @@ void main() {
lastSelectionChangedCause = null;

EditableText.debugDeterministicCursor = false;
},
leakTrackingTestConfig: const LeakTrackingTestConfig(
// TODO(ksokolovskyi): remove after fixing
// https://github.com/flutter/flutter/issues/134386
notDisposedAllowList: <String, int?> {'LeaderLayer': 8},
));
});

group('Selection changed scroll into view', () {
final String text = List<int>.generate(64, (int index) => index).join('\n');
Expand Down

0 comments on commit f097036

Please sign in to comment.