How to add analytics code in React Native lifecycle - react-native

I have a TabBarIOS which contains five navigators. I need to track each view on screen for google analytics, but ReactNative doesn't provide a lifecycle for that.
I'v tried to track in the componentDidMount of those views, but it will be only called once in its lifecycle for each view. Switching between tabs will not trigger componentDidMount again.
Furthermore, when I push()/pop() a view into/from a navigator, I need a callback to find which component will be shown.
Is there any callback method or delegate method which would be called when a component is going to show (like -viewDidAppear: in iOS)?

TabBarIOS.Item has a property named onPress() that gets called when the item is pressed. You can use this callback to update analytics.

Related

Iconic Vue PopoverController/ModalController with custom events

I am trying to use the PopoverController in Ionic 6 with Vue 3 (Composition API). Now, as I can not just add an #custom-event to my popover, I do not know, how to respond to custom events from my popover inside the parent component. Of course, you could pass callbacks as props, but that's pretty much an anti-pattern in vue.
Any ideas on how to pass custom events from the popover created by the popover controller to the parent?

What is similar to ViewWillAppear of objective-c for React-Native?

I'm using Navigation.startTabBasedApp and for each tab, componentDidMount() only calls one on app start. I want to trigger some method when user taps on particular tab. Even componentWillReceiveProps() is not getting called.

NSNotification or Delegate to register for when the visible view changes

I'm developing a project in objective-c for ios, and I have a view with multiple tabs using a subclass of UITabBarController. Each tab has it's own UINavigationController. When a view loads on a tab, the appropriate activation events fire (viewWillAppear, viewDidLoad, etc.). However, once you tap on a different tab, and tap back, not all these events will fire again since the view is already the visible view for that specific tab (viewDidLoad for example).
My question is this: is there a notification or delegate that I can simply register for and get notified when the visible view in the window changes? I've done some research and I didn't find anything specific for this. What I plan on doing is:
Check the visible view when the tab bar index changes: tabBarController:didSelectViewController
Register for this event on each navigation controller: navigationController:didShowViewController:animated:
By doing this, I should be notified whenever the visibleViewController changes by either changing the tab, or navigating within the tab's navigation flow (except for modals, in this case, I don't care about them. They are handled already).
Is this the right approach?
Have you looked at UITabBarControllerDelegate? This method sounds what you are looking for:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
From the documentation:
In iOS v3.0 and later, the tab bar controller calls this method regardless
of whether the selected view controller changed. In addition, it is called only
in response to user taps in the tab bar and is not called when your code
changes the tab bar contents programmatically.
Here's the link: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
Hope that helps!
First implement the UITabBarController delegate method "tabBarController:didSelectViewController" and register for it in the app delegate. You can't register for it in each navigation controller. Only one object can be the delegate. In that method, typecast it to a UINavigationController.
Then get the UIViewController by calling "topViewController" on that UINavigationController. Then call the viewWillAppear: method directly on it.

Prism. OnNavigationTo doesn't fired when i show my view with RegisterViewWithRegion

I have a little problem with the OnNavigatedTo method in the INavigationAware interface.
When I show my view with RegionManager.RequestNavigate(myRegionName, myViewName),
the OnNavigationTo method is called.
But when I use RegionManager.RegisterViewWithRegion(myRegionName, typeof(myView))
I can not get this scenario, and after that, I call
RegionManager.RequestNavigate(myRegionName, myViewName2) to my second view i am having a call to OnNavigatedFrom method of my first view.
My question is:
Why OnNavigatedTo method does not called and how i can get notice about view is shown when i use RegisterViewWithRegion?
Registering using the region manager will show the first view that was registered with it. It will never call OnNavigatedTo. Basically, to get it to do what you want to do, you'll need to "navigate" to your first View without OnNavigatedFrom to be called. To do this:
// Register all your views into the region
// The first View that is registered is automatically activated
regionManager.Regions["myRegionName"].Add(myView);
regionManager.Regions["myRegionName"].Add(myView2);
// Deactivate the View so it doesn't show in the UI
regionManager.Regions["myRegionName"].Deactivate(regionManager.Regions["myRegionName"].ActiveViews.First());
// Now navigate to your first screen
regionManager.RequestNavigate("myRegionName", "myView");
OnNavigatedTo should be called once, and OnNavigatedFrom should only be called after you request navigation to another View.
To allow view navigation you have to register it as an object, try something like that:
_container.RegisterType<Object, MainView>("MainView", new TransientLifetimeManager());
_regionManager.RegisterViewWithRegion("MainRegion", () => _container.Resolve<MainView>());
the first line allow you view navigation while the second will automaticly resolve the view as the region is created

how to pass data or string while popviewController

I am navigating 6 navigations down..and from sixth navigation page i want to transfer something(some string value) to First PAge .If i continue the navigation the navigation controller maintains the stack and while going back i have to come across all previous navigated views. If i am popping from Sixth navigation view to First it is not carrying any value.How to do this..any another logic to carry string or data ?or to clear the navigation controller Stack ?
If you wish to send information you might want to go through the app delegate or create a custom delegate that you wire up in Interface Builder.
I would create a new method in the AppDelegate (ex. -(void)didChangeSixthPageString), then call it from SixthPageViewController. In the AppDelegate you probably have a reference to the the first view controller, so you can pass it the string.