How to handle back button android to both exit app and close react native navigation side menu when it is open in home page - back-button

I am using react native navigation Wix side menu in my project. I want to close it when It is open and user clicks on mobile physical back icon. But I have defined for the back button to close my app when user clicks on it. So my back icon should do two following works:
1- it should close the menu when it is open.
2- it should exit from app when the menu is close.
I have saved the status of the side menu (open: true , close:false) in redux store to handle it. But the problem is when user open or close the menu with swiping on mobile screen. In this case I cannot update my state in redux store. I cannot disable this option (Swiping) of side menu in react native navigation to get ride of the problem. So I do not know how to fix it!

You could listen to the componentDidAppear event in your Side menu screen to set your redux store state for its visibility.
Also you could add Backhandler event handler in your screen to either close the side menu or exit the app.
For example:
useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', () => {
if (reduxStore.sideMenuOpened) {
// Close the side menu.
closeSideMenu()
// Prevent the Backhandler's event bubbling up.
return true
}
// Let the backhandler's event bubble up to close the app if you are in root screen.
return false
})
}, [])

Related

HelloWorld sample code not working on Android: Back button not visible

I got the sample app from
https://github.com/PrismLibrary/Prism/tree/master/Sandbox/Xamarin/HelloWorld
I tested it on Android 6:
Run the app from sample code (no modifications), it shows MainPage
Tap on ViewA from the menu, it navigates to ViewA, but there is no back button in the app bar.
Hitting device back button works, it navigates back to MainPage.
The behavior I am expecting is to see the back button in the bar too.
UPDATE
I'm debugging Prism, and I can see clearly that Prism's PageNavigationService navigates to ViewA by just calling currentPage.Navigation.PushAsync(page, animated).
I can see that the Xamarin Forms's NavigationImpl has the NavigationStack with two pages, MainPage and ViewA. So the MainPage is still there in the navigation stack, but for some reason the back button is not visible.
ANSWER!
#lowleetak discovered that there is a call somewhere in the sample which hides the back button!
The app start in MasterDetail page. Where the MasterPage is the Menu and DetailPage is the MyNavigationPage/MainPage initially.
When you click ViewA from menu, it is changing the DetailPage from MainPage to MyNavigationPage/ViewA. It is the root/initial page in the navigation stack of the DetailPage. So, there is no Back button showing.

Unable to switch to Alert without closing window popup in webdriver

Scenario:
Enter a keyword (Position) in a textbox
press Tab or click on the next element
A window popup appears
a list of position matching the criteria will be listed
click the required record
Popup window closes automatically
Alert will be displayed
have click on ok button of alert.
switch to main window and check the position details
Question :- i found many solutions in the site but all are about performing actions on window popup and close the popup then switch to alert or main browser
but my application closes the popup window automatically after selection,hence i cannot use the driver.close() or driver.switchto.defaultContent().
If i dont close the driver (for popup) im not able to identify the next alert displayed after popup.
if i switch directly to mainwindhandle, the alert dismiss is happening instead of accept.
Please anyone who know how to switch from window popup to alert without popup close help is needed...
Thanks ....
If alert dismiss is happening when you are trying to accept it, why don't you use alert.dismiss(), it will probably accept the alert in your context.
When you switch to the popup window, the driver focus is on the popup window. What you might want to do is, just after clicking the required record, switch to the main window then accept the alert.
This must be helpful for you . From your questions, Even after your pop up closes automatically you must be able to access your parent window element by switching back to it. There is no need of driver.close() all the time. Here is the code,
// do something with the pop up and it closes automatically here.
driver.switchTo().defaultContent();
driver.switchTo().frame("your parent window mainframe"));
// try to access your parent window element here

How to make the back button act as the home button in Android

I have a very simple application. The app asks a question and depending on what the user clicks a different text is shown. Now, when the home button is pressed the phone goes to the home screen and the app pauses.
But when I press the back button the dialog goes away but the white background (Default in an app made by eclipse) is still there. Then I have to press the back button once more to get to the home screen.
My question, is there a way to make the back button act as the home button to return to the home screen? If there is, what is it.
I have tried using onStop and onResume and onPause but the same thing happens.
Thanks,
dhoehna.
Sounds like android SDK. So, I'm going to assume you are doing Android development.
You'll have to override the method called OnBackPressed(). Then you can override the back button to do what you want it to do.

jQuery dialog serving multiple button's click event handller

I have a scenario where...
1.) Have created a div with a dropdown list and ok, cancel button
2.) On document ready - registering div created on step 1 into a jQuery dialog
3.) on a javascript button click - I am opening this dialog box.
4.) Now, the problem is - the jQuery dialogbox which I have created, needs to be used by other button clicks as well on same page. Now, my div's (which is a dialog at runtime using jQuery) ok button click is already engaged with a javascript function (button1 click) and I can not associate other button's click events with it - thus stuck up here and have no clues or hit to resolve this.
Anyone have faced this issue in asp.net, jquery earlier? Can someone provide a guidance?
Why you cant associate another event?
buttons will have different id. Is it?
$('#button1').click(function() {
alert('Handler for button 1 .click() called.');
});
$('#button2').click(function() {
alert('Handler for button 2 .click() called.');
});
Is this not possible in your case.?
Options:
1) disassociate the click handler when the function opens the div, then later in the function of opening the div associate a click handler to the button.
2) create multiple buttons toggle them all hidden, associate the click handler to each button you want. When the div is opened do a check to see which button to toggle to visible.
3) create no buttons but have a function create the button on the fly. When the div is opened, create the button for that div by calling the function and passing in a code telling it which button to open and what to associate to the click handler (this can be stored in an array and all that is passed in is the key).
Depending on the application, I have used all of these methods. The last one can have a twist that allows it to call an ajax server based application to get the button text and functionality (stored in a database), this saves you from having to load an array with button data, and also allows for easier expansion of the application.

Flex - Menu Created On Button Click

I created a Button in MXMXL. On button click, I create a Menu as a child of the Button. I am using an XML datasource. The reason for creating it this way, was due to the amount of custom skinning involved. A popupmenubutton was not an option. Anyway, so my question is this: when clicking the button, the menu is displayed. However, if you click the button again, the menu reopens. I want the menu to close if the user clicks the button a second time. Now, I got it to work by setting a var after opening the menu, and then I check that var on each click to make sure that the menu isn't already open. If true, then it will close the menu, instead of reopening it. This works, until the user clicks away, in which the HIDE event gets dispatched and the menu closes. My hack no longer works.
Any suggestions? I spent hours trying different things. The hardest part is trying to destinguish from that second button click when the menu is open, and when the user clicks away from the menu. They both dispatch the HIDE event.
Help!!!
Have you tried adding another eventlistener to the button...FlexMouseEvent.MOUSE_DOWN_OUTSIDE ? You should then be able to set the preventDefault event to true to stop the event from firing anything else and stop the menu from closing.

Resources