1
- import { Component , computed , defineComponent , h } from '@vue/runtime-core'
1
+ import {
2
+ Component ,
3
+ defineComponent ,
4
+ h ,
5
+ reactive ,
6
+ watch ,
7
+ } from '@vue/runtime-core'
2
8
import { ref } from 'vue'
3
9
import { Colors } from '../abstract/Colors'
4
10
import { EdgeInsetsStep } from '../abstract/EdgeInsets'
5
- import { NavigationController } from '../abstract/Navigation'
11
+ import {
12
+ NavigationController ,
13
+ NavigationControllerRoute ,
14
+ } from '../abstract/Navigation'
6
15
import {
7
16
OpacityDecoration ,
8
17
OpacityDecorationSteps ,
@@ -44,20 +53,40 @@ export const Navigation = ({ child }: NavigationI) => {
44
53
const routeController = MultiProvider . get < NavigationController > (
45
54
NavigationController
46
55
)
47
- const currentRoute = computed ( ( ) => routeController . currentRoute )
48
- const currentWidget = computed ( ( ) => currentRoute . value . widget )
49
-
50
- const isRoutesExists = computed ( ( ) => routeController . routes . length > 0 )
51
-
52
- const isFullscreen = computed ( ( ) => {
53
- const maybeFullscreen = currentRoute . value . fullscreen
54
- return maybeFullscreen == null || maybeFullscreen == true
56
+ const currentRoute = reactive < NavigationControllerRoute > ( {
57
+ widget : null ,
58
+ fullscreen : true ,
59
+ routeName : '' ,
55
60
} )
56
- const isNotFullscreen = computed ( ( ) => ! isFullscreen . value )
61
+ const isRoutesExists = ref < boolean > ( false )
62
+ const isFullscreen = ref < boolean > ( false )
63
+ const isNotFullscreen = ref < boolean > ( false )
64
+
65
+ watch (
66
+ routeController . routes ,
67
+ ( newRoutes ) => {
68
+ const newRoute = newRoutes [ 0 ]
69
+ if ( newRoute == null ) {
70
+ isRoutesExists . value = false
71
+ currentRoute . widget = null
72
+ return
73
+ }
74
+ currentRoute . widget = newRoute . widget
75
+ currentRoute . routeName = newRoute . routeName
76
+ currentRoute . fullscreen = newRoute . fullscreen
77
+ isNotFullscreen . value = ! newRoute . fullscreen
78
+ isFullscreen . value = newRoute . fullscreen
79
+ isRoutesExists . value = true
80
+ } ,
81
+ {
82
+ deep : true ,
83
+ immediate : true ,
84
+ }
85
+ )
57
86
58
87
return {
59
88
isFullscreen,
60
- currentWidget ,
89
+ currentRoute ,
61
90
isNotFullscreen,
62
91
isRoutesExists,
63
92
routeController,
@@ -114,7 +143,7 @@ export const Navigation = ({ child }: NavigationI) => {
114
143
event . stopPropagation ( )
115
144
}
116
145
>
117
- { h ( this . currentWidget ) }
146
+ { h ( this . currentRoute . widget ?? < div /> ) }
118
147
</ div >
119
148
) ,
120
149
} )
@@ -134,7 +163,7 @@ export const Navigation = ({ child }: NavigationI) => {
134
163
new SizedBoxHeight ( { } ) . css ,
135
164
] }
136
165
>
137
- { h ( this . currentWidget ) }
166
+ { h ( this . currentRoute . widget ?? < div /> ) }
138
167
</ div >
139
168
) ,
140
169
visible : ref ( this . isFullscreen ) ,
0 commit comments