1
1
namespace BitBlazorUI {
2
2
export class AppShell {
3
+ private static STORE_KEY = 'bit-appshell-scrolls' ;
4
+
3
5
public static PreScroll : number = 0 ;
4
6
5
7
private static _currentUrl : string ;
@@ -9,9 +11,10 @@ namespace BitBlazorUI {
9
11
public static initScroll ( container : HTMLElement , url : string ) {
10
12
AppShell . _container = container ;
11
13
AppShell . _currentUrl = url ;
12
- AppShell . _scrolls [ url ] = AppShell . PreScroll ;
13
- if ( AppShell . PreScroll > 0 ) {
14
- AppShell . _container . scrollTo ( { top : AppShell . PreScroll , behavior : 'instant' } ) ;
14
+ AppShell . _scrolls = JSON . parse ( sessionStorage . getItem ( AppShell . STORE_KEY ) || '{}' ) ;
15
+ AppShell . storeScroll ( url , AppShell . PreScroll > 0 ? AppShell . PreScroll : AppShell . _scrolls [ url ] ) ;
16
+ if ( AppShell . _scrolls [ url ] ! > 0 ) {
17
+ AppShell . _container . scrollTo ( { top : AppShell . _scrolls [ url ] , behavior : 'instant' } ) ;
15
18
}
16
19
AppShell . addScroll ( ) ;
17
20
}
@@ -22,7 +25,7 @@ namespace BitBlazorUI {
22
25
23
26
public static afterRenderScroll ( url : string ) {
24
27
AppShell . _currentUrl = url ;
25
- AppShell . _scrolls [ url ] = AppShell . _scrolls [ url ] || 0 ;
28
+ AppShell . storeScroll ( url , AppShell . _scrolls [ url ] ) ;
26
29
AppShell . _container ?. scrollTo ( { top : AppShell . _scrolls [ url ] , behavior : 'instant' } ) ;
27
30
AppShell . addScroll ( ) ;
28
31
}
@@ -40,7 +43,12 @@ namespace BitBlazorUI {
40
43
}
41
44
42
45
private static onScroll ( ) {
43
- AppShell . _scrolls [ AppShell . _currentUrl ] = AppShell . _container ?. scrollTop ;
46
+ AppShell . storeScroll ( AppShell . _currentUrl , AppShell . _container ?. scrollTop ) ;
47
+ }
48
+
49
+ private static storeScroll ( url : string , value : number | undefined ) {
50
+ AppShell . _scrolls [ url ] = value || 0 ;
51
+ window . sessionStorage . setItem ( AppShell . STORE_KEY , JSON . stringify ( AppShell . _scrolls ) ) ;
44
52
}
45
53
}
46
54
}
0 commit comments