@@ -34,7 +34,7 @@ import { tap, debounceTime, filter, takeUntil, switchMap } from 'rxjs/operators'
34
34
import { Gallery } from '../services/gallery.service' ;
35
35
import { GalleryState , GalleryError } from '../models/gallery.model' ;
36
36
import { GalleryConfig } from '../models/config.model' ;
37
- import { SlidingDirection , ThumbnailsView } from '../models/constants' ;
37
+ import { SlidingDirection } from '../models/constants' ;
38
38
import { SliderAdapter , HorizontalAdapter , VerticalAdapter } from './adapters' ;
39
39
import { SmoothScrollManager } from '../smooth-scroll' ;
40
40
import { resizeObservable } from '../utils/resize-observer' ;
@@ -162,89 +162,90 @@ export class GallerySliderComponent implements OnInit, OnChanges, AfterViewInit,
162
162
this . adapter = new VerticalAdapter ( this . slider , this . config ) ;
163
163
break ;
164
164
}
165
-
166
- if ( ! changes . config . firstChange ) {
167
- requestAnimationFrame ( ( ) => {
168
- // Keep the correct sliding position when direction changes
169
- this . scrollToIndex ( this . state . currIndex , 'auto' ) ;
170
- } ) ;
165
+ if ( this . _platform . isBrowser ) {
166
+ if ( ! changes . config . firstChange ) {
167
+ requestAnimationFrame ( ( ) => {
168
+ // Keep the correct sliding position when direction changes
169
+ this . scrollToIndex ( this . state . currIndex , 'auto' ) ;
170
+ } ) ;
171
+ }
172
+ // Reactivate gestures
173
+ this . enableDisableGestures ( ) ;
171
174
}
172
-
173
- // Reactivate gestures
174
- this . enableDisableGestures ( ) ;
175
175
}
176
176
177
- if ( ! changes . config . firstChange ) {
177
+ if ( this . _platform . isBrowser && ! changes . config . firstChange ) {
178
178
if ( changes . config . currentValue ?. mouseSlidingDisabled !== changes . config . previousValue ?. mouseSlidingDisabled ) {
179
179
this . enableDisableGestures ( ) ;
180
180
}
181
181
}
182
182
}
183
183
184
184
// Scroll to current index
185
- if ( changes . state && changes . state . currentValue ?. currIndex !== changes . state . previousValue ?. currIndex ) {
185
+ if ( this . _platform . isBrowser && changes . state && changes . state . currentValue ?. currIndex !== changes . state . previousValue ?. currIndex ) {
186
186
requestAnimationFrame ( ( ) => {
187
187
this . scrollToIndex ( this . state . currIndex , changes . state . firstChange ? 'auto' : this . state . behavior ) ;
188
188
} ) ;
189
189
}
190
190
}
191
191
192
192
ngOnInit ( ) : void {
193
- this . _zone . runOutsideAngular ( ( ) => {
194
-
195
- // We need to set the visibleElements in the viewport using intersection observer
196
- this . createIntersectionObserver ( this . slider ) . pipe (
197
- tap ( ( entry : IntersectionObserverEntry ) => {
198
- entry . target . classList . toggle ( 'g-item-visible' , entry . isIntersecting ) ;
199
- if ( entry . isIntersecting ) {
200
- this . visibleElements . set ( entry . target , entry ) ;
201
- } else {
202
- this . visibleElements . delete ( entry . target ) ;
203
- }
204
- } ) ,
205
- takeUntil ( this . _destroyed$ )
206
- ) . subscribe ( ) ;
193
+ if ( this . _platform . isBrowser ) {
194
+ this . _zone . runOutsideAngular ( ( ) => {
195
+ // We need to set the visibleElements in the viewport using intersection observer
196
+ this . createIntersectionObserver ( this . slider ) . pipe (
197
+ tap ( ( entry : IntersectionObserverEntry ) => {
198
+ entry . target . classList . toggle ( 'g-item-visible' , entry . isIntersecting ) ;
199
+ if ( entry . isIntersecting ) {
200
+ this . visibleElements . set ( entry . target , entry ) ;
201
+ } else {
202
+ this . visibleElements . delete ( entry . target ) ;
203
+ }
204
+ } ) ,
205
+ takeUntil ( this . _destroyed$ )
206
+ ) . subscribe ( ) ;
207
207
208
- // Subscribe to slider scroll event
209
- fromEvent ( this . slider , 'scroll' , { passive : true } ) . pipe (
210
- debounceTime ( 50 ) ,
211
- filter ( ( ) => ! this . _isPanning ) ,
212
- tap ( ( ) => this . onViewportScroll ( ) ) ,
213
- takeUntil ( this . _destroyed$ )
214
- ) . subscribe ( ) ;
208
+ // Subscribe to slider scroll event
209
+ fromEvent ( this . slider , 'scroll' , { passive : true } ) . pipe (
210
+ debounceTime ( 50 ) ,
211
+ filter ( ( ) => ! this . _isPanning ) ,
212
+ tap ( ( ) => this . onViewportScroll ( ) ) ,
213
+ takeUntil ( this . _destroyed$ )
214
+ ) . subscribe ( ) ;
215
215
216
- // Detect if the size of the slider has changed detecting current index on scroll
217
- if ( this . _platform . isBrowser ) {
216
+ // Detect if the size of the slider has changed detecting current index on scroll
218
217
resizeObservable ( this . _el . nativeElement ) . pipe (
219
218
debounceTime ( this . config . resizeDebounceTime ) ,
220
219
tap ( ( [ entry ] : ResizeObserverEntry [ ] ) => this . onHostResize ( entry ) ) ,
221
220
takeUntil ( this . _destroyed$ )
222
221
) . subscribe ( ) ;
223
- }
224
- } ) ;
222
+ } ) ;
223
+ }
225
224
}
226
225
227
226
ngAfterViewInit ( ) : void {
228
- this . items . notifyOnChanges ( ) ;
229
- this . items . changes . pipe (
230
- startWith ( null ) ,
231
- tap ( ( ) => {
232
- // Disconnect all and reconnect later
233
- this . visibleElements . forEach ( ( item : IntersectionObserverEntry ) => {
234
- this . intersectionObserver . unobserve ( item . target ) ;
235
- } ) ;
227
+ if ( this . _platform . isBrowser ) {
228
+ this . items . notifyOnChanges ( ) ;
229
+ this . items . changes . pipe (
230
+ startWith ( null ) ,
231
+ tap ( ( ) => {
232
+ // Disconnect all and reconnect later
233
+ this . visibleElements . forEach ( ( item : IntersectionObserverEntry ) => {
234
+ this . intersectionObserver . unobserve ( item . target ) ;
235
+ } ) ;
236
236
237
- // Connect with the new items
238
- this . items . toArray ( ) . map ( ( item : GalleryItemComponent ) => {
239
- this . intersectionObserver . observe ( item . element ) ;
240
- } ) ;
241
- } ) ,
242
- takeUntil ( this . _destroyed$ )
243
- ) . subscribe ( ) ;
237
+ // Connect with the new items
238
+ this . items . toArray ( ) . map ( ( item : GalleryItemComponent ) => {
239
+ this . intersectionObserver . observe ( item . element ) ;
240
+ } ) ;
241
+ } ) ,
242
+ takeUntil ( this . _destroyed$ )
243
+ ) . subscribe ( ) ;
244
+ }
244
245
}
245
246
246
247
ngAfterViewChecked ( ) : void {
247
- if ( this . config . itemAutosize ) {
248
+ if ( this . config . itemAutosize && this . _platform . isBrowser ) {
248
249
this . slider . style . setProperty ( '--slider-centralize-start-size' , this . adapter . getCentralizerStartSize ( ) + 'px' ) ;
249
250
this . slider . style . setProperty ( '--slider-centralize-end-size' , this . adapter . getCentralizerEndSize ( ) + 'px' ) ;
250
251
}
0 commit comments