Are goBack() and pop() without arguments functionally identical? - react-navigation

From reading the documentation it would seem so, but I suppose I'm confused as to why it isn't called out that they're interchangeable when pop() is called without arguments, or why there would even be two different functions with such similar behavior (and why goBack() wouldn't also take an argument for the number of screens to go back)?
pop - go back in the stack

The difference is:
pop is specific to stack navigator, accepts arguments like the number of screens to pop which is relevant for the stack navigator
goBack is more general, it works in any navigator: stack, tabs drawer
It's not exactly interchangable since it depends on which navigator are you in. For example, if your screen is in a tab navigator nested in stack navigator, if you use pop(), it'll go back in the parent stack navigator, but if you call goBack(), it'll go back in the tab navigator (depending on if there are any screens to go back in both cases).
So generally you probably want to use goBack() which will do the appropriate behavior in most cases, and use pop() only if you have specific requirements and want the specific behaviour it provides.

With the help of pop you can go back a few screens back in a stack
goBack takes you back to the last screen
see here
The pop action takes you back to a previous screen in the stack. It takes one optional argument (count), which allows you to specify how many screens to pop back by.
import { StackActions } from '#react-navigation/native';
StackActions.pop(2);

Related

Making sure the route specified in initialRouteName is always added as the first screen in the stack

Our app have multiple tabs, each tab contains a stack.
We need to be able to navigate from a screen in a stack belonging to one tab to a specific screen in a stack belonging to another tab. This can be done like so navigation.navigate("tab2", {screen:"screen2"}).
We are using react-navigation version 5
Current Behavior
The problem is that if I have not navigated to the initial route for the destination stack(route) before, screen2 is now the only screen in the stack. I need somehow to always make sure that the screen specified in the initialRouteName is added to the stack first.
Expected Behavior
If you specify initialRouteName that route is always added as the first route in the stack, even if you navigate to a specific route defined in the stack.
Setting lazy=false, would solve the issue, but it's important to not initialise the "initial route screen" before actual navigating to a screen in the stack.
It might be that this is work as designed, but are there any way to achieve the behavior I expect then?
How to reproduce
The issue/problem can be reproduced in this snack
Click the "Navigate to Screen2 on Tab 2" button on "tab1". Make sure you have not clicked on Tab2 before doing this.
You are now navigated to Screen2 on Tab2 with no option to navigation to the screen specified in initialRouteName.
This is more of less a copy of this issue
Found that you actual can navigate to a nested navigator and make sure the route specified in initialRouteName is the initial route. It can be done by specifying initial:false like so:
navigation.navigate("tab2", {screen:"screen2", initial: false})
Documentation can be found here

Xamarin Forms page navigation

I know in Xamarin we can use Tabbed page, Carousel page... but I wonder that if I open every new page like this:
Application.Current.MainPage = new MyPage();
Is this a bad approach? Is this effect performance or any other things?
Basically when you use PushAsync, it adds the new page on top of the navigation stack. The navigation stack is a LIFO you can manage using PushAsync, PopAsync or the back button. So when you use PopAsync, it removes the last page from the stack (as it does using the back button).
Using Application.Current.MainPage = new MyPage(); for opening every page, you are just overriding the very first element of the stack and therefore you are not able to use back navigation at all since you would always keep one single page into the navigation stack.
Moreover, with this approach, clicking on the back button will exit the app.
You can do this as long as it works for you. However it may cause some problems, especially that you can't use the system back function in any way. Also you may lose some animations that should be part of the standard UI and that are considered as a good practice.

How can I know who calls the method in Xcode?

Does Xcode have a way to show the caller function of a method? I want to know all of the calling functions of a method in a class. A solution would be to find the method in the project, but sometimes different classes have methods with the same name - That could find us a method we're not looking for..
Many other IDEs have this capability, such as Visual C++ 2003/2005/2008,Eclipse ...
Can you do this in XCode?
Xcode 4.4 intrudced this functionality:
New Features in Xcode 4.4 (Scroll down to 'Find and Search Additions')
Move your cursor on top of the function you are interested in
Open the Assistant editor(⌃ +⌘+Enter)
On the top of the assistant editor, Select 'Callers'
You will see a list of all the function that's calling your function
Not the as effective as other IDEs, but does the job.
Yes. Set a breakpoint inside your method, then when it breaks, there are two spots to see a stack. First is in Xcode's "console" area (usually the bottom middle), there is a top-bar which may not immediately appear to be navigable, but it is a select-style UI control which has the entire stack in it. Selecting a different level shows you that scope's variables, etc. and pops your editor to that exact file (where you can mouse-over variables to see their in-memory real-time values). Second is in the left-hand area (where you normally browse files). There is another tab there (besides the file browser) for exactly this purpose. There is a slider at the bottom which controls how many "steps" in the stack you see; clicking on one has a similar affect.
For simple refactoring such as method re-naming, you can use the contextual-menu when you right-click a selected method-name, and Xcode will replace all identical selectors in your project. However, this does not address what you mentioned about different classes having methods with the same signature. It does, however, give you a very nice interface for reviewing the changes in-context and easily accepting or rejecting them one at a time.
It might be noted, however, that changing method signatures often may be a sign of poor design, and particularly if you have to do it with methods which have the same signature on different classes (which are not "siblings" and therefore should both get the rename)

datastructure behind browsing history

Im writing a QML file browser. Now, I want to implement a back and forward function. This function is similar to browser back and forward functionality. Example :
I start in "/home/text/folder1" and browse to "/home/text/folder1/src". Now I browse to "/home/text/folder1/src/java". If I press back twice, I should be at "/home/text/folder1", and I cannot press back anymore (the button should be grayed out or in some other way indicate that there are no more "previous" items to be shown).
I was thinking of implementing this via a double-linked list. However, I am having troubles understanding where I should insert new items to the list, and when I should do it.
Take the previous example :
If instead of pressing back twice, I press back only once (I am now in "/home/text/folder1/src"). If I suddenly go to "/home/text/folder2" , what now? How should my double linked list look now?
This is a datastructure question, and not implementation, so code is not required.
I think your idea using a doubly LinkedList is a good point to start. If you enter a new directory, you add the new item after the current item, discarding the tail of the linked list.
Assume we were in folders 1,2,3 (i.e. we have the list 1->2->[3], square brackets indicating current node). Now we go back twice, resulting in [1]->2->3 if we now go to a new folder 4, we obtain 1->[4], so we have discarded the 2->3 part.
I would have a stack, rather than a list. Every forward navigation puts a link on the stack; every time you go back, you remove the item from the stack.

Draw diagram by call stack

Does any one know how to draw a class diagram by call stack in VS2010?
As rerun said, the question in itself doesn't make much sense, perhaps you mean a Sequence Diagram? If so, you can't directly create it from the CallStack window, but you can create it from the code editor as described here.
The closest built-in thing to what you want is the Parallel Stacks debug window, which can be accessed via the Debug menu, Windows menu.
It doesn't exactly give you a seperate box for each item in the call chain, but at least it's visual and easier to visually parse than the call stack window.
Be sure to turn on the Method View.
It also allows navigation to the methods in the call stack.

Resources