SemanticsHandle should dispatch creation and disposal events. (#137960)
This commit is contained in:
parent
4880aab113
commit
c0b21b16ef
@ -822,6 +822,16 @@ typedef LayoutCallback<T extends Constraints> = void Function(T constraints);
|
|||||||
class _LocalSemanticsHandle implements SemanticsHandle {
|
class _LocalSemanticsHandle implements SemanticsHandle {
|
||||||
_LocalSemanticsHandle._(PipelineOwner owner, this.listener)
|
_LocalSemanticsHandle._(PipelineOwner owner, this.listener)
|
||||||
: _owner = owner {
|
: _owner = owner {
|
||||||
|
// TODO(polina-c): stop duplicating code across disposables
|
||||||
|
// https://github.com/flutter/flutter/issues/137435
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
MemoryAllocations.instance.dispatchObjectCreated(
|
||||||
|
library: 'package:flutter/rendering.dart',
|
||||||
|
className: '$_LocalSemanticsHandle',
|
||||||
|
object: this,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
_owner.semanticsOwner!.addListener(listener!);
|
_owner.semanticsOwner!.addListener(listener!);
|
||||||
}
|
}
|
||||||
@ -834,6 +844,12 @@ class _LocalSemanticsHandle implements SemanticsHandle {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
// TODO(polina-c): stop duplicating code across disposables
|
||||||
|
// https://github.com/flutter/flutter/issues/137435
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
|
||||||
|
}
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
_owner.semanticsOwner!.removeListener(listener!);
|
_owner.semanticsOwner!.removeListener(listener!);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,17 @@ mixin SemanticsBinding on BindingBase {
|
|||||||
///
|
///
|
||||||
/// To obtain a [SemanticsHandle], call [SemanticsBinding.ensureSemantics].
|
/// To obtain a [SemanticsHandle], call [SemanticsBinding.ensureSemantics].
|
||||||
class SemanticsHandle {
|
class SemanticsHandle {
|
||||||
SemanticsHandle._(this._onDispose);
|
SemanticsHandle._(this._onDispose) {
|
||||||
|
// TODO(polina-c): stop duplicating code across disposables
|
||||||
|
// https://github.com/flutter/flutter/issues/137435
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
MemoryAllocations.instance.dispatchObjectCreated(
|
||||||
|
library: 'package:flutter/semantics.dart',
|
||||||
|
className: '$SemanticsHandle',
|
||||||
|
object: this,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final VoidCallback _onDispose;
|
final VoidCallback _onDispose;
|
||||||
|
|
||||||
@ -201,6 +211,12 @@ class SemanticsHandle {
|
|||||||
/// framework will stop generating semantics information.
|
/// framework will stop generating semantics information.
|
||||||
@mustCallSuper
|
@mustCallSuper
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
// TODO(polina-c): stop duplicating code across disposables
|
||||||
|
// https://github.com/flutter/flutter/issues/137435
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
|
||||||
|
}
|
||||||
|
|
||||||
_onDispose();
|
_onDispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,4 +82,14 @@ void main() {
|
|||||||
expect(SemanticsBinding.instance.semanticsEnabled, isFalse);
|
expect(SemanticsBinding.instance.semanticsEnabled, isFalse);
|
||||||
expect(tester.binding.pipelineOwner.semanticsOwner, isNull);
|
expect(tester.binding.pipelineOwner.semanticsOwner, isNull);
|
||||||
}, semanticsEnabled: false);
|
}, semanticsEnabled: false);
|
||||||
|
|
||||||
|
test('SemanticsHandle dispatches memory events', () async {
|
||||||
|
await expectLater(
|
||||||
|
await memoryEvents(
|
||||||
|
() => SemanticsBinding.instance.ensureSemantics().dispose(),
|
||||||
|
SemanticsHandle,
|
||||||
|
),
|
||||||
|
areCreateAndDispose,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user