hide tabBar on screens using drawer + tabs + stack - react-navigation

I want to hide the tab bar in some screens, to be more exact in the screens after the main screen of each tab.
I am using reac navigation 5
React native with hooks
I have the following layout, I am using drawer, tabs, and stack.
I want the tab bar to be displayed normally when the user stops at the shopping cart tab, but when the user clicks a button that takes him to another screen of the shopping cart stack, I want the tab bar to no longer be visible .
That is, only in the main screens of the tabs, the tab bar is present, in the other screens, it should not.
This behavior is satisfactory with Home, but not in the other tabs.
I really appreciate any help, I receive comments, suggestions, and anything to make this navigation distribution much better.

I've done this in my app in the following way:
import { useFocusEffect } from '#react-navigation/native';
{ ... }
// Hide parent tab bar on focus
useFocusEffect(
useCallback(() => {
// Do something when the screen is focused
const parent = dangerouslyGetParent();
if (parent) {
parent.setOptions({
tabBarVisible: false,
});
}
return () => {
};
}, [dangerouslyGetParent]),
);
Beware though. To make this really work when using navigation.pop() or navigating back to a previous screen you will need to add this same code to the components you want to ensure do show the tab bar as this modifies the navigator configuration itself. So you would just do the same in screens that get navigated to from the disabled tab bar screen with the above code sub tabBarVisible: true
I haven't really found a better way from researching when I was digging. Would love for other solutions that are more elegant but this at least will get you started and functionality working.

Related

NSColorPanel not showing up after the first time

I have a statusBarItem that I want to use to show the NSColorPanel.
The following code is called when the button is tapped, which activates the ColorPanel.
#IBAction func showColour( button:NSButton ){
DispatchQueue.main.async {
NSApplication.shared.orderFrontColorPanel(self)
print( "panel frame:\(NSColorPanel.shared.frame), is visible:\(NSColorPanel.shared.isVisible )" )
}
}
If the user presses the close button to close the colour panel, tapping the button to show the panel works as expected and displays the panel again. However, if the user clicks in an empty space, the colorPanel disappears, and tapping the button to reopen the panel does not work any more. However, based on the logs, it appears that the panel has a valid rect and is visible.
Any Suggestions?ThanksReza
As it was pointed out by a user on Reddit, when tapping in an empty space the app will go to the background, and is no longer the foreground application, so a utility-style window like the color panel will not be displayed. Hence as the app is not active, subsequent taps to show the colour panel, will not bring the utility window to the front.
So the solution is to make sure the app is active prior to trying to open the colour panel by calling:
NSApplication.shared.activate(ignoringOtherApps: true )
in the showColour function

NSTabView: Toolbar does not display

macOS 10.12.6; Xcode 9.3, storyboards
I have an NSTabView (tabless) that in itself contains two NSTabViews. One is tabless, the other one uses the 'toolbar' style.
When I start my app with the toolbar visible, everything is fine: it displays my tabs in the toolbar, I can change them, etc etc. Once I change to the other branch of my storyboard, the toolbar disappears... and when I come back, instead of a toolbar proper, with buttons and all that, I get a slightly widened bar that has no content in it.
I've set up a sample project to show my problem, where - for ease of switching - I have left the other two tabViewControllers to show their tabs (bottom/top, but this makes no difference).
1) First run (starting with 'toolbar' branch):
2) (not shown): switch to 'top' branch
3) After switching back to 'toolbar':
As a diagnostic aid, I've created a 'displayToolbarStatus' IBAction in the AppController:
#IBAction func displayToolbarStatus(_ sender: NSMenuItem){
if let window = NSApplication.shared.windows.first {
print(window.toolbar?.isVisible)
}
}
The results are as follows:
1) optional(true)
2) nil
3) optional(true)
which is very much in line with how things should work: the toolbar exists and is displayed, there is no toolbar, the toolbar exists and is displayed. Only, of course, it is not usable as a toolbar. (turning visibility off and on, or trying to force a size change with window.toolbar?.sizeMode = .regular has no effect whatsoever, nor does assigning icons to the toolbar items; the toolbar remains squashed and without functioning buttons.
I haven't worked in any depth with NSToolbar: is this a known problem with a workaround; is this new to Xcode 9.2 (which, after all, thinks that no window is valid, so obviously has some problems in that field)?
I really want to use the NSTabView 'toolbar' functionality: how do I proceed?
I've now had more time to play with toolbars. The 'weird' appearance of the non responsive toolbar is simply an empty toolbar, which gave me a clue as to what was going on.
0) The NSTabView overrides the window's toolbar; it does not hand back control when it vanishes; this means that if you have another toolbar in your window that will never show up the moment you're using an NSTabView with 'toolbar' style.
1) I have added a print statement to every relevant method in the ToolbarTabViewController and a 'Switching Tabs' in the containing TabViewController's DidSelect TabViewItem, as well as logging when Toolbar items are added to the window.
(The ToolbarTabViewController is the second controller in the containing TabViewController; it is selected. Otherwise the stack looks slightly different):
ViewDidLoad
Switching tabs
viewWillAppear
viewDidAppear
Switching tabs
Toolbar will add item
Toolbar will add item
viewWillAppear
viewDidAppear
Switching away to the other tab:
viewWillDisappear
Switching tabs
Toolbar did remove item
Toolbar did remove item
viewDidDisappear
So far, so good.
Switching back to the ToolbarTabController, we get
viewWillAppear
Switching tabs
viewDidAppear
Whatever method is called that adds the tabs-related items to the toolbar on first appearance does never get called again. (Note also that the the order of switching tabs and viewDidAppear is not consistent between the first and subsequent appearances.)
2) So, the logical thing to do seems to be to capture the items that are being created and to add them back for future iterations. In the ToolbarTabViewController:
var defaultToolbarItems: [NSToolbarItem] = []
#IBAction func addTabsBack(_ sender: Any){
if let window = NSApplication.shared.windows.first {
if let toolbar = window.toolbar{
for (index, item) in defaultToolbarItems.enumerated() {
toolbar.insertItem(withItemIdentifier: item.itemIdentifier, at: index)
}
}
}
}
override func toolbarWillAddItem(_ notification: Notification) {
// print("Toolbar will add item")
if let toolbarItem = notification.userInfo?["item"] as? NSToolbarItem {
if defaultToolbarItems.count < tabView.numberOfTabViewItems{
defaultToolbarItems.append(toolbarItem)
}
}
}
3) The last question was when (and where) to call addTabsBack() - I found that if I try to call it in viewWillAppear I start out with four toolbarItems, though the number of tabViewItems is 2. (and they do, in fact, seem to be duplications: same name, same functionality). Therefore, I am calling addTabsBack()in the surrounding TabViewController's 'didSelect TabViewItem' method - willSelect is too early; but didSelect gives me exactly the functionality I need.
4) There probably is a more elegant way of capturing the active toolbarItems, but for now, I have a working solution.

