Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit d58db64

Browse files
TedSandernshahan
authored andcommitted
Change ModalComponent to use OnPush
PiperOrigin-RevId: 242779022
1 parent fdce791 commit d58db64

File tree

1 file changed

+9
-18
lines changed
  • angular_components/lib/laminate/components/modal

1 file changed

+9
-18
lines changed

angular_components/lib/laminate/components/modal/modal.dart

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ abstract class Modal {
154154
<ng-content></ng-content>
155155
</template>
156156
''',
157+
changeDetection: ChangeDetectionStrategy.OnPush,
157158
// TODO(google): Change preserveWhitespace to false to improve codesize.
158159
preserveWhitespace: true,
159160
visibility: Visibility.all, // Injected by dialog, et al.
@@ -182,7 +183,7 @@ class ModalComponent
182183
bool _isDestroyed = false;
183184
bool _isHidden = false;
184185
bool _isVisible = false;
185-
OverlayRef _resolvedOverlayRef;
186+
final OverlayRef _resolvedOverlayRef;
186187
Element _lastFocusedElement;
187188

188189
/// Whether to return focus to the last focused element before the modal
@@ -196,9 +197,13 @@ class ModalComponent
196197
Future<bool> _pendingClose;
197198

198199
ModalComponent(OverlayService overlayService, this._element, this._domService,
199-
@Optional() @SkipSelf() this._parentModal, @Optional() this._stack) {
200-
_createdOverlayRef(
201-
overlayService.createOverlayRefSync(OverlayState.Dialog));
200+
@Optional() @SkipSelf() this._parentModal, @Optional() this._stack)
201+
: _resolvedOverlayRef =
202+
overlayService.createOverlayRefSync(OverlayState.Dialog) {
203+
_disposer
204+
..addDisposable(_resolvedOverlayRef)
205+
..addStreamSubscription(_resolvedOverlayRef.onVisibleChanged
206+
.listen(_onOverlayVisibleChanged));
202207
}
203208

204209
@Input()
@@ -223,20 +228,6 @@ class ModalComponent
223228
_disposer.dispose();
224229
}
225230

226-
void _createdOverlayRef(OverlayRef overlayRef) {
227-
// If the modal is closed before the overlay is created we should dispose
228-
// the ref to avoid leaks since `onDestroy` was already called.
229-
if (_isDestroyed) {
230-
overlayRef.dispose();
231-
} else {
232-
_resolvedOverlayRef = overlayRef;
233-
_disposer
234-
..addDisposable(_resolvedOverlayRef)
235-
..addStreamSubscription(_resolvedOverlayRef.onVisibleChanged
236-
.listen(_onOverlayVisibleChanged));
237-
}
238-
}
239-
240231
// A callback received when the overlay reports a visibility change.
241232
void _onOverlayVisibleChanged(bool isVisible) {
242233
_isVisible = isVisible;

0 commit comments

Comments
 (0)