Recovering Stage3D context after viewing iAd using Starling and Air for iOS - air

I have an app using Starling and a native extension for iAds (Milkman Games iAds Extension)
I noticed that when a user clicks the iad, interacts with it and then returns to the game there is a long delay with a black screen as Starling recovers a Stage3D context.
I would like to be able to show some sort of loading screen during this time, but everything I try doesn't seem to work.
Does anyone have a suggestion how to implement this? Is it even possible?

This is just a theory, haven't tested it but it should work.
Listen for Event.ACTIVATE. This should trigger when the iAd is closed. It's also triggered a lot of other times so we need to make sure that we check for this black screen, to do this we can simply have this inside the event handler:
private function _onActivateHandler(e:Event):void
{
if (starling.context.driverInfo.indexOf("Disposed") != -1)
{
this.addChild(loadingTextOrBitmapEtcEtc);
starling.stage3D.addEventListener(Event.CONTEXT3D_CREATE, this._onContext3DCreateHandler);
}
}
private function _onContext3DCreateHandler(e:Event):void
{
starling.stage3D.removeEventListener(Event.CONTEXT3D_CREATE, this._onContext3DCreateHandler);
this.removeChild(loadingTextOrBitmapEtcEtc);
}

Related

Does Mapbox has a get user pan/swipe event? Can't find anything in Docs

What I'm looking for?
I want to get notified when the user swipes/pans the pan to check other locations.
The only only event I could find is onPress but it is only fired when the user actually presses on the map, but if the user swipes the map to change view it doesn't get fired.
What I need it for
I want to know if the user swiped the map and the user's location is not the center of the map anymore. If yes, then show a button to center map around the user's location. Like I said, how do I know if the user swiped.
What am I using
Mapbox SDK for react-native (currently only testing on ios but I need it to work on ios and android in the future).
What I have tried so far
onRegionWillChange = { ( ) => this.myfunction() }
myfunction here only gets notified when the region loaded changes, not when the user is not centered anymore.
this._map.getCenter()
I user this to know if thee center of the map is the user's location. But I am looking again for the event that gets fired when the user swipes & then I would call this function to verify the swipe.
Any Help is very much apprechiated
I've no experience using the SDK for react-native, but using the JS version you can use on drag events. It might lead you to a way to do it using the react-native SDK.
There are three types.
drag
dragend
dragstart
This shows an example that listen for the drag event and writes out the current center of the map to console.
this._map.on("drag", (x) => {
console.log(this._map.getCenter());
});

Is there an event to listen on for when a React Native app is quit?

Im interested in firing a function when a user quits the app, meaning they bring up multi-tasking and close-out the app.
I'm not talking about navigating back to your home screen and keeping the app in the background.
I'm aware of AppState, but as I said, im looking for the suit scenario, not a change from active, to the background
Is this possible, my componentWillUnmount() is not firing in this case?
Here is an example using an OS background task and additional library. That might be your best bet without using AppState/ComponentDidUnmount() which would only detect active/background status:
https://github.com/billmalarky/react-native-queue#os-background-task-full-example
componentWillUnmount() won't fire because that's only when a component is being removed from the DOM.
The JavaScript engine closes when the app does so there's no other way to communicate with it once the app is closed.

React Native lifecycle and restarts

Firstly, apologies for the slightly open ended questions but I can't find the info I'm looking for in other questions.
I'm trying to understand the lifecycle of a RN app on both iOS and Android. I understand the app bootstraps when you first start it and stays running while the phone is alive, but what happens when the user switches to a different app and comes back, or their screen times out then they switch it back on? It would be really annoying if the app restarted just because they briefly switched to check their email.
My specific use case (not particularly important to this generic question but included for context) is that I'm trying to build a game with socket.io connections and I'm wondering if I can hook into events to see if the app has been in the background or if I even need to. I have found a way of forcing a restart which may be necessary at some points, but I'd rather just try to reconnect things that have disconnected if I can find out when that happens.
Any push in the right direction would be appreciated.
The app doesn't restart when it goes in the background as you describe. The app keeps its state and the user sees the last screen they visited.
You should have a look at react native's AppState
https://facebook.github.io/react-native/docs/appstate
Using AppState you can addEventListeners that capture the change of the app's state like when going to background.
Of course there are also some problems here...
You can't capture the "kill "event. You can only detect if the app is sent to the background but unfortunately you can't detect when the user chooses to "kill" the app
You can't run any code while your app is in the background. This might be serious in your case but you should evaluate it. For example if you have a timer and you sent the app to the background then the timer stops.

IBM Worklight - hiding splash screen

I want to hide the screen splah of my app and i'm trying to do this with Cordova function navigator.splashscreen.hide() according to this
function wlEnvInit(){
wlCommonInit();
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("device is ready!");
navigator.splashscreen.hide();
}
}
I placed this code on android/js/myAppName.js and iphone/js/myAppName.js folders. It does not work. There is something wrong?
I assume what you're trying to do is to hide the splash image at a point in time based on your own preference? This is currently not possible.
Worklight bypasses Cordova's splash image mechanism as well as does not provide an API to manipulate its duration programmatically (= choose when to hide it). This is an area that is destined to change in a future release.
If what you're trying to do is to simply not show a splash image at all, then:
In iOS: this is not possible. The splash image is mandatory by Apple
In Android: simply delete the splash.9.png image file from the yourProject\apps\yourApp\android\native\res\drawable folder
BTW, I do not see the use for the deviceready listener, because if you've reached wlCommonInit, then the device (Cordova...) has already been initialized. The app would not have functioned otherwise.
For the time being, a workaround for it would be by replacing the Splash screen image with a complete white background screen/image.

Detect when a HTML5 Video runs full screen from Objective-C

I received this request: https://github.com/Simbul/baker/issues/291
So I tried to look up if there was any event fired on Objective-C side from the UIWebView when the video began and stopped to be in full screen, in order to enable/disable again the orientation lock.
I'm aware this is possible in JavaScript:
var player = document.getElementsByTagName("video")[0];
player.addEventListener('play',videoPlayHandler,false);
player.addEventListener('pause',videoPauseHandler,false);
but I would like to avoid injecting code in the page to detect it, since Baker is a framework and we allow any content running inside it.
Thanks in advance. :)