MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / canGoBack

Method canGoBack

packages/core/ui/frame/frame-common.ts:128–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

126 }
127
128 public canGoBack(): boolean {
129 let backstack = this._backStack.length;
130 let previousForwardNotInBackstack = false;
131 this._navigationQueue.forEach((item) => {
132 const entry = item.entry;
133 const isBackNavigation = item.navigationType === NavigationType.back;
134 if (isBackNavigation) {
135 previousForwardNotInBackstack = false;
136 if (!entry) {
137 backstack--;
138 } else {
139 const backstackIndex = this._backStack.indexOf(entry);
140 if (backstackIndex !== -1) {
141 backstack = backstackIndex;
142 } else {
143 // NOTE: We don't search for entries in navigationQueue because there is no way for
144 // developer to get reference to BackstackEntry unless transition is completed.
145 // At that point the entry is put in the backstack array.
146 // If we start to return Backstack entry from navigate method then
147 // here we should check also navigationQueue as well.
148 backstack--;
149 }
150 }
151 } else if (entry.entry.clearHistory) {
152 previousForwardNotInBackstack = false;
153 backstack = 0;
154 } else {
155 backstack++;
156 if (previousForwardNotInBackstack) {
157 backstack--;
158 }
159
160 previousForwardNotInBackstack = entry.entry.backstackVisible === false;
161 }
162 });
163
164 // this is our first navigation which is not completed yet.
165 if (this._navigationQueue.length > 0 && !this._currentEntry) {
166 backstack--;
167 }
168
169 return backstack > 0;
170 }
171
172 /**
173 * Navigates to the previous entry (if any) in the back stack.

Callers 1

goBackMethod · 0.95

Calls 2

forEachMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected