@@ -23,11 +23,26 @@ import { ScrollDetail } from '@ionic/core';
2323import { CoreUtils } from '@services/utils/utils' ;
2424import { CoreComponentsRegistry } from '@singletons/components-registry' ;
2525import { CoreDom } from '@singletons/dom' ;
26- import { CoreEventObserver } from '@singletons/events' ;
26+ import { CoreEventObserver , CoreEvents } from '@singletons/events' ;
2727import { CoreMath } from '@singletons/math' ;
2828import { Subscription } from 'rxjs' ;
2929import { CoreFormatTextDirective } from './format-text' ;
3030
31+ declare module '@singletons/events' {
32+
33+ /**
34+ * Augment CoreEventsData interface with events specific to this service.
35+ *
36+ * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
37+ */
38+ export interface CoreEventsData {
39+ [ COLLAPSIBLE_HEADER_UPDATED ] : { collapsed : boolean } ;
40+ }
41+
42+ }
43+
44+ export const COLLAPSIBLE_HEADER_UPDATED = 'collapsible_header_updated' ;
45+
3146/**
3247 * Directive to make <ion-header> collapsible.
3348 *
@@ -151,6 +166,27 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest
151166 this . visiblePromise ?. cancel ( ) ;
152167 }
153168
169+ /**
170+ * Update collapsed status of the header.
171+ *
172+ * @param collapsed Whether header is collapsed or not.
173+ */
174+ protected setCollapsed ( collapsed : boolean ) : void {
175+ if ( ! this . page ) {
176+ return ;
177+ }
178+
179+ const isCollapsed = this . page . classList . contains ( 'collapsible-header-page-is-collapsed' ) ;
180+
181+ if ( isCollapsed === collapsed ) {
182+ return ;
183+ }
184+
185+ this . page . classList . toggle ( 'collapsible-header-page-is-collapsed' , collapsed ) ;
186+
187+ CoreEvents . trigger ( COLLAPSIBLE_HEADER_UPDATED , { collapsed } ) ;
188+ }
189+
154190 /**
155191 * Listen to changing events.
156192 */
@@ -458,8 +494,8 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest
458494 }
459495 }
460496
497+ this . setCollapsed ( ! enable ) ;
461498 this . page . style . setProperty ( '--collapsible-header-progress' , enable ? '0' : '1' ) ;
462- this . page . classList . toggle ( 'collapsible-header-page-is-collapsed' , ! enable ) ;
463499 }
464500
465501 /**
@@ -523,9 +559,9 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest
523559 ? 0
524560 : CoreMath . clamp ( contentScroll . scrollTop / scrollingHeight , 0 , 1 ) ;
525561
562+ this . setCollapsed ( progress === 1 ) ;
526563 page . style . setProperty ( '--collapsible-header-progress' , `${ progress } ` ) ;
527564 page . classList . toggle ( 'collapsible-header-page-is-frozen' , frozen ) ;
528- page . classList . toggle ( 'collapsible-header-page-is-collapsed' , progress === 1 ) ;
529565
530566 Object
531567 . entries ( progress > .5 ? collapsedFontStyles : expandedFontStyles )
@@ -547,8 +583,8 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest
547583 const scrollTop = contentScroll . scrollTop ;
548584 const collapse = progress > 0.5 ;
549585
586+ this . setCollapsed ( collapse ) ;
550587 page . style . setProperty ( '--collapsible-header-progress' , collapse ? '1' : '0' ) ;
551- page . classList . toggle ( 'collapsible-header-page-is-collapsed' , collapse ) ;
552588
553589 if ( collapse && this . scrollingHeight && this . scrollingHeight > 0 && scrollTop < this . scrollingHeight ) {
554590 this . content ?. scrollToPoint ( null , this . scrollingHeight ) ;
0 commit comments