jQuery how do i select multiple elements

I am new to jQuery and i want to figure out how to select multiple elements for my navigation bar i'm trying to create. I want to have it check if the users mouse is over the item in the navigation bar or over the drop down menu (otherwise the drop down menu would disappear). I have tried to use:
$('#nav_item_1').mouseenter(function(){
//make the drop down menu visible and change nav_item background here
}); `
$('#nav_item_1,#dropdown').mouseleave({
//revert everything back to normal
});
but then when i try to move my mouse from the item in the navigation bar to the drop down menu it reverts everything back to normal.
The issue that you're having is because when you leave the navigation bar item .mouseleave is being triggered instantly hiding the #dropdown with it.
What I would do here is set a slight time out on the mouseleave event of the nav_item about half a second or less to hide the dropdown. This will allow the user the amount of seconds set outside of the navigation bar so that they can hover over the dropdown. After the user is on the #dropdown I would clear the timeout preventing the normal behavior of the dropdown hiding.
How would you do this with code?
$('#nav_item_1').mouseleave(function() {
/* set your time out here to return everything to normal. Because we want to allow the dropdown to stay visible for a fraction of time required to move the cursor to the dropdown.*/
});
And then,
$('#dropdown').mouseenter(function() {
// clear the timer to prevent normal behavior (keeping the dropdown visible).
});
Check out this link: http://www.w3schools.com/js/js_timing.asp
Regarding your original question about selecting multiple items. You are doing it corrently. But as I explained above your code is not reaching the mouseleave event of the #dropdown.
The second piece of code makes it so that when you leave #nav_item_1 OR #dropdown, everything will be reverted. So when you leave the #nav_item_1 to go to the #dropdown, the event will fire.
You could check every mouse move if the current mouse target contains the dropdown or nav_item:
$("#nav_item_1").mouseenter(function () {
// make menu visible etc
}
$(document).mousemove(function (e) { // note the e parameter
if ($(e.target).has("#dropdown,#nav_item_1").length !== 0) {
// revert
}
}
This requires the two elements to be very close to each other in order for it to work properly though.

Using UIAutomation in iOS to click on the buttons on the tab bar

I have a tabbar in my application and I have to write a JavaScript file to click on the buttons on the tab bar but the problem is I can't find any relevant information about tab bars and UIAutomation.
There are 4 buttons in my tab bar, I am not able to figure out how should I take the reference of my tab bar in the JavaScript file I have to write, for the navigationbar I have used
navBar = mainWindow().navigationBar();
navBar.leftButton().tap();
But I cant find anything similar for the tab bars.
You're writing about tab bar and trying to access it through navBar.
Try this code:
var tabBar = UIATarget.localTarget().frontMostApp().tabBar();
var tabButton = tabBar.buttons()["First"];
// Tap the tab bar !
tabButton.tap();
Tutorial => http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation

xcode 4.2.1 - storyboard - Moving from different view using modal and having Tab bar visible

In xcode storyboard, I have created a Tab Bar Controller that goes to 4 different tabs. One of the tabs is the main menu that has the same links available at the Tab bar. When I use the tab bar to move to the tabs, I do have the tab bar visible. But when I use the main menu links it goes fine to the different views but I lose the tab bar. How can I go from view to other view without losing the tab bar.
I have no header files in my project everything is done through storyboard.
You have to create a class implementation file for the view that you are using as a menu, in it you need to create a function that is called when you press the buttons. In those functions, you should call the following:
// Change 0 to the tab index that you want to display.
[self.tabBarController setSelectedIndex:0];
or
// Change theAppropriateViewController to the view controller that you want to display.
[self.tabBarController setSelectedViewController:theAppropriateViewController];

Resources