What is react-native component doing when the component is in background - react-native

What is react-native component doing when the component is in background?
And What will react-native do when component re-active to foreground?
Like Page A navigate to Page B.
And Page B back to Page A.What happened to A and B?
Is there any ui update like onResume on Android or something?
Edit:
I have a TabNavagation with four tab.One of the tabs renders an Android UI Component which is a custom frameLayout(a listview is in the frameLayout).
When the frameLayout first rendered, the listview position is not correct(position is -4 item height).But when I navigate to a child page and goback, I found that the frameLayout is correct now and does't enter any android lifecycle.
So I'm wondering is it doing something background?

It is hard to tell without detail information on what type of navigation you are using but I can explain it considering you are using common navigation packages.
If your navigation is some sort of stack navigation, when you navigate/push a new screen to view the previous screen lays under the stack and doesn't un-mount. It is much like dealing a deck of card to a pile. It doesn't re-render unless the props or state of that specific component changes. When you navigate back the new screen un-mounts and the previous screen shows back.
Common packages lets you to pass props to the next screen and if you need to re-render a previous component a easy hack to achieve this by sending a function from the previous component and running it on componentWillUnmount life-cycle event of the current screen. I explained this sort of usage in this answer.

After debug many many times, I found that it is the react-navigation.
Four tabs in homepage with bottom tabbar.When I enter a child page with navigationOptions:{header:null}, the bottom bar is gone. And when I goback from the child page, the bottom bar has back meanwhile and the whole view has corrected.Seems the whole view is re-draw?So I called view.requestLayout() in createViewInstance().So the final result is the view need to requestLayout manual.
UPDATE:
answer top is not totally correct.The final problem is the custom view should measure self in its requestLayout.
I found the answer in https://github.com/facebook/react-native/issues/4990
#Override
public void requestLayout() {
super.requestLayout();
post(measureAndLayout);
}
private final Runnable measureAndLayout = new Runnable() {
#Override
public void run() {
measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
layout(getLeft(), getTop(), getRight(), getBottom());
}
};
And thanks for your answers.#bennygenel #Jouke

Related

Passing the navigation object down the nested react component

My react component hierarchy looks like
StackNavigation
- MainScreen
- List
- Row
- Button
My usecase involves go to a new screen on click of the button. My main screen receives react-navigation's navigation props. How do I pass it down to my button in a sane manner.
You'd better pass a callback to your button through all the hierarchy and call it when button is pressed. Afterwards when you know which button is pressed (on which row) you can navigate to necessary screen from your MainScreen.

XAML Xamarin Forms navigation drawer sample code for iOS/Android

Does anyone know how a navigation drawer similar to the one in the Sonos app can be implemented? I have checked both Android and iOS versions of the app and see that the navigation drawer has been implemented in the same way for both platforms.
The two key things that I like and want to implement are:
the slide out drawer is below the navigation bar. When it slides out, the navigation bar is still visible
it appears as if it is the drawer that slides out, rather than the detail view moving to the right. I've noticed that the default master detail page slides out in a different way and it's not what we want.
Have a look at the images below so see I mean.
thanks
Although not technically a good practice, if you put a MasterDetailPage into a NavigationPage, it will slide out like in the above pictures. Here's how you do that:
In the App.cs constructor or your app's OnStart() method:
MainPage = new NavigationPage(new MyMasterDetailPage()) {
Title = "Your Title"
};
Create a new MasterDetailPage called MyMasterDetailPage.
In the constructor, add the following code:
Detail = new HomePage();
Master = new MenuPage()
{
Title = "Menu"
};
You then need to create a ContentPage for both HomePage and MenuPage.
One issue that you will run into if you use this method, is that if you don't call MyMasterDetailPage as the first page upon opening the app, the three horizontal bars on the NavigationBar won't appear, which will make it hard for users to tell there is a drawer. So if you need users to go to a login page or another page before your MasterDetailPage, you may want to find another implementation.

React Native NavigatorExperimental - Combine AnimatedView with CardStack

i 've a NavigationAnimatedView which rendering a ListView with pushed DetailsView.
In the NavigationHeader, on the rightComponent, i have a button and i want to display a view with NavigationCardStack from bottomToTop. How can i combine the two modes of navigation ?
Like the filters button on the F8 app on the home screen.
i don't understand how with a dispatch action (navigatePush ?) on the FiltersButton, i can't switch with a navigationCardStack to display a FilterViews from BottomToTop.
You can provide props to NavigationCard when you render it:
_renderScene(props) {
return (
<NavigationCard
style={NavigationCardStackStyleInterpolator.forVertical(props)}
...
Sorry that part isn't documented very well right now!

Cannot call method onCreateOptionsMenu () on startup for napp drawer

I have a problem only with nap drawer module.I have this code:
**drawer = NapDrawerModule.createDrawer({
//parameter for the drawer
});**
Then I have:
*
*drawer.getActivity().onCreateOptionsMenu = function(e) {
//code for creation menu**
}
Problem is that when I started application the method onCreateOptionsMenu() not called so my menu item not show up.When I pressed physical menu button it show up.
I noticed that this is problem only with NapDrawer.I tried make simple TI.UI.createWindow(),add method onCreateOptionsMenu() and it work.
I don't know what is a problem with drawer.I use titanium 5.0 and target android SDK 22.
I found the solution for the problem above.Anyone who has this kind of problem the next solution work for me.You need to add in your nap drawer create method next attribute:hamburgerIcon:true

MvvmCross application freezes and crashes when re-showing modal view model

The app I'm working on consists of a hierarchy of data and a filter to search through that data. The data is displayed in a hierarchy of table views, and navigation through that hierarchy works fine. However, when I try to navigate to my filter view model (which is shown as a modal view controller), I run into problems.
The first time I open the modal view, everything works fine, and I can close it and all navigation still works. When I try to open it a second time, however, the modal view will appear and the app will freeze and crash after a couple of seconds.
Here is the code from my custom presenter (which is a subclass of MvxModalSupportTouchViewPresenter) that is handling the modal navigation request:
public override void Show (IMvxTouchView view)
{
if (view is IMvxModalTouchView) {
var newNav = new UINavigationController ();
newNav.PushViewController (view as UIViewController, false);
newNav.NavigationBar.TintColor = UIColor.Black;
PresentModalViewController (newNav, true);
return;
...
(taken from MvvmCross Using a modal ViewController from a Tab)
I close the modal by dismissing it in the view itself. Does anyone have any idea why the app is crashing?
follow up on this by email was...
"As to my previous question, I found where the error was. The view
associated with my modal view model got into an infinite loop of
Dispose() calls. It would only happen if the modal was shown multiple
times. Commenting out the Dispose() method allowed me to open it
multiple times."
Not sure currently whether this was a fault in the mvx framework or in the app code - but thought I'd post this here in case it helps others